improve the better trade link logic

This commit is contained in:
Moody Salem 2021-04-28 20:02:55 -05:00
parent b25287923c
commit c3909bc1d0
No known key found for this signature in database
GPG Key ID: 8CB5CD10385138DB
3 changed files with 15 additions and 8 deletions

@ -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 (
<VersionLinkContainer>
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 '}
<StyledInternalLink to={linkDestination}>
<b>Uniswap {version.toUpperCase()} </b>
</StyledInternalLink>

@ -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,

@ -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) ? (
<BetterTradeLink version={Version.v2} />
{[V3TradeState.VALID, V3TradeState.SYNCING, V3TradeState.NO_ROUTE_FOUND].includes(v3TradeState) ? (
toggledVersion === Version.v3 && isTradeBetter(v3Trade, v2Trade) ? (
<BetterTradeLink version={Version.v2} otherTradeNonexistent={!v3Trade} />
) : toggledVersion === Version.v2 && isTradeBetter(v2Trade, v3Trade) ? (
<BetterTradeLink version={Version.v3} />
<BetterTradeLink version={Version.v3} otherTradeNonexistent={!v2Trade} />
) : null
) : null}
<BottomGrouping>
{swapIsUnsupported ? (