diff --git a/src/pages/App.tsx b/src/pages/App.tsx index b918176478..9f99222a06 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -5,12 +5,14 @@ import ErrorBoundary from 'components/ErrorBoundary' import Loader from 'components/Icons/LoadingSpinner' import NavBar, { PageTabs } from 'components/NavBar' import { useFeatureFlagsIsLoaded } from 'featureFlags' +import { useUniswapXDefaultEnabled } from 'featureFlags/flags/uniswapXDefault' import { useAtom } from 'jotai' import { useBag } from 'nft/hooks/useBag' import { lazy, Suspense, useEffect, useLayoutEffect, useMemo, useState } from 'react' import { Navigate, Route, Routes, useLocation, useSearchParams } from 'react-router-dom' import { shouldDisableNFTRoutesAtom } from 'state/application/atoms' -import { useRouterPreference } from 'state/user/hooks' +import { RouterPreference } from 'state/routing/types' +import { useRouterPreference, useUserOptedOutOfUniswapX } from 'state/user/hooks' import { StatsigProvider, StatsigUser } from 'statsig-react' import styled from 'styled-components' import DarkModeQueryParamReader from 'theme/components/DarkModeQueryParamReader' @@ -79,7 +81,8 @@ export default function App() { const isDarkMode = useIsDarkMode() const [routerPreference] = useRouterPreference() const [scrolledState, setScrolledState] = useState(false) - + const isUniswapXDefaultEnabled = useUniswapXDefaultEnabled() + const userOptedOutOfUniswapX = useUserOptedOutOfUniswapX() const routerConfig = useRouterConfig() useEffect(() => { @@ -127,8 +130,21 @@ export default function App() { }, [isDarkMode]) useEffect(() => { + // 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) + return + } + + // In the transition period, override the stored API preference to UniswapX if the user hasn't opted out. + if (routerPreference === RouterPreference.API && !userOptedOutOfUniswapX) { + user.set(CustomUserProperties.ROUTER_PREFERENCE, RouterPreference.X) + return + } + + // 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]) + }, [routerPreference, isUniswapXDefaultEnabled, userOptedOutOfUniswapX]) useEffect(() => { const scrollListener = () => {