Skip to content

Commit

Permalink
Fixed race when setting source token from custom config (#1881)
Browse files Browse the repository at this point in the history
Would be set to ETH even if you specified a different token.
  • Loading branch information
kev1n-peters committed Apr 4, 2024
1 parent 48db411 commit b5ebe15
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions wormhole-connect/src/views/Bridge/Bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit b5ebe15

Please sign in to comment.