Skip to content

Commit

Permalink
abort wormhole scan api if tooks more than 1.5 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianscatularo committed Nov 22, 2024
1 parent 29f950e commit c914870
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion apps/connect-v1/src/hooks/useConnectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ export const useConnectConfig = () => {

useEffect(() => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 1500); // Abort after 1.5 seconds
getSortedChains(
ENV.wormholeConnectConfig.networks as ChainName[],
controller.signal
).then((chains) => !!chains && setNetworks(chains));
return () => controller.abort();
return () => {
clearTimeout(timeoutId); // Clear the timeout
controller.abort();
}
}, []);

return networks ? config : undefined;
Expand Down
6 changes: 5 additions & 1 deletion apps/connect/src/hooks/useConnectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ export const useConnectConfig = () => {

useEffect(() => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 1500); // Abort after 1.5 seconds
getSortedChains(
ENV.wormholeConnectConfig.chains as Chain[],
controller.signal
).then((chains) => !!chains && setNetworks(chains));
return () => controller.abort();
return () => {
clearTimeout(timeoutId); // Clear the timeout
controller.abort();
}
}, []);

return networks ? config : undefined;
Expand Down

0 comments on commit c914870

Please sign in to comment.