move fcm token storage (#1175)

* move fcm token from proving store to setting store for better separation of concerns.

* use analytics on adapter

* Revert "use analytics on adapter"

This reverts commit 4854d6fa87.

* prettier

* please be good

* ik heb oopsie wooopsie

* remove
This commit is contained in:
Aaron DeRuvo
2025-10-01 12:59:00 +02:00
committed by GitHub
parent 9131cd3649
commit 1856c9b325
14 changed files with 68 additions and 106 deletions

View File

@@ -20,6 +20,7 @@ import { navigationRef } from '@/navigation';
import { unsafe_getPrivateKey } from '@/providers/authProvider';
import { selfClientDocumentsAdapter } from '@/providers/passportDataProvider';
import { logNFCEvent, logProofEvent } from '@/Sentry';
import { useSettingStore } from '@/stores/settingStore';
import analytics from '@/utils/analytics';
type GlobalCrypto = { crypto?: { subtle?: Crypto['subtle'] } };
@@ -95,15 +96,6 @@ export const SelfClientProvider = ({ children }: PropsWithChildren) => {
auth: {
getPrivateKey: () => unsafe_getPrivateKey(),
},
notification: {
registerDeviceToken: async (sessionId, deviceToken, isMock) => {
// Forward to our app-level function which handles staging vs production
// and also fetches the token if not provided
const { registerDeviceToken: registerFirebaseDeviceToken } =
await import('@/utils/notifications/notificationService');
return registerFirebaseDeviceToken(sessionId, deviceToken, isMock);
},
},
}),
[],
);
@@ -158,6 +150,35 @@ export const SelfClientProvider = ({ children }: PropsWithChildren) => {
}
});
addListener(
SdkEvents.PROVING_BEGIN_GENERATION,
async ({ uuid, isMock, context }) => {
const { fcmToken } = useSettingStore.getState();
if (fcmToken) {
try {
analytics().trackEvent('DEVICE_TOKEN_REG_STARTED');
logProofEvent('info', 'Device token registration started', context);
const { registerDeviceToken: registerFirebaseDeviceToken } =
await import('@/utils/notifications/notificationService');
await registerFirebaseDeviceToken(uuid, fcmToken, isMock);
analytics().trackEvent('DEVICE_TOKEN_REG_SUCCESS');
logProofEvent('info', 'Device token registration success', context);
} catch (error) {
logProofEvent('warn', 'Device token registration failed', context, {
error: error instanceof Error ? error.message : String(error),
});
console.error('Error registering device token:', error);
analytics().trackEvent('DEVICE_TOKEN_REG_FAILED', {
message: error instanceof Error ? error.message : String(error),
});
}
}
},
);
addListener(SdkEvents.PROOF_EVENT, ({ level, context, event, details }) => {
// Log proof events for monitoring/debugging
logProofEvent(level, event, context, details);

View File

@@ -21,6 +21,7 @@ import { Title } from '@/components/typography/Title';
import useHapticNavigation from '@/hooks/useHapticNavigation';
import { ExpandableBottomLayout } from '@/layouts/ExpandableBottomLayout';
import { styles } from '@/screens/prove/ProofRequestStatusScreen';
import { useSettingStore } from '@/stores/settingStore';
import { flushAllAnalytics, trackNfcEvent } from '@/utils/analytics';
import { black, white } from '@/utils/colors';
import { notificationSuccess } from '@/utils/haptic';
@@ -40,8 +41,8 @@ const ConfirmBelongingScreen: React.FC<ConfirmBelongingScreenProps> = () => {
const [_requestingPermission, setRequestingPermission] = useState(false);
const currentState = useProvingStore(state => state.currentState);
const init = useProvingStore(state => state.init);
const setFcmToken = useProvingStore(state => state.setFcmToken);
const setUserConfirmed = useProvingStore(state => state.setUserConfirmed);
const setFcmToken = useSettingStore(state => state.setFcmToken);
const isReadyToProve = currentState === 'ready_to_prove';
useEffect(() => {
notificationSuccess();
@@ -74,7 +75,7 @@ const ConfirmBelongingScreen: React.FC<ConfirmBelongingScreenProps> = () => {
if (permissionGranted) {
const token = await getFCMToken();
if (token) {
setFcmToken(token, selfClient);
setFcmToken(token);
trackEvent(ProofEvents.FCM_TOKEN_STORED);
}
}

View File

@@ -20,6 +20,8 @@ interface PersistedSettingsState {
isDevMode: boolean;
setDevModeOn: () => void;
setDevModeOff: () => void;
fcmToken: string | null;
setFcmToken: (token: string | null) => void;
}
interface NonPersistedSettingsState {
@@ -69,6 +71,9 @@ export const useSettingStore = create<SettingsState>()(
setDevModeOn: () => set({ isDevMode: true }),
setDevModeOff: () => set({ isDevMode: false }),
fcmToken: null,
setFcmToken: (token: string | null) => set({ fcmToken: token }),
// Non-persisted state (will not be saved to storage)
hideNetworkModal: false,
setHideNetworkModal: (hideNetworkModal: boolean) => {