Commit f26a3306 authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

fix(L2): ensure chainIds match before fetching pool data (#2652)

* ensure chainIds match before fetching pool data

* debounce both input currencies, and only look for pairs on currencies that share a chainId

* pr feedback
parent 1846883e
...@@ -2,15 +2,14 @@ import { Currency, Token } from '@uniswap/sdk-core' ...@@ -2,15 +2,14 @@ import { Currency, Token } from '@uniswap/sdk-core'
import { useMemo } from 'react' import { useMemo } from 'react'
import { ADDITIONAL_BASES, BASES_TO_CHECK_TRADES_AGAINST, CUSTOM_BASES } from '../constants/routing' import { ADDITIONAL_BASES, BASES_TO_CHECK_TRADES_AGAINST, CUSTOM_BASES } from '../constants/routing'
import { useActiveWeb3React } from './web3'
export function useAllCurrencyCombinations(currencyA?: Currency, currencyB?: Currency): [Token, Token][] { export function useAllCurrencyCombinations(currencyA?: Currency, currencyB?: Currency): [Token, Token][] {
const { chainId } = useActiveWeb3React() const chainId = currencyA?.chainId
const [tokenA, tokenB] = chainId ? [currencyA?.wrapped, currencyB?.wrapped] : [undefined, undefined] const [tokenA, tokenB] = chainId ? [currencyA?.wrapped, currencyB?.wrapped] : [undefined, undefined]
const bases: Token[] = useMemo(() => { const bases: Token[] = useMemo(() => {
if (!chainId) return [] if (!chainId || chainId !== tokenB?.chainId) return []
const common = BASES_TO_CHECK_TRADES_AGAINST[chainId] ?? [] const common = BASES_TO_CHECK_TRADES_AGAINST[chainId] ?? []
const additionalA = tokenA ? ADDITIONAL_BASES[chainId]?.[tokenA.address] ?? [] : [] const additionalA = tokenA ? ADDITIONAL_BASES[chainId]?.[tokenA.address] ?? [] : []
......
...@@ -26,12 +26,12 @@ export function useBestV3Trade( ...@@ -26,12 +26,12 @@ export function useBestV3Trade(
const routingAPIEnabled = useRoutingAPIEnabled() const routingAPIEnabled = useRoutingAPIEnabled()
const isWindowVisible = useIsWindowVisible() const isWindowVisible = useIsWindowVisible()
const debouncedAmount = useDebounce(amountSpecified, 100) const [debouncedAmount, debouncedOtherCurrency] = useDebounce([amountSpecified, otherCurrency], 200)
const routingAPITrade = useRoutingAPITrade( const routingAPITrade = useRoutingAPITrade(
tradeType, tradeType,
routingAPIEnabled && isWindowVisible ? debouncedAmount : undefined, routingAPIEnabled && isWindowVisible ? debouncedAmount : undefined,
otherCurrency debouncedOtherCurrency
) )
const isLoading = amountSpecified !== undefined && debouncedAmount === undefined const isLoading = amountSpecified !== undefined && debouncedAmount === undefined
...@@ -43,10 +43,10 @@ export function useBestV3Trade( ...@@ -43,10 +43,10 @@ export function useBestV3Trade(
(tradeType === TradeType.EXACT_INPUT (tradeType === TradeType.EXACT_INPUT
? !routingAPITrade.trade.inputAmount.equalTo(amountSpecified) || ? !routingAPITrade.trade.inputAmount.equalTo(amountSpecified) ||
!amountSpecified.currency.equals(routingAPITrade.trade.inputAmount.currency) || !amountSpecified.currency.equals(routingAPITrade.trade.inputAmount.currency) ||
!otherCurrency?.equals(routingAPITrade.trade.outputAmount.currency) !debouncedOtherCurrency?.equals(routingAPITrade.trade.outputAmount.currency)
: !routingAPITrade.trade.outputAmount.equalTo(amountSpecified) || : !routingAPITrade.trade.outputAmount.equalTo(amountSpecified) ||
!amountSpecified.currency.equals(routingAPITrade.trade.outputAmount.currency) || !amountSpecified.currency.equals(routingAPITrade.trade.outputAmount.currency) ||
!otherCurrency?.equals(routingAPITrade.trade.inputAmount.currency)) !debouncedOtherCurrency?.equals(routingAPITrade.trade.inputAmount.currency))
const useFallback = !routingAPIEnabled || (!debouncing && routingAPITrade.state === V3TradeState.NO_ROUTE_FOUND) const useFallback = !routingAPIEnabled || (!debouncing && routingAPITrade.state === V3TradeState.NO_ROUTE_FOUND)
...@@ -54,7 +54,7 @@ export function useBestV3Trade( ...@@ -54,7 +54,7 @@ export function useBestV3Trade(
const bestV3Trade = useClientSideV3Trade( const bestV3Trade = useClientSideV3Trade(
tradeType, tradeType,
useFallback ? debouncedAmount : undefined, useFallback ? debouncedAmount : undefined,
useFallback ? otherCurrency : undefined useFallback ? debouncedOtherCurrency : undefined
) )
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment