ignore v3 state when only v2 only (#2383)

This commit is contained in:
Justin Domingue 2021-09-17 16:29:08 -04:00 committed by GitHub
parent 9bc00ccaf6
commit 648e4e02c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -181,7 +181,8 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): {
const isV2TradeBetter = useMemo(() => { const isV2TradeBetter = useMemo(() => {
try { try {
// avoids comparing trades when V3Trade is not in a ready state. // avoids comparing trades when V3Trade is not in a ready state.
return [V3TradeState.VALID, V3TradeState.SYNCING, V3TradeState.NO_ROUTE_FOUND].includes(v3Trade.state) return toggledVersion === Version.v2 ||
[V3TradeState.VALID, V3TradeState.SYNCING, V3TradeState.NO_ROUTE_FOUND].includes(v3Trade.state)
? isTradeBetter(v3Trade.trade, v2Trade, TWO_PERCENT) ? isTradeBetter(v3Trade.trade, v2Trade, TWO_PERCENT)
: undefined : undefined
} catch (e) { } catch (e) {
@ -189,7 +190,7 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): {
// inputs/ouputs than v2 // inputs/ouputs than v2
return undefined return undefined
} }
}, [v2Trade, v3Trade]) }, [toggledVersion, v2Trade, v3Trade.state, v3Trade.trade])
const bestTrade = isV2TradeBetter == undefined ? undefined : isV2TradeBetter ? v2Trade : v3Trade.trade const bestTrade = isV2TradeBetter == undefined ? undefined : isV2TradeBetter ? v2Trade : v3Trade.trade