fix: delay setting user.router_preference until statsig and redux initialize (#7458)
This commit is contained in:
parent
7001452f89
commit
ad1e2c60a1
@ -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'
|
||||
@ -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'
|
||||
@ -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,
|
||||
@ -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)
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user