fix: don't show a price impact warning if the user is (un)wrapping (#6059)

This commit is contained in:
Jordan Frankfurt 2023-03-03 13:04:14 -05:00 committed by GitHub
parent 2df0ca178c
commit ac8d294ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

@ -57,16 +57,18 @@ export function useClientSideV3Trade<TTradeType extends TradeType>(
gasRequired: chainId ? QUOTE_GAS_OVERRIDES[chainId] ?? DEFAULT_GAS_QUOTE : undefined,
})
const currenciesAreTheSame = useMemo(
() => currencyIn && currencyOut && (currencyIn.equals(currencyOut) || currencyIn.wrapped.equals(currencyOut)),
[currencyIn, currencyOut]
)
return useMemo(() => {
if (
!amountSpecified ||
!currencyIn ||
!currencyOut ||
quotesResults.some(({ valid }) => !valid) ||
// skip when tokens are the same
(tradeType === TradeType.EXACT_INPUT
? amountSpecified.currency.equals(currencyOut)
: amountSpecified.currency.equals(currencyIn))
currenciesAreTheSame
) {
return {
state: TradeState.INVALID,
@ -144,5 +146,5 @@ export function useClientSideV3Trade<TTradeType extends TradeType>(
tradeType,
}),
}
}, [amountSpecified, currencyIn, currencyOut, quotesResults, routes, routesLoading, tradeType])
}, [amountSpecified, currenciesAreTheSame, currencyIn, currencyOut, quotesResults, routes, routesLoading, tradeType])
}

@ -22,7 +22,7 @@ export function useRoutingAPIArguments({
}) {
return useMemo(
() =>
!tokenIn || !tokenOut || !amount || tokenIn.equals(tokenOut)
!tokenIn || !tokenOut || !amount || tokenIn.equals(tokenOut) || tokenIn.wrapped.equals(tokenOut.wrapped)
? undefined
: {
amount: amount.quotient.toString(),

@ -21,9 +21,9 @@ export function computeRoutes(
const parsedTokenIn = parseToken(quoteResult.route[0][0].tokenIn)
const parsedTokenOut = parseToken(quoteResult.route[0][quoteResult.route[0].length - 1].tokenOut)
if (parsedTokenIn.address !== currencyIn.wrapped.address) return undefined
if (parsedTokenOut.address !== currencyOut.wrapped.address) return undefined
if (parsedTokenIn.wrapped.equals(parsedTokenOut.wrapped)) return undefined
try {
return quoteResult.route.map((route) => {