From 8a1d37999567fdd5497fde7d53538d2dc7dea3c1 Mon Sep 17 00:00:00 2001 From: Nando <24811313+fzavalia@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:49:22 +0100 Subject: [PATCH] fix: Refech route on change token --- .../src/components/Modals/BuyWithCryptoModal/hooks.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts b/webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts index b2ea684e5..a3dbdeb68 100644 --- a/webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts +++ b/webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts @@ -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( @@ -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() && @@ -575,11 +580,8 @@ const useCrossChainRoute = ( } } }, [ - route, useMetaTx, - routeFailed, selectedToken, - isFetchingRoute, selectedChain, assetChainId, calculateRoute