diff --git a/components/forms/Input.tsx b/components/forms/Input.tsx index dc6573f6..66659a3f 100644 --- a/components/forms/Input.tsx +++ b/components/forms/Input.tsx @@ -36,9 +36,9 @@ const Input = forwardRef((props, ref) => { ((props, ref) => { ) }) +Input.displayName = 'Input' export default Input diff --git a/components/forms/Switch.tsx b/components/forms/Switch.tsx index f65a6ba3..66369e6a 100644 --- a/components/forms/Switch.tsx +++ b/components/forms/Switch.tsx @@ -1,4 +1,4 @@ -import { FunctionComponent, ReactNode } from 'react' +import { FunctionComponent, ReactNode, memo } from 'react' interface SwitchProps { checked: boolean @@ -44,4 +44,4 @@ const Switch: FunctionComponent = ({ ) } -export default Switch +export default memo(Switch) diff --git a/components/shared/Notification.tsx b/components/shared/Notification.tsx index 43cd29a6..955af53e 100644 --- a/components/shared/Notification.tsx +++ b/components/shared/Notification.tsx @@ -5,15 +5,15 @@ import { InformationCircleIcon, XCircleIcon, } from '@heroicons/react/outline' -import useMangoStore, { CLIENT_TX_TIMEOUT, CLUSTER } from '../../store/state' +import mangoStore, { CLIENT_TX_TIMEOUT, CLUSTER } from '../../store/state' import { Notification, notify } from '../../utils/notifications' import Loading from './Loading' import { Transition } from '@headlessui/react' import { TokenInstructions } from '@project-serum/serum' const NotificationList = () => { - const notifications = useMangoStore((s) => s.notifications) - const walletTokens = useMangoStore((s) => s.wallet.tokens) + const notifications = mangoStore((s) => s.notifications) + const walletTokens = mangoStore((s) => s.wallet.tokens) const notEnoughSoLMessage = 'Not enough SOL' // if a notification is shown with {"InstructionError":[0,{"Custom":1}]} then @@ -60,7 +60,7 @@ const NotificationList = () => { } const Notification = ({ notification }: { notification: Notification }) => { - const setMangoStore = useMangoStore((s) => s.set) + const setMangoStore = mangoStore((s) => s.set) const { type, title, description, txid, show, id } = notification // overwrite the title if of the error message if it is a time out error diff --git a/components/swap/JupiterRoutes.tsx b/components/swap/JupiterRoutes.tsx index c34590d9..4d7140e5 100644 --- a/components/swap/JupiterRoutes.tsx +++ b/components/swap/JupiterRoutes.tsx @@ -1,4 +1,4 @@ -import { Dispatch, SetStateAction, useState } from 'react' +import React, { Dispatch, SetStateAction, useState } from 'react' import { TransactionInstruction, PublicKey } from '@solana/web3.js' import { toUiDecimals } from '@blockworks-foundation/mango-v4' import { Jupiter, RouteInfo } from '@jup-ag/core' @@ -119,4 +119,4 @@ const JupiterRoutes = ({ ) : null } -export default JupiterRoutes +export default React.memo(JupiterRoutes) diff --git a/components/swap/SelectToken.tsx b/components/swap/SelectToken.tsx index b0296af7..c9a7d641 100644 --- a/components/swap/SelectToken.tsx +++ b/components/swap/SelectToken.tsx @@ -173,7 +173,11 @@ const SelectToken = ({
{sortedTokens.map((token) => ( - + ))}
diff --git a/components/swap/Swap.tsx b/components/swap/Swap.tsx index 94862442..4f07f71b 100644 --- a/components/swap/Swap.tsx +++ b/components/swap/Swap.tsx @@ -36,16 +36,17 @@ const Swap = () => { const [inputToken, setInputToken] = useState('SOL') const [outputToken, setOutputToken] = useState('USDC') const [submitting, setSubmitting] = useState(false) - const [animateSwtichArrow, setAnimateSwitchArrow] = useState(0) + const [animateSwitchArrow, setAnimateSwitchArrow] = useState(0) const [showTokenSelect, setShowTokenSelect] = useState('') const [useMargin, setUseMargin] = useState(true) const [sizePercentage, setSizePercentage] = useState('') const [showConfirm, setShowConfirm] = useState(false) const [slippage, setSlippage] = useState(0.1) - const debouncedAmountIn = useDebounce(amountIn, 400) + const set = mangoStore.getState().set const tokens = mangoStore((s) => s.jupiterTokens) const connected = mangoStore((s) => s.connected) + const debouncedAmountIn = useDebounce(amountIn, 500) useEffect(() => { const connection = mangoStore.getState().connection @@ -54,7 +55,7 @@ const Swap = () => { connection, cluster: CLUSTER, // platformFeeAndAccounts: NO_PLATFORM_FEE, - routeCacheDuration: 5_000, // Will not refetch data on computeRoutes for up to 10 seconds + routeCacheDuration: 10_000, // Will not refetch data on computeRoutes for up to 10 seconds }) setJupiter(jupiter) } @@ -143,7 +144,7 @@ const Swap = () => { setInputToken(outputToken) setOutputToken(inputToken) - setAnimateSwitchArrow(animateSwtichArrow + 1) + setAnimateSwitchArrow(animateSwitchArrow + 1) } const handleSizePercentage = (percentage: string) => { @@ -203,13 +204,12 @@ const Swap = () => { return ( @@ -230,13 +230,12 @@ const Swap = () => { /> @@ -266,8 +265,10 @@ const Swap = () => { className="no-underline" onClick={() => console.log('Set max input amount')} > - {t('max')} - 0 + + {t('balance')}: + + 0
@@ -308,7 +309,7 @@ const Swap = () => {