From ad1e2c60a1d6c295a408b149ea660a3b6caa7afb Mon Sep 17 00:00:00 2001 From: eddie <66155195+just-toby@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:42:57 -0700 Subject: [PATCH] fix: delay setting user.router_preference until statsig and redux initialize (#7458) --- src/pages/App.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 3f15ce0356..f844b5bcc9 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -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 }