feat: Use routing-api or URA for price fetches behind feature flag (#6740)
use routing-api or URA for price fetches behind feature flag
This commit is contained in:
parent
4235b57cd8
commit
04e4335cc2
@ -1,6 +1,7 @@
|
||||
import { BaseVariant, FeatureFlag, featureFlagSettings, useUpdateFlag } from 'featureFlags'
|
||||
import { useNativeUSDCArbitrumFlag } from 'featureFlags/flags/nativeUsdcArbitrum'
|
||||
import { DetailsV2Variant, useDetailsV2Flag } from 'featureFlags/flags/nftDetails'
|
||||
import { useRoutingAPIForPriceFlag } from 'featureFlags/flags/priceRoutingApi'
|
||||
import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/traceJsonRpc'
|
||||
import { UnifiedRouterVariant, useRoutingAPIV2Flag } from 'featureFlags/flags/unifiedRouter'
|
||||
import { useUpdateAtom } from 'jotai/utils'
|
||||
@ -221,6 +222,12 @@ export default function FeatureFlagModal() {
|
||||
featureFlag={FeatureFlag.nativeUsdcArbitrum}
|
||||
label="Enable Circle native USDC on Arbitrum"
|
||||
/>
|
||||
<FeatureFlagOption
|
||||
variant={BaseVariant}
|
||||
value={useRoutingAPIForPriceFlag()}
|
||||
featureFlag={FeatureFlag.routingAPIPrice}
|
||||
label="Use the URA or routing-api for price fetches"
|
||||
/>
|
||||
<FeatureFlagGroup name="Debug">
|
||||
<FeatureFlagOption
|
||||
variant={TraceJsonRpcVariant}
|
||||
|
9
src/featureFlags/flags/priceRoutingApi.ts
Normal file
9
src/featureFlags/flags/priceRoutingApi.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { BaseVariant, FeatureFlag, useBaseFlag } from '../index'
|
||||
|
||||
export function useRoutingAPIForPriceFlag(): BaseVariant {
|
||||
return useBaseFlag(FeatureFlag.routingAPIPrice)
|
||||
}
|
||||
|
||||
export function useRoutingAPIForPrice(): boolean {
|
||||
return useRoutingAPIForPriceFlag() === BaseVariant.Enabled
|
||||
}
|
@ -13,6 +13,7 @@ export enum FeatureFlag {
|
||||
uraEnabled = 'ura_enabled',
|
||||
debounceSwapQuote = 'debounce_swap_quote',
|
||||
nativeUsdcArbitrum = 'web_usdc_arbitrum',
|
||||
routingAPIPrice = 'routing_api_price',
|
||||
}
|
||||
|
||||
interface FeatureFlagsContextType {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
|
||||
import { useRoutingAPIForPrice } from 'featureFlags/flags/priceRoutingApi'
|
||||
import { useMemo } from 'react'
|
||||
import { GetQuoteArgs, INTERNAL_ROUTER_PREFERENCE_PRICE, RouterPreference } from 'state/routing/slice'
|
||||
import { currencyAddressForSwapQuote } from 'state/routing/utils'
|
||||
@ -21,6 +22,7 @@ export function useRoutingAPIArguments({
|
||||
tradeType: TradeType
|
||||
routerPreference: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE
|
||||
}): GetQuoteArgs | undefined {
|
||||
const isRoutingAPIPrice = useRoutingAPIForPrice()
|
||||
return useMemo(
|
||||
() =>
|
||||
!tokenIn || !tokenOut || !amount || tokenIn.equals(tokenOut) || tokenIn.wrapped.equals(tokenOut.wrapped)
|
||||
@ -37,7 +39,8 @@ export function useRoutingAPIArguments({
|
||||
tokenOutSymbol: tokenOut.wrapped.symbol,
|
||||
routerPreference,
|
||||
tradeType,
|
||||
isRoutingAPIPrice,
|
||||
},
|
||||
[amount, routerPreference, tokenIn, tokenOut, tradeType]
|
||||
[amount, routerPreference, tokenIn, tokenOut, tradeType, isRoutingAPIPrice]
|
||||
)
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ export interface GetQuoteArgs {
|
||||
amount: string
|
||||
routerPreference: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE
|
||||
tradeType: TradeType
|
||||
isRoutingAPIPrice?: boolean
|
||||
}
|
||||
|
||||
enum QuoteState {
|
||||
@ -83,7 +84,7 @@ export const routingApi = createApi({
|
||||
)
|
||||
},
|
||||
async queryFn(args, _api, _extraOptions, fetch) {
|
||||
if (shouldUseAPIRouter(args.routerPreference)) {
|
||||
if (shouldUseAPIRouter(args)) {
|
||||
try {
|
||||
const { tokenInAddress, tokenInChainId, tokenOutAddress, tokenOutChainId, amount, tradeType } = args
|
||||
const type = isExactInput(tradeType) ? 'exactIn' : 'exactOut'
|
||||
|
@ -187,8 +187,11 @@ export function currencyAddressForSwapQuote(currency: Currency): string {
|
||||
return currency.address
|
||||
}
|
||||
|
||||
export function shouldUseAPIRouter(
|
||||
routerPreference?: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE
|
||||
): boolean {
|
||||
export function shouldUseAPIRouter(args: GetQuoteArgs): boolean {
|
||||
const { routerPreference, isRoutingAPIPrice } = args
|
||||
if (routerPreference === INTERNAL_ROUTER_PREFERENCE_PRICE && isRoutingAPIPrice) {
|
||||
return true
|
||||
}
|
||||
|
||||
return routerPreference === RouterPreference.API || routerPreference === RouterPreference.AUTO
|
||||
}
|
||||
|
@ -54,8 +54,7 @@ export const routingApiV2 = createApi({
|
||||
)
|
||||
},
|
||||
async queryFn(args: GetQuoteArgs, _api, _extraOptions, fetch) {
|
||||
const routerPreference = args.routerPreference
|
||||
if (shouldUseAPIRouter(routerPreference)) {
|
||||
if (shouldUseAPIRouter(args)) {
|
||||
try {
|
||||
const { tokenInAddress, tokenInChainId, tokenOutAddress, tokenOutChainId, amount, tradeType } = args
|
||||
const type = isExactInput(tradeType) ? 'EXACT_INPUT' : 'EXACT_OUTPUT'
|
||||
|
Loading…
Reference in New Issue
Block a user