Add `native_pwi_disabled` feature gate experiment (#4507)
* Add native_pwi_disabled feature gate experiment * Use constzio/stable
parent
f5f3bd8130
commit
332524b7de
|
@ -14,7 +14,11 @@ import * as SplashScreen from 'expo-splash-screen'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {Provider as StatsigProvider} from '#/lib/statsig/statsig'
|
import {
|
||||||
|
initialize,
|
||||||
|
Provider as StatsigProvider,
|
||||||
|
tryFetchGates,
|
||||||
|
} from '#/lib/statsig/statsig'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {MessagesProvider} from '#/state/messages'
|
import {MessagesProvider} from '#/state/messages'
|
||||||
import {init as initPersistedState} from '#/state/persisted'
|
import {init as initPersistedState} from '#/state/persisted'
|
||||||
|
@ -69,6 +73,9 @@ function InnerApp() {
|
||||||
try {
|
try {
|
||||||
if (account) {
|
if (account) {
|
||||||
await resumeSession(account)
|
await resumeSession(account)
|
||||||
|
} else {
|
||||||
|
await initialize()
|
||||||
|
await tryFetchGates(undefined, 'prefer-fresh-gates')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`session: resume failed`, {message: e})
|
logger.error(`session: resume failed`, {message: e})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export type Gate =
|
export type Gate =
|
||||||
// Keep this alphabetic please.
|
// Keep this alphabetic please.
|
||||||
|
| 'native_pwi_disabled'
|
||||||
| 'request_notifications_permission_after_onboarding_v2'
|
| 'request_notifications_permission_after_onboarding_v2'
|
||||||
| 'show_avi_follow_button'
|
| 'show_avi_follow_button'
|
||||||
| 'show_follow_back_label_v2'
|
| 'show_follow_back_label_v2'
|
||||||
|
|
|
@ -14,6 +14,8 @@ import {useNonReactiveCallback} from '../hooks/useNonReactiveCallback'
|
||||||
import {LogEvents} from './events'
|
import {LogEvents} from './events'
|
||||||
import {Gate} from './gates'
|
import {Gate} from './gates'
|
||||||
|
|
||||||
|
const SDK_KEY = 'client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV'
|
||||||
|
|
||||||
type StatsigUser = {
|
type StatsigUser = {
|
||||||
userID: string | undefined
|
userID: string | undefined
|
||||||
// TODO: Remove when enough users have custom.platform:
|
// TODO: Remove when enough users have custom.platform:
|
||||||
|
@ -251,7 +253,7 @@ AppState.addEventListener('change', (state: AppStateStatus) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
export async function tryFetchGates(
|
export async function tryFetchGates(
|
||||||
did: string,
|
did: string | undefined,
|
||||||
strategy: 'prefer-low-latency' | 'prefer-fresh-gates',
|
strategy: 'prefer-low-latency' | 'prefer-fresh-gates',
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
@ -275,6 +277,10 @@ export async function tryFetchGates(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function initialize() {
|
||||||
|
return Statsig.initialize(SDK_KEY, null, createStatsigOptions([]))
|
||||||
|
}
|
||||||
|
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
const {currentAccount, accounts} = useSession()
|
const {currentAccount, accounts} = useSession()
|
||||||
const did = currentAccount?.did
|
const did = currentAccount?.did
|
||||||
|
@ -320,7 +326,7 @@ export function Provider({children}: {children: React.ReactNode}) {
|
||||||
<GateCache.Provider value={gateCache}>
|
<GateCache.Provider value={gateCache}>
|
||||||
<StatsigProvider
|
<StatsigProvider
|
||||||
key={did}
|
key={did}
|
||||||
sdkKey="client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV"
|
sdkKey={SDK_KEY}
|
||||||
mountKey={currentStatsigUser.userID}
|
mountKey={currentStatsigUser.userID}
|
||||||
user={currentStatsigUser}
|
user={currentStatsigUser}
|
||||||
// This isn't really blocking due to short initTimeoutMs above.
|
// This isn't really blocking due to short initTimeoutMs above.
|
||||||
|
|
|
@ -29,7 +29,8 @@ import {
|
||||||
useLoggedOutView,
|
useLoggedOutView,
|
||||||
useLoggedOutViewControls,
|
useLoggedOutViewControls,
|
||||||
} from '#/state/shell/logged-out'
|
} from '#/state/shell/logged-out'
|
||||||
import {isWeb} from 'platform/detection'
|
import {useGate} from 'lib/statsig/statsig'
|
||||||
|
import {isNative, isWeb} from 'platform/detection'
|
||||||
import {Deactivated} from '#/screens/Deactivated'
|
import {Deactivated} from '#/screens/Deactivated'
|
||||||
import {Onboarding} from '#/screens/Onboarding'
|
import {Onboarding} from '#/screens/Onboarding'
|
||||||
import {SignupQueued} from '#/screens/SignupQueued'
|
import {SignupQueued} from '#/screens/SignupQueued'
|
||||||
|
@ -50,6 +51,7 @@ function NativeStackNavigator({
|
||||||
screenOptions,
|
screenOptions,
|
||||||
...rest
|
...rest
|
||||||
}: NativeStackNavigatorProps) {
|
}: NativeStackNavigatorProps) {
|
||||||
|
const gate = useGate()
|
||||||
// --- this is copy and pasted from the original native stack navigator ---
|
// --- this is copy and pasted from the original native stack navigator ---
|
||||||
const {state, descriptors, navigation, NavigationContent} =
|
const {state, descriptors, navigation, NavigationContent} =
|
||||||
useNavigationBuilder<
|
useNavigationBuilder<
|
||||||
|
@ -100,7 +102,11 @@ function NativeStackNavigator({
|
||||||
const {showLoggedOut} = useLoggedOutView()
|
const {showLoggedOut} = useLoggedOutView()
|
||||||
const {setShowLoggedOut} = useLoggedOutViewControls()
|
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||||
const {isMobile, isTabletOrMobile} = useWebMediaQueries()
|
const {isMobile, isTabletOrMobile} = useWebMediaQueries()
|
||||||
if ((!PWI_ENABLED || activeRouteRequiresAuth) && !hasSession) {
|
const isNativePWIDisabled = isNative && gate('native_pwi_disabled')
|
||||||
|
if (
|
||||||
|
(!PWI_ENABLED || isNativePWIDisabled || activeRouteRequiresAuth) &&
|
||||||
|
!hasSession
|
||||||
|
) {
|
||||||
return <LoggedOut />
|
return <LoggedOut />
|
||||||
}
|
}
|
||||||
if (hasSession && currentAccount?.signupQueued) {
|
if (hasSession && currentAccount?.signupQueued) {
|
||||||
|
|
Loading…
Reference in New Issue