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
19b4ee46
Unverified
Commit
19b4ee46
authored
Sep 30, 2022
by
Zach Pomerantz
Committed by
GitHub
Sep 30, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: memoize tokens in TokenDetails (#4777)
parent
2aea96c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
index.tsx
src/components/Widget/index.tsx
+1
-2
index.tsx
src/pages/TokenDetails/index.tsx
+21
-11
No files found.
src/components/Widget/index.tsx
View file @
19b4ee46
import
{
Currency
,
OnReviewSwapClick
,
SwapWidget
}
from
'
@uniswap/widgets
'
import
{
Currency
,
OnReviewSwapClick
,
SwapWidget
}
from
'
@uniswap/widgets
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
RPC_PROVIDERS
}
from
'
constants/providers
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
import
{
useIsDarkMode
}
from
'
state/user/hooks
'
import
{
useIsDarkMode
}
from
'
state/user/hooks
'
...
@@ -34,7 +33,7 @@ export default function Widget({ defaultToken, onReviewSwapClick }: WidgetProps)
...
@@ -34,7 +33,7 @@ export default function Widget({ defaultToken, onReviewSwapClick }: WidgetProps)
<
SwapWidget
<
SwapWidget
disableBranding
disableBranding
hideConnectionUI
hideConnectionUI
jsonRpcUrlMap=
{
RPC_PROVIDERS
}
// jsonRpcUrlMap is excluded - network providers are always passed directly
routerUrl=
{
WIDGET_ROUTER_URL
}
routerUrl=
{
WIDGET_ROUTER_URL
}
width=
{
WIDGET_WIDTH
}
width=
{
WIDGET_WIDTH
}
locale=
{
locale
}
locale=
{
locale
}
...
...
src/pages/TokenDetails/index.tsx
View file @
19b4ee46
import
{
Token
}
from
'
@uniswap/sdk-core
'
import
{
NativeCurrency
,
Token
}
from
'
@uniswap/sdk-core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
formatToDecimal
}
from
'
analytics/utils
'
import
{
formatToDecimal
}
from
'
analytics/utils
'
import
{
import
{
...
@@ -21,7 +21,7 @@ import TokenSafetyModal from 'components/TokenSafety/TokenSafetyModal'
...
@@ -21,7 +21,7 @@ import TokenSafetyModal from 'components/TokenSafety/TokenSafetyModal'
import
Widget
,
{
WIDGET_WIDTH
}
from
'
components/Widget
'
import
Widget
,
{
WIDGET_WIDTH
}
from
'
components/Widget
'
import
{
getChainInfo
}
from
'
constants/chainInfo
'
import
{
getChainInfo
}
from
'
constants/chainInfo
'
import
{
L1_CHAIN_IDS
,
L2_CHAIN_IDS
,
SupportedChainId
,
TESTNET_CHAIN_IDS
}
from
'
constants/chains
'
import
{
L1_CHAIN_IDS
,
L2_CHAIN_IDS
,
SupportedChainId
,
TESTNET_CHAIN_IDS
}
from
'
constants/chains
'
import
{
isCelo
,
nativeOnChain
,
WRAPPED_NATIVE_CURRENCY
}
from
'
constants/tokens
'
import
{
isCelo
,
nativeOnChain
}
from
'
constants/tokens
'
import
{
checkWarning
}
from
'
constants/tokenSafety
'
import
{
checkWarning
}
from
'
constants/tokenSafety
'
import
{
Chain
}
from
'
graphql/data/__generated__/TokenQuery.graphql
'
import
{
Chain
}
from
'
graphql/data/__generated__/TokenQuery.graphql
'
import
{
useTokenQuery
}
from
'
graphql/data/Token
'
import
{
useTokenQuery
}
from
'
graphql/data/Token
'
...
@@ -99,10 +99,10 @@ export default function TokenDetails() {
...
@@ -99,10 +99,10 @@ export default function TokenDetails() {
const
{
tokenAddress
:
tokenAddressParam
,
chainName
}
=
useParams
<
{
tokenAddress
?:
string
;
chainName
?:
string
}
>
()
const
{
tokenAddress
:
tokenAddressParam
,
chainName
}
=
useParams
<
{
tokenAddress
?:
string
;
chainName
?:
string
}
>
()
const
chainId
=
CHAIN_NAME_TO_CHAIN_ID
[
validateUrlChainParam
(
chainName
)]
const
chainId
=
CHAIN_NAME_TO_CHAIN_ID
[
validateUrlChainParam
(
chainName
)]
let
tokenAddress
=
tokenAddressParam
let
tokenAddress
=
tokenAddressParam
let
nativeCurrency
let
nativeCurrency
:
NativeCurrency
|
Token
|
undefined
if
(
tokenAddressParam
===
'
NATIVE
'
)
{
if
(
tokenAddressParam
===
'
NATIVE
'
)
{
nativeCurrency
=
nativeOnChain
(
chainId
)
nativeCurrency
=
nativeOnChain
(
chainId
)
tokenAddress
=
WRAPPED_NATIVE_CURRENCY
[
chainId
]?.
address
?.
toLowerCase
()
tokenAddress
=
nativeCurrency
.
wrapped
.
address
}
}
const
tokenWarning
=
tokenAddress
?
checkWarning
(
tokenAddress
)
:
null
const
tokenWarning
=
tokenAddress
?
checkWarning
(
tokenAddress
)
:
null
...
@@ -152,7 +152,10 @@ export default function TokenDetails() {
...
@@ -152,7 +152,10 @@ export default function TokenDetails() {
const
{
chainId
:
connectedChainId
,
account
}
=
useWeb3React
()
const
{
chainId
:
connectedChainId
,
account
}
=
useWeb3React
()
// TODO: consider updating useTokenBalance to work with just address/chain to avoid using Token data structure here
// TODO: consider updating useTokenBalance to work with just address/chain to avoid using Token data structure here
const
balanceValue
=
useTokenBalance
(
account
,
new
Token
(
chainId
,
tokenAddress
??
''
,
18
))
const
balanceValue
=
useTokenBalance
(
account
,
useMemo
(()
=>
new
Token
(
chainId
,
tokenAddress
??
''
,
18
),
[
chainId
,
tokenAddress
])
)
const
balance
=
balanceValue
?
formatToDecimal
(
balanceValue
,
Math
.
min
(
balanceValue
.
currency
.
decimals
,
6
))
:
undefined
const
balance
=
balanceValue
?
formatToDecimal
(
balanceValue
,
Math
.
min
(
balanceValue
.
currency
.
decimals
,
6
))
:
undefined
const
balanceUsdValue
=
useStablecoinValue
(
balanceValue
)?.
toFixed
(
2
)
const
balanceUsdValue
=
useStablecoinValue
(
balanceValue
)?.
toFixed
(
2
)
const
balanceUsd
=
balanceUsdValue
?
parseFloat
(
balanceUsdValue
)
:
undefined
const
balanceUsd
=
balanceUsdValue
?
parseFloat
(
balanceUsdValue
)
:
undefined
...
@@ -188,11 +191,18 @@ export default function TokenDetails() {
...
@@ -188,11 +191,18 @@ export default function TokenDetails() {
})
})
:
null
:
null
const
defaultWidgetToken
=
const
widgetToken
=
useMemo
(()
=>
{
nativeCurrency
??
const
currentChainId
=
CHAIN_NAME_TO_CHAIN_ID
[
currentChainName
]
(
token
?.
address
&&
token
.
symbol
&&
token
.
name
// The widget is not yet configured to use Celo.
?
new
Token
(
CHAIN_NAME_TO_CHAIN_ID
[
currentChainName
],
token
.
address
,
18
,
token
.
symbol
,
token
.
name
)
if
(
isCelo
(
chainId
)
||
isCelo
(
currentChainId
))
return
undefined
:
undefined
)
return
(
nativeCurrency
??
(
token
?.
address
&&
token
.
symbol
&&
token
.
name
?
new
Token
(
currentChainId
,
token
.
address
,
18
,
token
.
symbol
,
token
.
name
)
:
undefined
)
)
},
[
chainId
,
currentChainName
,
nativeCurrency
,
token
?.
address
,
token
?.
name
,
token
?.
symbol
])
return
(
return
(
<
TokenDetailsLayout
>
<
TokenDetailsLayout
>
...
@@ -219,7 +229,7 @@ export default function TokenDetails() {
...
@@ -219,7 +229,7 @@ export default function TokenDetails() {
<
AddressSection
address=
{
token
.
address
??
''
}
/>
<
AddressSection
address=
{
token
.
address
??
''
}
/>
</
LeftPanel
>
</
LeftPanel
>
<
RightPanel
>
<
RightPanel
>
<
Widget
defaultToken=
{
!
isCelo
(
chainId
)
?
defaultWidgetToken
:
undefined
}
onReviewSwapClick=
{
onReviewSwap
}
/>
<
Widget
defaultToken=
{
widgetToken
}
onReviewSwapClick=
{
onReviewSwap
}
/>
{
tokenWarning
&&
<
TokenSafetyMessage
tokenAddress=
{
token
.
address
??
''
}
warning=
{
tokenWarning
}
/>
}
{
tokenWarning
&&
<
TokenSafetyMessage
tokenAddress=
{
token
.
address
??
''
}
warning=
{
tokenWarning
}
/>
}
<
BalanceSummary
address=
{
token
.
address
??
''
}
balance=
{
balance
}
balanceUsd=
{
balanceUsd
}
/>
<
BalanceSummary
address=
{
token
.
address
??
''
}
balance=
{
balance
}
balanceUsd=
{
balanceUsd
}
/>
</
RightPanel
>
</
RightPanel
>
...
...
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