From 25764c7ab41708f03e4c671857be519020bee46f Mon Sep 17 00:00:00 2001 From: enes Date: Sat, 12 Oct 2024 11:52:43 +0200 Subject: [PATCH 1/2] fix: processing events Partially revert to before 23a04faad89ae3138008f4b1b9a112bf944f279b --- src/layouts/Main.tsx | 18 ++++++++++++++---- src/utils/nostr.ts | 5 ++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx index 9cdc549..0fd5526 100644 --- a/src/layouts/Main.tsx +++ b/src/layouts/Main.tsx @@ -39,6 +39,7 @@ export const MainLayout = () => { const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState(`Loading App`) const isLoggedIn = useAppSelector((state) => state.auth?.loggedIn) const authState = useAppSelector((state) => state.auth) + const usersAppData = useAppSelector((state) => state.userAppData) // Ref to track if `subscribeForSigits` has been called const hasSubscribed = useRef(false) @@ -174,12 +175,10 @@ export const MainLayout = () => { }, [dispatch]) /** - * When authState change user logged in / or app reloaded - * we set robohash avatar in the global state based on user npub - * so that avatar will be consistent across the app when kind 0 is empty + * Subscribe for the sigits */ useEffect(() => { - if (authState && isLoggedIn) { + if (authState && isLoggedIn && usersAppData) { const pubkey = authState.usersPubkey || authState.keyPair?.public if (pubkey && !hasSubscribed.current) { @@ -190,6 +189,17 @@ export const MainLayout = () => { // Mark `subscribeForSigits` as called hasSubscribed.current = true } + } + }, [authState, isLoggedIn, usersAppData]) + + /** + * When authState change user logged in / or app reloaded + * we set robohash avatar in the global state based on user npub + * so that avatar will be consistent across the app when kind 0 is empty + */ + useEffect(() => { + if (authState && isLoggedIn) { + const pubkey = authState.usersPubkey || authState.keyPair?.public if (pubkey) { dispatch(setUserRobotImage(getRoboHashPicture(pubkey))) diff --git a/src/utils/nostr.ts b/src/utils/nostr.ts index fb96186..ec8c97e 100644 --- a/src/utils/nostr.ts +++ b/src/utils/nostr.ts @@ -875,7 +875,10 @@ export const subscribeForSigits = async (pubkey: string) => { } const processReceivedEvent = async (event: Event, difficulty: number = 5) => { - const processedEvents = store.getState().userAppData?.processedGiftWraps || [] + const processedEvents = store.getState().userAppData?.processedGiftWraps + + // Abort processing if userAppData is undefined + if (!processedEvents) return if (processedEvents.includes(event.id)) return From 1d1986f0829f4c1ca183b017150ecfdbaa96a86c Mon Sep 17 00:00:00 2001 From: enes Date: Sat, 12 Oct 2024 12:05:55 +0200 Subject: [PATCH 2/2] fix: clear hasSubscribed after the logout --- src/layouts/Main.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx index 0fd5526..19ac4d9 100644 --- a/src/layouts/Main.tsx +++ b/src/layouts/Main.tsx @@ -124,6 +124,9 @@ export const MainLayout = () => { if (opts.type === 'login' || opts.type === 'signup') { dispatch(updateNostrLoginAuthMethod(opts.method)) login() + } else if (opts.type === 'logout') { + // Clear `subscribeForSigits` as called after the logout + hasSubscribed.current = false } }