···78import {msg} from '@lingui/macro'
79import {i18n, MessageDescriptor} from '@lingui/core'
80import HashtagScreen from '#/screens/Hashtag'
08182const navigationRef = createNavigationContainerRef<AllNavigatorParams>()
83···649 return
650 }
651 didInit = true
0652 const initMs = Math.round(
653 // @ts-ignore Emitted by Metro in the bundle prelude
654 performance.now() - global.__BUNDLE_START_TIME__,
655 )
656 console.log(`Time to first paint: ${initMs} ms`)
00657 if (__DEV__) {
658 // This log is noisy, so keep false committed
659 const shouldLog = false
···78import {msg} from '@lingui/macro'
79import {i18n, MessageDescriptor} from '@lingui/core'
80import HashtagScreen from '#/screens/Hashtag'
81+import {logEvent} from './lib/statsig/statsig'
8283const navigationRef = createNavigationContainerRef<AllNavigatorParams>()
84···650 return
651 }
652 didInit = true
653+654 const initMs = Math.round(
655 // @ts-ignore Emitted by Metro in the bundle prelude
656 performance.now() - global.__BUNDLE_START_TIME__,
657 )
658 console.log(`Time to first paint: ${initMs} ms`)
659+ logEvent('init', initMs)
660+661 if (__DEV__) {
662 // This log is noisy, so keep false committed
663 const shouldLog = false
+57-5
src/lib/statsig/statsig.tsx
···1import React from 'react'
000000023-export function useGate(_gateName: string) {
4- // Not enabled for native yet.
5- return false
0000000000000000000000000000006}
78export function Provider({children}: {children: React.ReactNode}) {
9- // Not enabled for native yet.
10- return children
00000000000000011}
···1import React from 'react'
2+import {
3+ Statsig,
4+ StatsigProvider,
5+ useGate as useStatsigGate,
6+} from 'statsig-react-native-expo'
7+import {useSession} from '../../state/session'
8+import {sha256} from 'js-sha256'
910+const statsigOptions = {
11+ environment: {
12+ tier: process.env.NODE_ENV === 'development' ? 'development' : 'production',
13+ },
14+ // Don't block on waiting for network. The fetched config will kick in on next load.
15+ // This ensures the UI is always consistent and doesn't update mid-session.
16+ // Note this makes cold load (no local storage) and private mode return `false` for all gates.
17+ initTimeoutMs: 1,
18+}
19+20+export function logEvent(
21+ eventName: string,
22+ value?: string | number | null,
23+ metadata?: Record<string, string> | null,
24+) {
25+ Statsig.logEvent(eventName, value, metadata)
26+}
27+28+export function useGate(gateName: string) {
29+ const {isLoading, value} = useStatsigGate(gateName)
30+ if (isLoading) {
31+ // This should not happen because of waitForInitialization={true}.
32+ console.error('Did not expected isLoading to ever be true.')
33+ }
34+ return value
35+}
36+37+function toStatsigUser(did: string | undefined) {
38+ let userID: string | undefined
39+ if (did) {
40+ userID = sha256(did)
41+ }
42+ return {userID}
43}
4445export function Provider({children}: {children: React.ReactNode}) {
46+ const {currentAccount} = useSession()
47+ const currentStatsigUser = React.useMemo(
48+ () => toStatsigUser(currentAccount?.did),
49+ [currentAccount?.did],
50+ )
51+ return (
52+ <StatsigProvider
53+ sdkKey="client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV"
54+ mountKey={currentStatsigUser.userID}
55+ user={currentStatsigUser}
56+ // This isn't really blocking due to short initTimeoutMs above.
57+ // However, it ensures `isLoading` is always `false`.
58+ waitForInitialization={true}
59+ options={statsigOptions}>
60+ {children}
61+ </StatsigProvider>
62+ )
63}
+13-1
src/lib/statsig/statsig.web.tsx
···1import React from 'react'
2-import {StatsigProvider, useGate as useStatsigGate} from 'statsig-react'
00003import {useSession} from '../../state/session'
4import {sha256} from 'js-sha256'
5···11 // This ensures the UI is always consistent and doesn't update mid-session.
12 // Note this makes cold load (no local storage) and private mode return `false` for all gates.
13 initTimeoutMs: 1,
0000000014}
1516export function useGate(gateName: string) {
···1import React from 'react'
2+import {
3+ Statsig,
4+ StatsigProvider,
5+ useGate as useStatsigGate,
6+} from 'statsig-react'
7import {useSession} from '../../state/session'
8import {sha256} from 'js-sha256'
9···15 // This ensures the UI is always consistent and doesn't update mid-session.
16 // Note this makes cold load (no local storage) and private mode return `false` for all gates.
17 initTimeoutMs: 1,
18+}
19+20+export function logEvent(
21+ eventName: string,
22+ value?: string | number | null,
23+ metadata?: Record<string, string> | null,
24+) {
25+ Statsig.logEvent(eventName, value, metadata)
26}
2728export function useGate(gateName: string) {