Commit cdae20f2 authored by Noah Zinsmeister's avatar Noah Zinsmeister

fix weth/eth bug

closes #47
parent eedba979
...@@ -56,7 +56,7 @@ export default function CommonBases({ ...@@ -56,7 +56,7 @@ export default function CommonBases({
ETH ETH
</Text> </Text>
</BaseWrapper> </BaseWrapper>
{(chainId ? SUGGESTED_BASES[chainId] : []).map((token: Token) => { {(typeof chainId === 'number' ? SUGGESTED_BASES[chainId] ?? [] : []).map((token: Token) => {
const selected = selectedCurrency instanceof Token && selectedCurrency.address === token.address const selected = selectedCurrency instanceof Token && selectedCurrency.address === token.address
return ( return (
<BaseWrapper onClick={() => !selected && onSelect(token)} disable={selected} key={token.address}> <BaseWrapper onClick={() => !selected && onSelect(token)} disable={selected} key={token.address}>
......
...@@ -106,9 +106,8 @@ export const CUSTOM_BASES: { [chainId in ChainId]?: { [tokenAddress: string]: To ...@@ -106,9 +106,8 @@ export const CUSTOM_BASES: { [chainId in ChainId]?: { [tokenAddress: string]: To
} }
// used for display in the default list when adding liquidity // used for display in the default list when adding liquidity
export const SUGGESTED_BASES: ChainTokenList = { export const SUGGESTED_BASES: Partial<ChainTokenList> = {
...WETH_ONLY, [ChainId.MAINNET]: [DAI, USDC, USDT, WBTC],
[ChainId.MAINNET]: [...WETH_ONLY[ChainId.MAINNET], DAI, USDC, USDT, WBTC],
} }
// used to construct the list of all pairs we consider by default in the frontend // used to construct the list of all pairs we consider by default in the frontend
......
import { TransactionResponse } from '@ethersproject/providers'
import { Currency, TokenAmount, ETHER } from '@uniswap/sdk-core'
import React, { useCallback, useContext, useMemo, useState } from 'react' import React, { useCallback, useContext, useMemo, useState } from 'react'
import { TransactionResponse } from '@ethersproject/providers'
import { Currency, TokenAmount, ETHER, currencyEquals } from '@uniswap/sdk-core'
import { WETH9 } from '@uniswap/sdk-core' import { WETH9 } from '@uniswap/sdk-core'
import { Link2, AlertTriangle } from 'react-feather' import { Link2, AlertTriangle } from 'react-feather'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
...@@ -80,11 +80,15 @@ export default function AddLiquidity({ ...@@ -80,11 +80,15 @@ export default function AddLiquidity({
// keep track for UI display purposes of user selected base currency // keep track for UI display purposes of user selected base currency
const [baseCurrency, setBaseCurrency] = useState(currencyA) const [baseCurrency, setBaseCurrency] = useState(currencyA)
const quoteCurrency = useMemo(() => (baseCurrency === currencyA ? currencyB : currencyA), [ const quoteCurrency = useMemo(
baseCurrency, () =>
currencyA, currencyA && currencyB && baseCurrency
currencyB, ? currencyEquals(baseCurrency, currencyA)
]) ? currencyB
: currencyA
: undefined,
[currencyA, currencyB, baseCurrency]
)
// mint state // mint state
const { independentField, typedValue, startPriceTypedValue } = useMintState() const { independentField, typedValue, startPriceTypedValue } = useMintState()
...@@ -247,38 +251,53 @@ export default function AddLiquidity({ ...@@ -247,38 +251,53 @@ export default function AddLiquidity({
!depositBDisabled ? currencies[Field.CURRENCY_B]?.symbol : '' !depositBDisabled ? currencies[Field.CURRENCY_B]?.symbol : ''
}` }`
const handleCurrencySelect = useCallback(
(currencyNew: Currency, currencyIdOther?: string): (string | undefined)[] => {
const currencyIdNew = currencyId(currencyNew)
if (currencyIdNew === currencyIdOther) {
// not ideal, but for now clobber the other if the currency ids are equal
return [currencyIdNew, undefined]
} else {
// prevent weth + eth
const isETHOrWETHNew =
currencyIdNew === 'ETH' || (chainId !== undefined && currencyIdNew === WETH9[chainId]?.address)
const isETHOrWETHOther =
currencyIdOther !== undefined &&
(currencyIdOther === 'ETH' || (chainId !== undefined && currencyIdOther === WETH9[chainId]?.address))
if (isETHOrWETHNew && isETHOrWETHOther) {
return [currencyIdNew, undefined]
} else {
return [currencyIdNew, currencyIdOther]
}
}
},
[chainId]
)
const handleCurrencyASelect = useCallback( const handleCurrencyASelect = useCallback(
(currencyA: Currency) => { (currencyANew: Currency) => {
const newCurrencyIdA = currencyId(currencyA) const [idA, idB] = handleCurrencySelect(currencyANew, currencyIdB)
//switch order if same selected if (idB === undefined) {
if (newCurrencyIdA === currencyIdB) { history.push(`/add/${idA}`)
history.push(`/add/${currencyIdB}/${currencyIdA}`)
} else if (chainId && newCurrencyIdA === WETH9[chainId]?.address && currencyIdB === 'ETH') {
// prevent eth / weth
history.push(`/add/${newCurrencyIdA}`)
} else { } else {
history.push(`/add/${newCurrencyIdA}/${currencyIdB ?? 'ETH'}`) history.push(`/add/${idA}/${idB}`)
} }
}, },
[currencyIdB, chainId, history, currencyIdA] [handleCurrencySelect, currencyIdB, history]
) )
const handleCurrencyBSelect = useCallback( const handleCurrencyBSelect = useCallback(
(currencyB: Currency) => { (currencyBNew: Currency) => {
const newCurrencyIdB = currencyId(currencyB) const [idB, idA] = handleCurrencySelect(currencyBNew, currencyIdA)
if (currencyIdA === newCurrencyIdB) { if (idA === undefined) {
if (currencyIdB) { history.push(`/add/${idB}`)
history.push(`/add/${currencyIdB}/${newCurrencyIdB}`)
} else {
history.push(`/add/${newCurrencyIdB}`)
}
} else if (chainId && newCurrencyIdB === WETH9[chainId]?.address && currencyIdA === 'ETH') {
// prevent eth / weth
history.push(`/add/${newCurrencyIdB}`)
} else { } else {
history.push(`/add/${currencyIdA ?? 'ETH'}/${newCurrencyIdB}`) history.push(`/add/${idA}/${idB}`)
} }
}, },
[currencyIdA, chainId, currencyIdB, history] [handleCurrencySelect, currencyIdA, history]
) )
const handleFeePoolSelect = useCallback( const handleFeePoolSelect = useCallback(
......
import { useActiveWeb3React } from 'hooks'
import React from 'react' import React from 'react'
import { Redirect, RouteComponentProps } from 'react-router-dom' import { Redirect, RouteComponentProps } from 'react-router-dom'
import AddLiquidity from './index' import AddLiquidity from './index'
import { WETH9 } from '@uniswap/sdk-core'
export function RedirectDuplicateTokenIds( export function RedirectDuplicateTokenIds(
props: RouteComponentProps<{ currencyIdA: string; currencyIdB: string; feeAmount?: string }> props: RouteComponentProps<{ currencyIdA: string; currencyIdB: string; feeAmount?: string }>
...@@ -11,7 +13,17 @@ export function RedirectDuplicateTokenIds( ...@@ -11,7 +13,17 @@ export function RedirectDuplicateTokenIds(
}, },
} = props } = props
if (currencyIdA && currencyIdB && currencyIdA.toLowerCase() === currencyIdB.toLowerCase()) { const { chainId } = useActiveWeb3React()
// prevent weth + eth
const isETHOrWETHA = currencyIdA === 'ETH' || (chainId !== undefined && currencyIdA === WETH9[chainId]?.address)
const isETHOrWETHB = currencyIdB === 'ETH' || (chainId !== undefined && currencyIdB === WETH9[chainId]?.address)
if (
currencyIdA &&
currencyIdB &&
(currencyIdA.toLowerCase() === currencyIdB.toLowerCase() || (isETHOrWETHA && isETHOrWETHB))
) {
return <Redirect to={`/add/${currencyIdA}`} /> return <Redirect to={`/add/${currencyIdA}`} />
} }
return <AddLiquidity {...props} /> return <AddLiquidity {...props} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment