From 085556e90d668dd5fdbf56b5de759fcfc083edad Mon Sep 17 00:00:00 2001 From: Kevin Peters Date: Thu, 4 Apr 2024 09:59:19 -0500 Subject: [PATCH] Fixed race when setting source token from custom config Would be set to ETH even if you specified a different token. --- wormhole-connect/src/views/Bridge/Bridge.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/wormhole-connect/src/views/Bridge/Bridge.tsx b/wormhole-connect/src/views/Bridge/Bridge.tsx index 5bbbdefc2..7cdcc6441 100644 --- a/wormhole-connect/src/views/Bridge/Bridge.tsx +++ b/wormhole-connect/src/views/Bridge/Bridge.tsx @@ -129,22 +129,28 @@ function Bridge() { }, [fromChain, toChain, receiving.address, dispatch]); useEffect(() => { + let active = true; const computeSrcTokens = async () => { const supported = await RouteOperator.allSupportedSourceTokens( config.tokens[destToken], fromChain, toChain, ); - dispatch(setSupportedSourceTokens(supported)); - const selectedIsSupported = isSupportedToken(token, supported); - if (!selectedIsSupported) { - dispatch(setToken('')); - } - if (supported.length === 1 && token === '') { - dispatch(setToken(supported[0].key)); + if (active) { + dispatch(setSupportedSourceTokens(supported)); + const selectedIsSupported = isSupportedToken(token, supported); + if (!selectedIsSupported) { + dispatch(setToken('')); + } + if (supported.length === 1 && token === '') { + dispatch(setToken(supported[0].key)); + } } }; computeSrcTokens(); + return () => { + active = false; + }; // IMPORTANT: do not include token in dependency array }, [route, fromChain, destToken, dispatch]);