From 5b9439312b68c8d2f4845be22cbce14c68aa7972 Mon Sep 17 00:00:00 2001 From: Celine Sarafa Date: Fri, 8 Mar 2024 04:02:35 +0100 Subject: [PATCH] chore: register on web load --- src/contexts/W3iContext/index.tsx | 9 ++++++++- src/utils/notifications.ts | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/contexts/W3iContext/index.tsx b/src/contexts/W3iContext/index.tsx index ad885063..02bd1aab 100644 --- a/src/contexts/W3iContext/index.tsx +++ b/src/contexts/W3iContext/index.tsx @@ -4,7 +4,7 @@ import { useAllSubscriptions, useWeb3InboxAccount, useWeb3InboxClient } from '@w import W3iContext from '@/contexts/W3iContext/context' import { useAuthState } from '@/contexts/W3iContext/hooks/authHooks' -import { setupSubscriptionsSymkeys } from '@/utils/notifications' +import { registerWithEcho, setupSubscriptionsSymkeys } from '@/utils/notifications' interface W3iContextProviderProps { children: React.ReactNode | React.ReactNode[] @@ -21,6 +21,13 @@ const W3iContextProvider: React.FC = ({ children }) => setupSubscriptionsSymkeys(activeSubscriptions?.map(sub => [sub.topic, sub.symKey]) ?? []) }, [activeSubscriptions]) + useEffect(() => { + // register on client init + if(client && window?.Notification.permission === 'granted') { + registerWithEcho(client) + } + }, [client]) + return ( { } export const registerWithEcho = async (client: Web3InboxClient) => { + console.log(">>> Registering with echo...") if (await requireNotifyPermission()) { + console.log(">>> Got permission") const token = await getFirebaseToken() + console.log(">>> Got token", token) const clientId = await client.registerWithPushServer(token, 'fcm') + console.log(">>> Got clientId", clientId) const [, putRegistrationToken ] = await getDbEchoRegistrations() await putRegistrationToken(clientId, token) + + console.log(">>> put token") } }