Skip to content

Commit

Permalink
update hooks to use prop conditional when fetching new output
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzettler committed Oct 30, 2024
1 parent 3f140fa commit a0aa4b6
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/features/swaps/SwapScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,32 +478,43 @@ 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),
})
}
})()
}, [
getOutputAmount,
inputMint,
inputAmount,
inputMintAcc,
outputMint,
outputMintAcc,
isDevnet,
setRecipient,
setRecipientOpen,
])

const getInputAmount = useCallback(
Expand Down

0 comments on commit a0aa4b6

Please sign in to comment.