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
7d20dd97
Unverified
Commit
7d20dd97
authored
May 20, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a crash related to WETH being loaded from add liquidity
parent
2b4f511b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
15 deletions
+28
-15
Tokens.ts
src/hooks/Tokens.ts
+28
-15
No files found.
src/hooks/Tokens.ts
View file @
7d20dd97
import
{
ChainId
,
Token
}
from
'
@uniswap/sdk
'
import
{
ChainId
,
Token
,
WETH
}
from
'
@uniswap/sdk
'
import
{
useEffect
,
useMemo
}
from
'
react
'
import
{
ALL_TOKENS
}
from
'
../constants/tokens
'
import
{
useAddUserToken
,
useFetchTokenByAddress
,
useUserAddedTokens
}
from
'
../state/user/hooks
'
import
{
isAddress
}
from
'
../utils
'
import
{
useActiveWeb3React
}
from
'
./index
'
...
...
@@ -11,8 +12,7 @@ export function useAllTokens(): { [address: string]: Token } {
return
useMemo
(()
=>
{
if
(
!
chainId
)
return
{}
return
(
userAddedTokens
const
tokens
=
userAddedTokens
// reduce into all ALL_TOKENS filtered by the current chain
.
reduce
<
{
[
address
:
string
]:
Token
}
>
(
(
tokenMap
,
token
)
=>
{
...
...
@@ -23,7 +23,15 @@ export function useAllTokens(): { [address: string]: Token } {
// want to make a copy in every iteration
{
...
ALL_TOKENS
[
chainId
as
ChainId
]
}
)
)
const
weth
=
WETH
[
chainId
as
ChainId
]
if
(
weth
)
{
// we have to replace it as a workaround because if it is automatically
// fetched by address it will cause an invariant when used in constructing
// pairs since we replace the name and symbol with 'ETH' and 'Ether'
tokens
[
weth
.
address
]
=
WETH
[
chainId
as
ChainId
]
}
return
tokens
},
[
userAddedTokens
,
chainId
])
}
...
...
@@ -39,8 +47,13 @@ export function useTokenByAddressAndAutomaticallyAdd(tokenAddress?: string): Tok
const
fetchTokenByAddress
=
useFetchTokenByAddress
()
const
addToken
=
useAddUserToken
()
const
allTokens
=
useAllTokens
()
const
{
chainId
}
=
useActiveWeb3React
()
useEffect
(()
=>
{
if
(
!
chainId
)
return
const
weth
=
WETH
[
chainId
as
ChainId
]
if
(
weth
&&
weth
.
address
===
isAddress
(
tokenAddress
))
return
if
(
tokenAddress
&&
!
allTokens
?.[
tokenAddress
])
{
fetchTokenByAddress
(
tokenAddress
).
then
(
token
=>
{
if
(
token
!==
null
)
{
...
...
@@ -48,7 +61,7 @@ export function useTokenByAddressAndAutomaticallyAdd(tokenAddress?: string): Tok
}
})
}
},
[
tokenAddress
,
allTokens
,
fetchTokenByAddress
,
addToken
])
},
[
tokenAddress
,
allTokens
,
fetchTokenByAddress
,
addToken
,
chainId
])
return
tokenAddress
?
allTokens
?.[
tokenAddress
]
:
undefined
}
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