Skip to content

Commit

Permalink
fix: race condition chance
Browse files Browse the repository at this point in the history
  • Loading branch information
AMIRKHANEF committed Nov 26, 2024
1 parent db72b57 commit d7401e5
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions packages/extension-ui/src/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,34 @@ export default function Popup (): React.ReactElement {
}, []);

useEffect(() => {
if (!authRequests || !metaRequests || !signRequests) {
return;
}
// Use a flag to prevent race conditions
let isMounted = true;

if (authRequests.length) {
_onAction('/authorize');
} else if (metaRequests.length) {
_onAction('/metadata');
} else if (signRequests.length) {
_onAction('/signing');
} else if (['/authorize', '/metadata', '/signing'].includes(pathname)) {
_onAction('/');
}
const handleRouting = () => {
if (!isMounted) {
return;
}

if (!authRequests || !metaRequests || !signRequests) {
return;
}

if (authRequests.length) {
_onAction('/authorize');
} else if (metaRequests.length) {
_onAction('/metadata');
} else if (signRequests.length) {
_onAction('/signing');
} else if (['/authorize', '/metadata', '/signing'].includes(pathname)) {
_onAction('/');
}
};

handleRouting();

return () => {
isMounted = false;
};
}, [_onAction, authRequests, authRequests?.length, metaRequests, metaRequests?.length, pathname, signRequests, signRequests?.length]);

useEffect(() => {
Expand Down

0 comments on commit d7401e5

Please sign in to comment.