Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delay setting user.router_preference until statsig and redux initialize #7458

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ErrorBoundary from 'components/ErrorBoundary'
import Loader from 'components/Icons/LoadingSpinner'
import NavBar, { PageTabs } from 'components/NavBar'
import { UK_BANNER_HEIGHT, UK_BANNER_HEIGHT_MD, UK_BANNER_HEIGHT_SM, UkBanner } from 'components/NavBar/UkBanner'
import { useFeatureFlagsIsLoaded } from 'featureFlags'
import { FeatureFlag, useFeatureFlagsIsLoaded } from 'featureFlags'
import { useUniswapXDefaultEnabled } from 'featureFlags/flags/uniswapXDefault'
import { useAtom } from 'jotai'
import { useBag } from 'nft/hooks/useBag'
Expand All @@ -16,7 +16,7 @@ import { useAppSelector } from 'state/hooks'
import { AppState } from 'state/reducer'
import { RouterPreference } from 'state/routing/types'
import { useRouterPreference, useUserOptedOutOfUniswapX } from 'state/user/hooks'
import { StatsigProvider, StatsigUser } from 'statsig-react'
import { StatsigProvider, StatsigUser, useGate } from 'statsig-react'
import styled from 'styled-components'
import DarkModeQueryParamReader from 'theme/components/DarkModeQueryParamReader'
import { useIsDarkMode } from 'theme/components/ThemeToggle'
Expand Down Expand Up @@ -214,6 +214,8 @@ function UserPropertyUpdater() {
const [routerPreference] = useRouterPreference()
const userOptedOutOfUniswapX = useUserOptedOutOfUniswapX()
const isUniswapXDefaultEnabled = useUniswapXDefaultEnabled()
const { isLoading: isUniswapXDefaultLoading } = useGate(FeatureFlag.uniswapXDefaultEnabled)
const rehydrated = useAppSelector((state) => state._persist.rehydrated)

useEffect(() => {
// User properties *must* be set before sending corresponding event properties,
Expand Down Expand Up @@ -246,6 +248,8 @@ function UserPropertyUpdater() {
}, [isDarkMode])

useEffect(() => {
if (isUniswapXDefaultLoading || !rehydrated) return

// If we're not in the transition period to UniswapX opt-out, set the router preference to whatever is specified.
if (!isUniswapXDefaultEnabled) {
user.set(CustomUserProperties.ROUTER_PREFERENCE, routerPreference)
Expand All @@ -260,6 +264,6 @@ function UserPropertyUpdater() {

// Otherwise, the user has opted out or their preference is UniswapX/client, so set the preference to whatever is specified.
user.set(CustomUserProperties.ROUTER_PREFERENCE, routerPreference)
}, [routerPreference, isUniswapXDefaultEnabled, userOptedOutOfUniswapX])
}, [routerPreference, isUniswapXDefaultEnabled, userOptedOutOfUniswapX, isUniswapXDefaultLoading, rehydrated])
return null
}