diff --git a/src/components/Swap.tsx b/src/components/Swap.tsx index af50f01..4a3630e 100644 --- a/src/components/Swap.tsx +++ b/src/components/Swap.tsx @@ -34,7 +34,11 @@ import { FEE_MULTIPLIER, } from "../context/Dex"; import { useTokenMap } from "../context/TokenList"; -import { useMint, useOwnedTokenAccount } from "../context/Token"; +import { + useMint, + useOwnedTokenAccount, + useTokenContext, +} from "../context/Token"; import { useCanSwap, useReferral, useIsWrapSol } from "../context/Swap"; import TokenDialog from "./TokenDialog"; import { SettingsButton } from "./Settings"; @@ -335,7 +339,8 @@ export function SwapButton() { isClosingNewAccounts, isStrict, } = useSwapContext(); - const { swapClient } = useDexContext(); + const { swapClient, isLoaded: isDexLoaded } = useDexContext(); + const { isLoaded: isTokensLoaded } = useTokenContext(); const fromMintInfo = useMint(fromMint); const toMintInfo = useMint(toMint); const openOrders = useOpenOrders(); @@ -649,16 +654,32 @@ export function SwapButton() { await swapClient.program.provider.sendAll(txs); }; - return disconnected ? ( - - ) : needsCreateAccounts ? ( + + if (disconnected) { + return ( + + ); + } + if (!isDexLoaded || !isTokensLoaded) { + return ( + + ); + } + return needsCreateAccounts ? (