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
21e0faeb
Unverified
Commit
21e0faeb
authored
Oct 11, 2022
by
Connor McEwen
Committed by
GitHub
Oct 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: actually fetch token object on page (#4875)
* fix: actually fetch token object on page * syntax
parent
4b71a8d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
18 deletions
+10
-18
useCurrency.ts
src/lib/hooks/useCurrency.ts
+7
-3
index.tsx
src/pages/TokenDetails/index.tsx
+3
-15
No files found.
src/lib/hooks/useCurrency.ts
View file @
21e0faeb
...
@@ -29,8 +29,12 @@ function parseStringOrBytes32(str: string | undefined, bytes32: string | undefin
...
@@ -29,8 +29,12 @@ function parseStringOrBytes32(str: string | undefined, bytes32: string | undefin
* Returns null if token is loading or null was passed.
* Returns null if token is loading or null was passed.
* Returns undefined if tokenAddress is invalid or token does not exist.
* Returns undefined if tokenAddress is invalid or token does not exist.
*/
*/
export
function
useTokenFromNetwork
(
tokenAddress
:
string
|
null
|
undefined
):
Token
|
null
|
undefined
{
export
function
useTokenFromNetwork
(
const
{
chainId
}
=
useWeb3React
()
tokenAddress
:
string
|
null
|
undefined
,
chainId
?:
number
):
Token
|
null
|
undefined
{
const
web3ReactChainId
=
useWeb3React
().
chainId
if
(
!
chainId
)
chainId
=
web3ReactChainId
const
supportedChain
=
isSupportedChain
(
chainId
)
const
supportedChain
=
isSupportedChain
(
chainId
)
const
formattedAddress
=
isAddress
(
tokenAddress
)
const
formattedAddress
=
isAddress
(
tokenAddress
)
...
@@ -46,7 +50,7 @@ export function useTokenFromNetwork(tokenAddress: string | null | undefined): To
...
@@ -46,7 +50,7 @@ export function useTokenFromNetwork(tokenAddress: string | null | undefined): To
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
if
(
typeof
tokenAddress
!==
'
string
'
||
!
supportedChain
||
!
formattedAddress
)
return
undefined
if
(
typeof
tokenAddress
!==
'
string
'
||
!
supportedChain
||
!
formattedAddress
)
return
undefined
if
(
decimals
.
loading
||
symbol
.
loading
||
tokenName
.
loading
)
return
null
if
(
decimals
.
loading
||
symbol
.
loading
||
tokenName
.
loading
||
!
chainId
)
return
null
if
(
decimals
.
result
)
{
if
(
decimals
.
result
)
{
return
new
Token
(
return
new
Token
(
chainId
,
chainId
,
...
...
src/pages/TokenDetails/index.tsx
View file @
21e0faeb
import
{
Token
}
from
'
@uniswap/sdk-core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
filterTimeAtom
}
from
'
components/Tokens/state
'
import
{
filterTimeAtom
}
from
'
components/Tokens/state
'
import
{
AboutSection
}
from
'
components/Tokens/TokenDetails/About
'
import
{
AboutSection
}
from
'
components/Tokens/TokenDetails/About
'
...
@@ -19,6 +18,7 @@ import { CHAIN_NAME_TO_CHAIN_ID, validateUrlChainParam } from 'graphql/data/util
...
@@ -19,6 +18,7 @@ import { CHAIN_NAME_TO_CHAIN_ID, validateUrlChainParam } from 'graphql/data/util
import
{
useIsUserAddedTokenOnChain
}
from
'
hooks/Tokens
'
import
{
useIsUserAddedTokenOnChain
}
from
'
hooks/Tokens
'
import
{
useOnGlobalChainSwitch
}
from
'
hooks/useGlobalChainSwitch
'
import
{
useOnGlobalChainSwitch
}
from
'
hooks/useGlobalChainSwitch
'
import
{
useAtomValue
}
from
'
jotai/utils
'
import
{
useAtomValue
}
from
'
jotai/utils
'
import
{
useTokenFromNetwork
}
from
'
lib/hooks/useCurrency
'
import
useCurrencyBalance
,
{
useTokenBalance
}
from
'
lib/hooks/useCurrencyBalance
'
import
useCurrencyBalance
,
{
useTokenBalance
}
from
'
lib/hooks/useCurrencyBalance
'
import
{
useCallback
,
useMemo
,
useState
}
from
'
react
'
import
{
useCallback
,
useMemo
,
useState
}
from
'
react
'
import
{
ArrowLeft
}
from
'
react-feather
'
import
{
ArrowLeft
}
from
'
react-feather
'
...
@@ -76,23 +76,11 @@ export default function TokenDetails() {
...
@@ -76,23 +76,11 @@ export default function TokenDetails() {
const
tokenQueryAddress
=
isNative
?
nativeCurrency
.
wrapped
.
address
:
tokenAddressParam
const
tokenQueryAddress
=
isNative
?
nativeCurrency
.
wrapped
.
address
:
tokenAddressParam
const
[
tokenQueryData
,
prices
]
=
useTokenQuery
(
tokenQueryAddress
??
''
,
currentChainName
,
timePeriod
)
const
[
tokenQueryData
,
prices
]
=
useTokenQuery
(
tokenQueryAddress
??
''
,
currentChainName
,
timePeriod
)
const
pageToken
=
useMemo
(
const
pageToken
=
useTokenFromNetwork
(
tokenAddressParam
,
CHAIN_NAME_TO_CHAIN_ID
[
currentChainName
])
()
=>
tokenQueryData
&&
!
isNative
?
new
Token
(
CHAIN_NAME_TO_CHAIN_ID
[
currentChainName
],
tokenAddressParam
??
''
,
18
,
tokenQueryData
?.
symbol
??
''
,
tokenQueryData
?.
name
??
''
)
:
undefined
,
[
currentChainName
,
isNative
,
tokenAddressParam
,
tokenQueryData
]
)
const
nativeCurrencyBalance
=
useCurrencyBalance
(
account
,
nativeCurrency
)
const
nativeCurrencyBalance
=
useCurrencyBalance
(
account
,
nativeCurrency
)
const
tokenBalance
=
useTokenBalance
(
account
,
isNative
?
nativeCurrency
.
wrapped
:
pageToken
)
const
tokenBalance
=
useTokenBalance
(
account
,
isNative
?
nativeCurrency
.
wrapped
:
pageToken
??
undefined
)
const
tokenWarning
=
tokenAddressParam
?
checkWarning
(
tokenAddressParam
)
:
null
const
tokenWarning
=
tokenAddressParam
?
checkWarning
(
tokenAddressParam
)
:
null
const
isBlockedToken
=
tokenWarning
?.
canProceed
===
false
const
isBlockedToken
=
tokenWarning
?.
canProceed
===
false
...
...
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