diff --git a/__mocks__/@react-native-firebase/crashlytics.ts b/__mocks__/@react-native-firebase/crashlytics.ts index 2df845ba0c69..9a7179041320 100644 --- a/__mocks__/@react-native-firebase/crashlytics.ts +++ b/__mocks__/@react-native-firebase/crashlytics.ts @@ -1,6 +1,6 @@ import type {FirebaseCrashlyticsTypes} from '@react-native-firebase/crashlytics'; -type CrashlyticsModule = Pick; +type CrashlyticsModule = Pick; type CrashlyticsMock = () => CrashlyticsModule; @@ -10,6 +10,7 @@ const crashlyticsMock: CrashlyticsMock = () => ({ log: jest.fn(), recordError: jest.fn(), setCrashlyticsCollectionEnabled: jest.fn(), + setUserId: jest.fn(), }); export default crashlyticsMock; diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 76f2b6ec19a8..ca9dec6d2279 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -31,6 +31,7 @@ import NetworkConnection from './libs/NetworkConnection'; import PushNotification from './libs/Notification/PushNotification'; import './libs/Notification/PushNotification/subscribePushNotification'; import Performance from './libs/Performance'; +import setCrashlyticsUserId from './libs/setCrashlyticsUserId'; import StartupTimer from './libs/StartupTimer'; // This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection import './libs/UnreadIndicatorUpdater'; @@ -238,6 +239,13 @@ function Expensify({ Audio.setAudioModeAsync({playsInSilentModeIOS: true}); }, []); + useEffect(() => { + if (!isAuthenticated) { + return; + } + setCrashlyticsUserId(session?.accountID ?? -1); + }, [isAuthenticated, session?.accountID]); + // Display a blank page until the onyx migration completes if (!isOnyxMigrated) { return null; diff --git a/src/components/TestCrash/index.native.tsx b/src/components/TestCrash/index.native.tsx new file mode 100644 index 000000000000..677f6b38d247 --- /dev/null +++ b/src/components/TestCrash/index.native.tsx @@ -0,0 +1,34 @@ +import React from 'react'; +import {View} from 'react-native'; +import Button from '@components/Button'; +import TestToolRow from '@components/TestToolRow'; +import useLocalize from '@hooks/useLocalize'; +import testCrash from '@libs/testCrash'; +import firebase from '../../../firebase.json'; + +/** + * Adds a button in native dev builds to test the crashlytics integration with user info. + */ +function TestCrash() { + const {translate} = useLocalize(); + + const isCrashlyticsDebugEnabled = firebase?.['react-native']?.crashlytics_debug_enabled ?? false; + + const toolRowTitle = translate('initialSettingsPage.troubleshoot.testCrash'); + + return ( + + {isCrashlyticsDebugEnabled ? ( + +