Skip to content

Commit

Permalink
feat: set pause queue incoming request based on loggedIn and isOnline
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-HocNguyena committed May 4, 2024
1 parent d1d183d commit 1c08c9c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ui/components/AppWrapper/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ const AppWrapper = (props: { children: ReactNode }) => {
}, []);

useEffect(() => {
if (authentication.loggedIn) {
dispatch(setPauseQueueIncomingRequest(!isOnline));
} else {
dispatch(setPauseQueueIncomingRequest(true));
}
if (isOnline) {
const handleMessages = async () => {
Agent.agent.connections.onConnectionStateChanged((event) => {
Expand Down Expand Up @@ -187,7 +192,7 @@ const AppWrapper = (props: { children: ReactNode }) => {
};
handleMessages();
}
}, [isOnline]);
}, [isOnline, authentication, dispatch]);

const checkKeyStore = async (key: string) => {
try {
Expand Down Expand Up @@ -279,21 +284,19 @@ const AppWrapper = (props: { children: ReactNode }) => {
try {
await Agent.agent.start();
setIsOnline(true);
await loadDatabase();
} catch (e) {
const errorStack = (e as Error).stack as string;
// If the error is failed to fetch with signify, we retry until the connection is secured
if (/SignifyClient/gi.test(errorStack)) {
await loadDatabase();
Agent.agent.bootAndConnect().then(() => {
setIsOnline(Agent.agent.getKeriaOnlineStatus());
});
} else {
throw e;
}
}
dispatch(setPauseQueueIncomingRequest(true));
await loadDatabase().catch((e) => {
/* TODO: handle error */
});
};

return <>{props.children}</>;
Expand Down

0 comments on commit 1c08c9c

Please sign in to comment.