From c3909bc1d08789162e5b32703c508e59e6a13709 Mon Sep 17 00:00:00 2001 From: Moody Salem Date: Wed, 28 Apr 2021 20:02:55 -0500 Subject: [PATCH] improve the better trade link logic --- src/components/swap/BetterTradeLink.tsx | 10 ++++++++-- src/hooks/useBestV3Trade.ts | 2 +- src/pages/Swap/index.tsx | 11 ++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/swap/BetterTradeLink.tsx b/src/components/swap/BetterTradeLink.tsx index 06265f94e3..e3b6acff79 100644 --- a/src/components/swap/BetterTradeLink.tsx +++ b/src/components/swap/BetterTradeLink.tsx @@ -24,7 +24,13 @@ function VersionLinkContainer({ children }: { children: React.ReactNode }) { ) } -export default function BetterTradeLink({ version }: { version: Version }) { +export default function BetterTradeLink({ + version, + otherTradeNonexistent = false, +}: { + version: Version + otherTradeNonexistent: boolean +}) { const location = useLocation() const search = useParsedQueryString() @@ -40,7 +46,7 @@ export default function BetterTradeLink({ version }: { version: Version }) { return ( - There is a better price for this trade on{' '} + {otherTradeNonexistent ? 'This trade can be executed on ' : 'There is a better price for this trade on '} Uniswap {version.toUpperCase()} ↗ diff --git a/src/hooks/useBestV3Trade.ts b/src/hooks/useBestV3Trade.ts index 05d6ce7a93..b5f9d733ab 100644 --- a/src/hooks/useBestV3Trade.ts +++ b/src/hooks/useBestV3Trade.ts @@ -36,7 +36,7 @@ export function useBestV3TradeExactIn( const quotesResults = useSingleContractMultipleData(quoter, 'quoteExactInput', quoteExactInInputs) return useMemo(() => { - if (!amountIn || !currencyOut || quotesResults.some(({ valid }) => !valid)) { + if (!amountIn || !currencyOut) { return { state: V3TradeState.INVALID, trade: null, diff --git a/src/pages/Swap/index.tsx b/src/pages/Swap/index.tsx index 52dc5bad6f..85a2918056 100644 --- a/src/pages/Swap/index.tsx +++ b/src/pages/Swap/index.tsx @@ -393,11 +393,12 @@ export default function Swap({ history }: RouteComponentProps) { setShowInverted={setShowInverted} /> ) : null} - {![V3TradeState.VALID, V3TradeState.SYNCING].includes(v3TradeState) ? null : toggledVersion === - Version.v3 && isTradeBetter(v3Trade, v2Trade) ? ( - - ) : toggledVersion === Version.v2 && isTradeBetter(v2Trade, v3Trade) ? ( - + {[V3TradeState.VALID, V3TradeState.SYNCING, V3TradeState.NO_ROUTE_FOUND].includes(v3TradeState) ? ( + toggledVersion === Version.v3 && isTradeBetter(v3Trade, v2Trade) ? ( + + ) : toggledVersion === Version.v2 && isTradeBetter(v2Trade, v3Trade) ? ( + + ) : null ) : null} {swapIsUnsupported ? (