Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
cdae20f2
Unverified
Commit
cdae20f2
authored
May 04, 2021
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix weth/eth bug
closes #47
parent
eedba979
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
35 deletions
+65
-35
CommonBases.tsx
src/components/SearchModal/CommonBases.tsx
+1
-1
index.ts
src/constants/index.ts
+2
-3
index.tsx
src/pages/AddLiquidity/index.tsx
+49
-30
redirects.tsx
src/pages/AddLiquidity/redirects.tsx
+13
-1
No files found.
src/components/SearchModal/CommonBases.tsx
View file @
cdae20f2
...
@@ -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
}
>
...
...
src/constants/index.ts
View file @
cdae20f2
...
@@ -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
...
...
src/pages/AddLiquidity/index.tsx
View file @
cdae20f2
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 handleCurrencyASelect = useCallback(
const handleCurrencySelect = useCallback(
(currencyA: Currency) => {
(currencyNew: Currency, currencyIdOther?: string): (string | undefined)[] => {
const newCurrencyIdA = currencyId(currencyA)
const currencyIdNew = currencyId(currencyNew)
//switch order if same selected
if (newCurrencyIdA === currencyIdB) {
if (currencyIdNew === currencyIdOther) {
history.push(`
/
add
/
$
{
currencyIdB
}
/${currencyIdA}`
)
// not ideal, but for now clobber the other if the currency ids are equal
}
else
if
(
chainId
&&
newCurrencyIdA
===
WETH9
[
chainId
]?.
address
&&
currencyIdB
===
'
ETH
'
)
{
return [currencyIdNew, undefined]
// prevent eth / weth
} else {
history
.
push
(
`/add/
${
newCurrencyIdA
}
`
)
// 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 {
} else {
history
.
push
(
`/add/
${
newCurrencyIdA
}
/
${
currencyIdB
??
'
ETH
'
}
`)
return [currencyIdNew, currencyIdOther]
}
}
}
},
},
[c
urrencyIdB, chainId, history, currencyIdA
]
[c
hainId
]
)
)
const handleCurrencyBSelect = useCallback(
(currencyB: Currency) => {
const handleCurrencyASelect = useCallback(
const newCurrencyIdB = currencyId(currencyB)
(currencyANew: Currency) => {
if (currencyIdA === newCurrencyIdB) {
const [idA, idB] = handleCurrencySelect(currencyANew, currencyIdB)
if (currencyIdB
) {
if (idB === undefined
) {
history.push(`
/
add
/
$
{
currencyIdB
}
/${newCurrencyIdB
}`
)
history.push(`
/
add
/
$
{
idA
}
`)
} else {
} else {
history
.
push
(
`/add/
${
newCurrencyI
dB
}
`
)
history.push(`
/
add
/
$
{
idA
}
/${i
dB}`
)
}
}
}
else
if
(
chainId
&&
newCurrencyIdB
===
WETH9
[
chainId
]?.
address
&&
currencyIdA
===
'
ETH
'
)
{
},
// prevent eth / weth
[
handleCurrencySelect
,
currencyIdB
,
history
]
history
.
push
(
`/add/
${
newCurrencyIdB
}
`
)
)
const
handleCurrencyBSelect
=
useCallback
(
(
currencyBNew
:
Currency
)
=>
{
const
[
idB
,
idA
]
=
handleCurrencySelect
(
currencyBNew
,
currencyIdA
)
if
(
idA
===
undefined
)
{
history
.
push
(
`/add/
${
idB
}
`
)
}
else
{
}
else
{
history
.
push
(
`/add/
${
currencyIdA
??
'
ETH
'
}
/${newCurrencyI
dB}`
)
history
.
push
(
`/add/
${
idA
}
/
${
i
dB
}
`
)
}
}
},
},
[
currencyIdA
,
chainId
,
currencyIdB
,
history
]
[
handleCurrencySelect
,
currencyIdA
,
history
]
)
)
const
handleFeePoolSelect
=
useCallback
(
const
handleFeePoolSelect
=
useCallback
(
...
...
src/pages/AddLiquidity/redirects.tsx
View file @
cdae20f2
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
}
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment