Bluesky app fork with some witchin' additions 💫

Add `native_pwi_disabled` feature gate experiment (#4507)

* Add native_pwi_disabled feature gate experiment

* Use const

authored by

Eric Bailey and committed by
GitHub
332524b7 f5f3bd81

+25 -5
+8 -1
src/App.native.tsx
··· 14 14 import {msg} from '@lingui/macro' 15 15 import {useLingui} from '@lingui/react' 16 16 17 - import {Provider as StatsigProvider} from '#/lib/statsig/statsig' 17 + import { 18 + initialize, 19 + Provider as StatsigProvider, 20 + tryFetchGates, 21 + } from '#/lib/statsig/statsig' 18 22 import {logger} from '#/logger' 19 23 import {MessagesProvider} from '#/state/messages' 20 24 import {init as initPersistedState} from '#/state/persisted' ··· 69 73 try { 70 74 if (account) { 71 75 await resumeSession(account) 76 + } else { 77 + await initialize() 78 + await tryFetchGates(undefined, 'prefer-fresh-gates') 72 79 } 73 80 } catch (e) { 74 81 logger.error(`session: resume failed`, {message: e})
+1
src/lib/statsig/gates.ts
··· 1 1 export type Gate = 2 2 // Keep this alphabetic please. 3 + | 'native_pwi_disabled' 3 4 | 'request_notifications_permission_after_onboarding_v2' 4 5 | 'show_avi_follow_button' 5 6 | 'show_follow_back_label_v2'
+8 -2
src/lib/statsig/statsig.tsx
··· 14 14 import {LogEvents} from './events' 15 15 import {Gate} from './gates' 16 16 17 + const SDK_KEY = 'client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV' 18 + 17 19 type StatsigUser = { 18 20 userID: string | undefined 19 21 // TODO: Remove when enough users have custom.platform: ··· 251 253 }) 252 254 253 255 export async function tryFetchGates( 254 - did: string, 256 + did: string | undefined, 255 257 strategy: 'prefer-low-latency' | 'prefer-fresh-gates', 256 258 ) { 257 259 try { ··· 273 275 // Don't leak errors to the calling code, this is meant to be always safe. 274 276 console.error(e) 275 277 } 278 + } 279 + 280 + export function initialize() { 281 + return Statsig.initialize(SDK_KEY, null, createStatsigOptions([])) 276 282 } 277 283 278 284 export function Provider({children}: {children: React.ReactNode}) { ··· 320 326 <GateCache.Provider value={gateCache}> 321 327 <StatsigProvider 322 328 key={did} 323 - sdkKey="client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV" 329 + sdkKey={SDK_KEY} 324 330 mountKey={currentStatsigUser.userID} 325 331 user={currentStatsigUser} 326 332 // This isn't really blocking due to short initTimeoutMs above.
+8 -2
src/view/shell/createNativeStackNavigatorWithAuth.tsx
··· 29 29 useLoggedOutView, 30 30 useLoggedOutViewControls, 31 31 } from '#/state/shell/logged-out' 32 - import {isWeb} from 'platform/detection' 32 + import {useGate} from 'lib/statsig/statsig' 33 + import {isNative, isWeb} from 'platform/detection' 33 34 import {Deactivated} from '#/screens/Deactivated' 34 35 import {Onboarding} from '#/screens/Onboarding' 35 36 import {SignupQueued} from '#/screens/SignupQueued' ··· 50 51 screenOptions, 51 52 ...rest 52 53 }: NativeStackNavigatorProps) { 54 + const gate = useGate() 53 55 // --- this is copy and pasted from the original native stack navigator --- 54 56 const {state, descriptors, navigation, NavigationContent} = 55 57 useNavigationBuilder< ··· 100 102 const {showLoggedOut} = useLoggedOutView() 101 103 const {setShowLoggedOut} = useLoggedOutViewControls() 102 104 const {isMobile, isTabletOrMobile} = useWebMediaQueries() 103 - if ((!PWI_ENABLED || activeRouteRequiresAuth) && !hasSession) { 105 + const isNativePWIDisabled = isNative && gate('native_pwi_disabled') 106 + if ( 107 + (!PWI_ENABLED || isNativePWIDisabled || activeRouteRequiresAuth) && 108 + !hasSession 109 + ) { 104 110 return <LoggedOut /> 105 111 } 106 112 if (hasSession && currentAccount?.signupQueued) {