Skip to content

Commit a0aa4b6

Browse files
committed
update hooks to use prop conditional when fetching new output
1 parent 3f140fa commit a0aa4b6

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/features/swaps/SwapScreen.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,32 +478,43 @@ const SwapScreen = () => {
478478
],
479479
)
480480

481+
useEffect(() => {
482+
setRecipient('')
483+
setRecipientOpen(false)
484+
setOutputAmount(0)
485+
}, [
486+
inputMint,
487+
inputAmount,
488+
outputMint,
489+
setRecipient,
490+
setRecipientOpen,
491+
setOutputAmount,
492+
])
493+
481494
useEffect(() => {
482495
// if changing outputMint ensure we get new routes
483496
;(async () => {
484497
if (
485498
!isDevnet &&
486-
inputMintAcc &&
487-
outputMintAcc &&
499+
inputMintAcc?.address === inputMint &&
500+
outputMintAcc?.address === outputMint &&
488501
typeof inputAmount !== 'undefined' &&
489502
inputAmount > 0 &&
490503
!outputMintAcc?.address.equals(DC_MINT)
491504
) {
492-
setRecipient('')
493-
setRecipientOpen(false)
494505
await getOutputAmount({
495506
balance: toBN(inputAmount || 0, inputMintAcc.decimals),
496507
})
497508
}
498509
})()
499510
}, [
500511
getOutputAmount,
512+
inputMint,
501513
inputAmount,
502514
inputMintAcc,
515+
outputMint,
503516
outputMintAcc,
504517
isDevnet,
505-
setRecipient,
506-
setRecipientOpen,
507518
])
508519

509520
const getInputAmount = useCallback(

0 commit comments

Comments
 (0)