Skip to content

Commit

Permalink
fix: Refech route on change token
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Feb 20, 2024
1 parent 878c512 commit 8a1d379
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ const useCrossChainRoute = (
)

const calculateRoute = useCallback(async () => {
abortControllerRef.current = new AbortController()
const abortController = abortControllerRef.current
const signal = abortController.signal
const providerMANA = providerTokens.find(
Expand Down Expand Up @@ -555,7 +556,11 @@ const useCrossChainRoute = (

// Refresh the route every time the selected token changes
useEffect(() => {
if (!route && !isFetchingRoute && !useMetaTx && !routeFailed) {
// Abort previous request
const abortController = abortControllerRef.current
abortController.abort()

if (!useMetaTx) {
const isBuyingL1WithOtherTokenThanEthereumMANA =
assetChainId === ChainId.ETHEREUM_MAINNET &&
selectedToken.chainId !== ChainId.ETHEREUM_MAINNET.toString() &&
Expand All @@ -575,11 +580,8 @@ const useCrossChainRoute = (
}
}
}, [
route,
useMetaTx,
routeFailed,
selectedToken,
isFetchingRoute,
selectedChain,
assetChainId,
calculateRoute
Expand Down

0 comments on commit 8a1d379

Please sign in to comment.