Skip to content

Commit

Permalink
Some changes for handle events
Browse files Browse the repository at this point in the history
  • Loading branch information
hide-on-bush-x committed Feb 15, 2023
1 parent a417717 commit d36318b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/provider/modules/session/session.ts
Expand Up @@ -14,8 +14,8 @@ export const useSession = (
isLoading: boolean;
error: unknown;
} => {
const queryKey: string = useMemo(() => {
return `session-${walletAddress}`;
const queryKey: any[] = useMemo(() => {
return ["session", walletAddress];
}, [walletAddress]);

const {
Expand All @@ -28,23 +28,23 @@ export const useSession = (
});

useEffect(() => {
if (loggedIn && walletAddress) {
void queryClient.invalidateQueries(queryKey);
if (loggedIn && !walletAddress) {
void queryClient.invalidateQueries('session');
}
}, [walletAddress, loggedIn, queryKey]);

const login = useCallback(async () => {
const logged = await masa?.session.login();
if (logged) {
await queryClient.invalidateQueries(queryKey);
await queryClient.invalidateQueries('session');
await queryClient.refetchQueries();
}
}, [masa, queryKey]);

const logout = useCallback(
async (callback?: () => void) => {
await masa?.session.logout();
await queryClient.invalidateQueries(queryKey);
await queryClient.invalidateQueries('session');
await queryClient.refetchQueries();

if (callback) {
Expand Down
1 change: 1 addition & 0 deletions src/provider/use-metamask.ts
Expand Up @@ -83,6 +83,7 @@ export const useMetamask = ({
await handleLogout?.();
await disconnect();
await queryClient.invalidateQueries('wallet');
await queryClient.invalidateQueries('session');
}
}
);
Expand Down

0 comments on commit d36318b

Please sign in to comment.