From cdbbb04f68a1af8080b1866075edb21509aff3e3 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 30 Oct 2024 13:47:58 -0500 Subject: [PATCH] update hooks to use prop conditional when fetching new output (#824) --- src/features/swaps/SwapScreen.tsx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/features/swaps/SwapScreen.tsx b/src/features/swaps/SwapScreen.tsx index dee182657..b91bec666 100644 --- a/src/features/swaps/SwapScreen.tsx +++ b/src/features/swaps/SwapScreen.tsx @@ -478,19 +478,30 @@ const SwapScreen = () => { ], ) + useEffect(() => { + setRecipient('') + setRecipientOpen(false) + setOutputAmount(0) + }, [ + inputMint, + inputAmount, + outputMint, + setRecipient, + setRecipientOpen, + setOutputAmount, + ]) + useEffect(() => { // if changing outputMint ensure we get new routes ;(async () => { if ( !isDevnet && - inputMintAcc && - outputMintAcc && + inputMintAcc?.address === inputMint && + outputMintAcc?.address === outputMint && typeof inputAmount !== 'undefined' && inputAmount > 0 && !outputMintAcc?.address.equals(DC_MINT) ) { - setRecipient('') - setRecipientOpen(false) await getOutputAmount({ balance: toBN(inputAmount || 0, inputMintAcc.decimals), }) @@ -498,12 +509,12 @@ const SwapScreen = () => { })() }, [ getOutputAmount, + inputMint, inputAmount, inputMintAcc, + outputMint, outputMintAcc, isDevnet, - setRecipient, - setRecipientOpen, ]) const getInputAmount = useCallback(