diff --git a/src/components/FeatureFlagModal/FeatureFlagModal.tsx b/src/components/FeatureFlagModal/FeatureFlagModal.tsx index 0c770c617c..597fa54e59 100644 --- a/src/components/FeatureFlagModal/FeatureFlagModal.tsx +++ b/src/components/FeatureFlagModal/FeatureFlagModal.tsx @@ -8,6 +8,7 @@ import { useInfoPoolPageFlag } from 'featureFlags/flags/infoPoolPage' import { useInfoTDPFlag } from 'featureFlags/flags/infoTDP' import { useMultichainUXFlag } from 'featureFlags/flags/multichainUx' import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/traceJsonRpc' +import { useUniswapXDefaultEnabledFlag } from 'featureFlags/flags/uniswapXDefault' import { useUniswapXEthOutputFlag } from 'featureFlags/flags/uniswapXEthOutput' import { useUniswapXExactOutputFlag } from 'featureFlags/flags/uniswapXExactOutput' import { useUniswapXSyntheticQuoteFlag } from 'featureFlags/flags/uniswapXUseSyntheticQuote' @@ -228,24 +229,6 @@ export default function FeatureFlagModal() { - - - + + + + + + @@ -47,13 +55,16 @@ export default function RouterPreferenceSettings() { { - if (routerPreference === RouterPreference.X) { + if (uniswapXInEffect) { // We need to remember if a user disables Uniswap X, so we don't show the opt-in flow again. dispatch(updateDisabledUniswapX({ disabledUniswapX: true })) } - setRouterPreference(routerPreference === RouterPreference.X ? RouterPreference.API : RouterPreference.X) + setRouterPreference(uniswapXInEffect ? RouterPreference.API : RouterPreference.X) }} /> @@ -73,7 +84,11 @@ export default function RouterPreferenceSettings() { isActive={routerPreference === RouterPreference.CLIENT} toggle={() => setRouterPreference( - routerPreference === RouterPreference.CLIENT ? RouterPreference.API : RouterPreference.CLIENT + routerPreference === RouterPreference.CLIENT + ? isUniswapXDefaultEnabled + ? RouterPreference.X + : RouterPreference.API + : RouterPreference.CLIENT ) } /> diff --git a/src/featureFlags/flags/uniswapXDefault.ts b/src/featureFlags/flags/uniswapXDefault.ts new file mode 100644 index 0000000000..2b34e8c2f9 --- /dev/null +++ b/src/featureFlags/flags/uniswapXDefault.ts @@ -0,0 +1,9 @@ +import { BaseVariant, FeatureFlag, useBaseFlag } from '../index' + +export function useUniswapXDefaultEnabledFlag(): BaseVariant { + return useBaseFlag(FeatureFlag.uniswapXDefaultEnabled) +} + +export function useUniswapXDefaultEnabled(): boolean { + return useUniswapXDefaultEnabledFlag() === BaseVariant.Enabled +} diff --git a/src/featureFlags/index.tsx b/src/featureFlags/index.tsx index b5220bfdac..941e1f6ffe 100644 --- a/src/featureFlags/index.tsx +++ b/src/featureFlags/index.tsx @@ -18,6 +18,7 @@ export enum FeatureFlag { infoTDP = 'info_tdp', infoPoolPage = 'info_pool_page', infoLiveViews = 'info_live_views', + uniswapXDefaultEnabled = 'uniswapx_default_enabled', } interface FeatureFlagsContextType { diff --git a/src/hooks/useUniversalRouter.ts b/src/hooks/useUniversalRouter.ts index 33ef09a707..055630194e 100644 --- a/src/hooks/useUniversalRouter.ts +++ b/src/hooks/useUniversalRouter.ts @@ -152,6 +152,7 @@ export function useUniversalRouterSwapCallback( }, [ account, analyticsContext, + blockNumber, chainId, fiatValues, options.deadline, diff --git a/src/lib/hooks/routing/useRoutingAPIArguments.ts b/src/lib/hooks/routing/useRoutingAPIArguments.ts index 08d93eca09..4405afe6a5 100644 --- a/src/lib/hooks/routing/useRoutingAPIArguments.ts +++ b/src/lib/hooks/routing/useRoutingAPIArguments.ts @@ -1,5 +1,6 @@ import { SkipToken, skipToken } from '@reduxjs/toolkit/query/react' import { Currency, CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core' +import { useUniswapXDefaultEnabled } from 'featureFlags/flags/uniswapXDefault' import { useUniswapXEthOutputEnabled } from 'featureFlags/flags/uniswapXEthOutput' import { useUniswapXExactOutputEnabled } from 'featureFlags/flags/uniswapXExactOutput' import { useUniswapXSyntheticQuoteEnabled } from 'featureFlags/flags/uniswapXUseSyntheticQuote' @@ -36,6 +37,7 @@ export function useRoutingAPIArguments({ const userDisabledUniswapX = useUserDisabledUniswapX() const uniswapXEthOutputEnabled = useUniswapXEthOutputEnabled() const uniswapXExactOutputEnabled = useUniswapXExactOutputEnabled() + const isUniswapXDefaultEnabled = useUniswapXDefaultEnabled() return useMemo( () => @@ -59,6 +61,7 @@ export function useRoutingAPIArguments({ userDisabledUniswapX, uniswapXEthOutputEnabled, uniswapXExactOutputEnabled, + isUniswapXDefaultEnabled, inputTax, outputTax, }, @@ -73,6 +76,7 @@ export function useRoutingAPIArguments({ uniswapXForceSyntheticQuotes, userDisabledUniswapX, uniswapXEthOutputEnabled, + isUniswapXDefaultEnabled, inputTax, outputTax, ] diff --git a/src/pages/Swap/index.tsx b/src/pages/Swap/index.tsx index 31259d4d11..be0dd24936 100644 --- a/src/pages/Swap/index.tsx +++ b/src/pages/Swap/index.tsx @@ -32,6 +32,7 @@ import TokenSafetyModal from 'components/TokenSafety/TokenSafetyModal' import { getChainInfo } from 'constants/chainInfo' import { asSupportedChain, isSupportedChain } from 'constants/chains' import { getSwapCurrencyId, TOKEN_SHORTHANDS } from 'constants/tokens' +import { useUniswapXDefaultEnabled } from 'featureFlags/flags/uniswapXDefault' import { useCurrency, useDefaultActiveTokens } from 'hooks/Tokens' import { useIsSwapUnsupported } from 'hooks/useIsSwapUnsupported' import { useLocalCurrencyPrice } from 'hooks/useLocalCurrencyPrice' @@ -565,6 +566,7 @@ export function Swap({ const switchingChain = useAppSelector((state) => state.wallets.switchingChain) const showOptInSmall = !useScreenSize().navSearchInputVisible const isDark = useIsDarkMode() + const isUniswapXDefaultEnabled = useUniswapXDefaultEnabled() const swapElement = ( @@ -791,14 +793,14 @@ export function Swap({ )} - {!showOptInSmall && } + {!showOptInSmall && !isUniswapXDefaultEnabled && } ) return ( <> {swapElement} - {showOptInSmall && } + {showOptInSmall && !isUniswapXDefaultEnabled && } ) } diff --git a/src/state/routing/types.ts b/src/state/routing/types.ts index 3f3644c40b..9c04b4990e 100644 --- a/src/state/routing/types.ts +++ b/src/state/routing/types.ts @@ -46,6 +46,7 @@ export interface GetQuoteArgs { uniswapXEthOutputEnabled: boolean uniswapXExactOutputEnabled: boolean userDisabledUniswapX: boolean + isUniswapXDefaultEnabled: boolean inputTax: Percent outputTax: Percent } diff --git a/src/state/routing/utils.ts b/src/state/routing/utils.ts index ed8f961e47..d2220fba0e 100644 --- a/src/state/routing/utils.ts +++ b/src/state/routing/utils.ts @@ -192,11 +192,20 @@ export async function transformRoutesToTrade( data: URAQuoteResponse, quoteMethod: QuoteMethod ): Promise { - const { tradeType, needsWrapIfUniswapX, routerPreference, account, amount } = args + const { + tradeType, + needsWrapIfUniswapX, + routerPreference, + account, + amount, + isUniswapXDefaultEnabled, + inputTax, + outputTax, + } = args - // During the opt-in period, only return UniswapX quotes if the user has turned on the setting, - // even if it is the better quote. - const showUniswapXTrade = data.routing === URAQuoteType.DUTCH_LIMIT && routerPreference === RouterPreference.X + const showUniswapXTrade = + data.routing === URAQuoteType.DUTCH_LIMIT && + (routerPreference === RouterPreference.X || (isUniswapXDefaultEnabled && routerPreference === RouterPreference.API)) const [currencyIn, currencyOut] = getTradeCurrencies(args, showUniswapXTrade) const { gasUseEstimateUSD, blockNumber, routes, gasUseEstimate } = getClassicTradeDetails( @@ -247,13 +256,13 @@ export async function transformRoutesToTrade( isUniswapXBetter, requestId: data.quote.requestId, quoteMethod, - inputTax: args.inputTax, - outputTax: args.outputTax, + inputTax, + outputTax, }) // During the opt-in period, only return UniswapX quotes if the user has turned on the setting, // even if it is the better quote. - if (isUniswapXBetter && args.routerPreference === RouterPreference.X) { + if (isUniswapXBetter && (routerPreference === RouterPreference.X || isUniswapXDefaultEnabled)) { const orderInfo = toDutchOrderInfo(data.quote.orderInfo) const wrapInfo = await getWrapInfo(needsWrapIfUniswapX, account, currencyIn.chainId, amount, usdCostPerGas)