Skip to content

Commit 5f6a83d

Browse files
kev1n-petersyuli-ferna
authored and
yuli-ferna
committed
Fixed race when setting source token from custom config (#1881)
Would be set to ETH even if you specified a different token.
1 parent a57855a commit 5f6a83d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

wormhole-connect/src/views/Bridge/Bridge.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,28 @@ function Bridge() {
129129
}, [fromChain, toChain, receiving.address, dispatch]);
130130

131131
useEffect(() => {
132+
let active = true;
132133
const computeSrcTokens = async () => {
133134
const supported = await RouteOperator.allSupportedSourceTokens(
134135
config.tokens[destToken],
135136
fromChain,
136137
toChain,
137138
);
138-
dispatch(setSupportedSourceTokens(supported));
139-
const selectedIsSupported = isSupportedToken(token, supported);
140-
if (!selectedIsSupported) {
141-
dispatch(setToken(''));
142-
}
143-
if (supported.length === 1 && token === '') {
144-
dispatch(setToken(supported[0].key));
139+
if (active) {
140+
dispatch(setSupportedSourceTokens(supported));
141+
const selectedIsSupported = isSupportedToken(token, supported);
142+
if (!selectedIsSupported) {
143+
dispatch(setToken(''));
144+
}
145+
if (supported.length === 1 && token === '') {
146+
dispatch(setToken(supported[0].key));
147+
}
145148
}
146149
};
147150
computeSrcTokens();
151+
return () => {
152+
active = false;
153+
};
148154
// IMPORTANT: do not include token in dependency array
149155
}, [route, fromChain, destToken, dispatch]);
150156

0 commit comments

Comments
 (0)