fix: usdc prices shouldn't reload when v3 prices reload

This commit is contained in:
Moody Salem 2021-05-27 15:28:45 -05:00
parent 8930627064
commit 7f1def300d
No known key found for this signature in database
GPG Key ID: 8CB5CD10385138DB

@ -2,12 +2,12 @@ import { Currency, CurrencyAmount, Price, Token } from '@uniswap/sdk-core'
import { useMemo } from 'react'
import { USDC } from '../constants/tokens'
import { useV2TradeExactOut } from './useV2Trade'
import { useBestV3TradeExactOut, V3TradeState } from './useBestV3Trade'
import { useBestV3TradeExactOut } from './useBestV3Trade'
import { useActiveWeb3React } from './web3'
// USDC amount used when calculating spot price for a given currency.
// The amount is large enough to filter low liquidity pairs.
const usdcCurrencyAmount = CurrencyAmount.fromRawAmount(USDC, 100_000e6)
const USDC_CURRENCY_AMOUNT_OUT = CurrencyAmount.fromRawAmount(USDC, 100_000e6)
/**
* Returns the price in USDC of the input currency
@ -16,10 +16,10 @@ const usdcCurrencyAmount = CurrencyAmount.fromRawAmount(USDC, 100_000e6)
export default function useUSDCPrice(currency?: Currency): Price<Currency, Token> | undefined {
const { chainId } = useActiveWeb3React()
const v2USDCTrade = useV2TradeExactOut(currency, chainId === 1 ? usdcCurrencyAmount : undefined, {
const v2USDCTrade = useV2TradeExactOut(currency, chainId === 1 ? USDC_CURRENCY_AMOUNT_OUT : undefined, {
maxHops: 2,
})
const v3USDCTrade = useBestV3TradeExactOut(currency, chainId === 1 ? usdcCurrencyAmount : undefined)
const v3USDCTrade = useBestV3TradeExactOut(currency, chainId === 1 ? USDC_CURRENCY_AMOUNT_OUT : undefined)
return useMemo(() => {
if (!currency || !chainId) {
@ -46,7 +46,7 @@ export default function useUSDCPrice(currency?: Currency): Price<Currency, Token
if (v2USDCTrade) {
const { numerator, denominator } = v2USDCTrade.route.midPrice
return new Price(currency, USDC, denominator, numerator)
} else if (v3USDCTrade.state === V3TradeState.VALID && v3USDCTrade.trade) {
} else if (v3USDCTrade.trade) {
const { numerator, denominator } = v3USDCTrade.trade.route.midPrice
return new Price(currency, USDC, denominator, numerator)
}