diff --git a/src/components/TradeRouting/index.tsx b/src/components/TradeRouting/index.tsx index 605b747a88..7598b3617c 100644 --- a/src/components/TradeRouting/index.tsx +++ b/src/components/TradeRouting/index.tsx @@ -78,12 +78,13 @@ const RouteRow = ({ route, chainId, backgroundColor }: RouteRowProps) => { {Array.isArray(subRoute) ? subRoute.map(pool => { const dex = getDexInfoByPool(pool, allDexes) + const poolId = pool.id.split('-')?.[0] const link = (i => { // TODO: Dungz remove condition - return isAddress(chainId, pool.id) && !['1inch', 'paraswap', '0x'].includes(pool.exchange) ? ( + return isAddress(chainId, poolId) && !['1inch', 'paraswap', '0x'].includes(pool.exchange) ? ( {i} diff --git a/src/hooks/web3/useChangeNetwork.ts b/src/hooks/web3/useChangeNetwork.ts index d26ce86e42..7db7db477f 100644 --- a/src/hooks/web3/useChangeNetwork.ts +++ b/src/hooks/web3/useChangeNetwork.ts @@ -141,7 +141,7 @@ export function useChangeNetwork() { method: 'wallet_addEthereumChain', params: [addChainParameter], }) - changeNetworkHandler(desiredChainId, wrappedSuccessCallback) + wrappedSuccessCallback() } catch (error) { console.error('Add new network failed', { addChainParameter, error }) failureCallback(connector, desiredChainId, error, customFailureCallback, customTexts) @@ -160,7 +160,6 @@ export function useChangeNetwork() { [ library?.provider, chainId, - changeNetworkHandler, connector, failureCallback, fetchKyberswapConfig, @@ -175,6 +174,7 @@ export function useChangeNetwork() { customSuccessCallback?: () => void, customFailureCallback?: (connector: Connector, error: Error) => void, waitUtilUpdatedChainId = false, + isAddNetworkIfPossible = true, ) => { const wrappedSuccessCallback = () => successCallback(desiredChainId, waitUtilUpdatedChainId, customSuccessCallback) @@ -207,15 +207,25 @@ export function useChangeNetwork() { failureCallback(connector, desiredChainId, error, customFailureCallback) return } - - addNewNetwork( - desiredChainId, - undefined, - undefined, - customSuccessCallback, - customFailureCallback, - waitUtilUpdatedChainId, - ) + if (isAddNetworkIfPossible) { + addNewNetwork( + desiredChainId, + undefined, + undefined, + () => + changeNetwork( + desiredChainId, + customSuccessCallback, + customFailureCallback, + waitUtilUpdatedChainId, + false, + ), + customFailureCallback, + waitUtilUpdatedChainId, + ) + } else { + failureCallback(connector, desiredChainId, error, customFailureCallback) + } } } else { changeNetworkHandler(desiredChainId, wrappedSuccessCallback)