Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed race when setting source token from custom config #1881

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading