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
e97e1172
Unverified
Commit
e97e1172
authored
Sep 23, 2022
by
lynn
Committed by
GitHub
Sep 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: show real balance in footer summary instead of dummy data (#4707)
real balances to footer
parent
b63e9538
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
31 deletions
+42
-31
BalanceSummary.tsx
src/components/Tokens/TokenDetails/BalanceSummary.tsx
+9
-11
FooterBalanceSummary.tsx
src/components/Tokens/TokenDetails/FooterBalanceSummary.tsx
+21
-16
index.tsx
src/pages/TokenDetails/index.tsx
+12
-4
No files found.
src/components/Tokens/TokenDetails/BalanceSummary.tsx
View file @
e97e1172
import
{
Trans
}
from
'
@lingui/macro
'
import
{
Trans
}
from
'
@lingui/macro
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
formatToDecimal
}
from
'
analytics/utils
'
import
{
useToken
}
from
'
hooks/Tokens
'
import
{
useToken
}
from
'
hooks/Tokens
'
import
{
useNetworkTokenBalances
}
from
'
hooks/useNetworkTokenBalances
'
import
{
useNetworkTokenBalances
}
from
'
hooks/useNetworkTokenBalances
'
import
{
useStablecoinValue
}
from
'
hooks/useStablecoinPrice
'
import
{
useTokenBalance
}
from
'
lib/hooks/useCurrencyBalance
'
import
{
AlertTriangle
}
from
'
react-feather
'
import
{
AlertTriangle
}
from
'
react-feather
'
import
styled
from
'
styled-components/macro
'
import
styled
from
'
styled-components/macro
'
...
@@ -49,16 +45,18 @@ const TotalBalanceItem = styled.div`
...
@@ -49,16 +45,18 @@ const TotalBalanceItem = styled.div`
display: flex;
display: flex;
`
`
export
default
function
BalanceSummary
({
address
}:
{
address
:
string
})
{
export
default
function
BalanceSummary
({
address
,
balanceNumber
,
balanceUsdNumber
,
}:
{
address
:
string
balanceNumber
?:
number
balanceUsdNumber
?:
number
})
{
const
token
=
useToken
(
address
)
const
token
=
useToken
(
address
)
const
{
loading
,
error
}
=
useNetworkTokenBalances
({
address
})
const
{
loading
,
error
}
=
useNetworkTokenBalances
({
address
})
const
{
account
}
=
useWeb3React
()
const
balance
=
useTokenBalance
(
account
,
token
??
undefined
)
const
balanceNumber
=
balance
?
formatToDecimal
(
balance
,
Math
.
min
(
balance
.
currency
.
decimals
,
6
))
:
undefined
const
balanceUsd
=
useStablecoinValue
(
balance
)?.
toFixed
(
2
)
const
balanceUsdNumber
=
balanceUsd
?
parseFloat
(
balanceUsd
)
:
undefined
if
(
loading
||
(
!
error
&&
!
balanceNumber
&&
!
balanceUsdNumber
))
return
null
if
(
loading
||
(
!
error
&&
!
balanceNumber
&&
!
balanceUsdNumber
))
return
null
return
(
return
(
<
BalancesCard
>
<
BalancesCard
>
...
...
src/components/Tokens/TokenDetails/FooterBalanceSummary.tsx
View file @
e97e1172
...
@@ -132,11 +132,13 @@ const ErrorText = styled.span`
...
@@ -132,11 +132,13 @@ const ErrorText = styled.span`
export
default
function
FooterBalanceSummary
({
export
default
function
FooterBalanceSummary
({
address
,
address
,
networkBalances
,
networkBalances
,
totalBalance
,
balanceNumber
,
balanceUsdNumber
,
}:
{
}:
{
address
:
string
address
:
string
networkBalances
:
(
JSX
.
Element
|
null
)[]
|
null
networkBalances
:
(
JSX
.
Element
|
null
)[]
|
null
totalBalance
:
number
balanceNumber
?:
number
balanceUsdNumber
?:
number
})
{
})
{
const
tokenSymbol
=
useToken
(
address
)?.
symbol
const
tokenSymbol
=
useToken
(
address
)?.
symbol
const
[
showMultipleBalances
,
setShowMultipleBalances
]
=
useState
(
false
)
const
[
showMultipleBalances
,
setShowMultipleBalances
]
=
useState
(
false
)
...
@@ -159,20 +161,23 @@ export default function FooterBalanceSummary({
...
@@ -159,20 +161,23 @@ export default function FooterBalanceSummary({
</
ErrorText
>
</
ErrorText
>
</
ErrorState
>
</
ErrorState
>
)
:
(
)
:
(
<
BalanceInfo
>
!!
balanceNumber
&&
{
multipleBalances
?
'
Balance on all networks
'
:
`Your balance on ${networkNameIfOneBalance}`
}
!!
balanceUsdNumber
&&
(
<
BalanceTotal
>
<
BalanceInfo
>
<
BalanceValue
>
{
multipleBalances
?
'
Balance on all networks
'
:
`Your balance on ${networkNameIfOneBalance}`
}
{
totalBalance
}
{
tokenSymbol
}
<
BalanceTotal
>
</
BalanceValue
>
<
BalanceValue
>
<
FiatValue
>
($107, 610.04)
</
FiatValue
>
{
balanceNumber
}
{
tokenSymbol
}
</
BalanceTotal
>
</
BalanceValue
>
{
multipleBalances
&&
(
<
FiatValue
>
{
`$${balanceUsdNumber}`
}
</
FiatValue
>
<
ViewAll
onClick=
{
()
=>
setShowMultipleBalances
(
!
showMultipleBalances
)
}
>
</
BalanceTotal
>
<
Trans
>
{
showMultipleBalances
?
'
Hide
'
:
'
View
'
}
all balances
</
Trans
>
{
multipleBalances
&&
(
</
ViewAll
>
<
ViewAll
onClick=
{
()
=>
setShowMultipleBalances
(
!
showMultipleBalances
)
}
>
)
}
<
Trans
>
{
showMultipleBalances
?
'
Hide
'
:
'
View
'
}
all balances
</
Trans
>
</
BalanceInfo
>
</
ViewAll
>
)
}
</
BalanceInfo
>
)
)
}
)
}
<
Link
to=
{
`/swap?outputCurrency=${address}`
}
>
<
Link
to=
{
`/swap?outputCurrency=${address}`
}
>
<
SwapButton
>
<
SwapButton
>
...
...
src/pages/TokenDetails/index.tsx
View file @
e97e1172
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
formatToDecimal
}
from
'
analytics/utils
'
import
{
import
{
LARGE_MEDIA_BREAKPOINT
,
LARGE_MEDIA_BREAKPOINT
,
MAX_WIDTH_MEDIA_BREAKPOINT
,
MAX_WIDTH_MEDIA_BREAKPOINT
,
...
@@ -23,7 +24,9 @@ import { checkWarning } from 'constants/tokenSafety'
...
@@ -23,7 +24,9 @@ import { checkWarning } from 'constants/tokenSafety'
import
{
useTokenQuery
}
from
'
graphql/data/Token
'
import
{
useTokenQuery
}
from
'
graphql/data/Token
'
import
{
useIsUserAddedToken
,
useToken
}
from
'
hooks/Tokens
'
import
{
useIsUserAddedToken
,
useToken
}
from
'
hooks/Tokens
'
import
{
useNetworkTokenBalances
}
from
'
hooks/useNetworkTokenBalances
'
import
{
useNetworkTokenBalances
}
from
'
hooks/useNetworkTokenBalances
'
import
{
useStablecoinValue
}
from
'
hooks/useStablecoinPrice
'
import
{
useAtomValue
}
from
'
jotai/utils
'
import
{
useAtomValue
}
from
'
jotai/utils
'
import
{
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
'
import
{
useNavigate
,
useParams
}
from
'
react-router-dom
'
import
{
useNavigate
,
useParams
}
from
'
react-router-dom
'
...
@@ -112,8 +115,12 @@ export default function TokenDetails() {
...
@@ -112,8 +115,12 @@ export default function TokenDetails() {
/* network balance handling */
/* network balance handling */
const
{
data
:
networkData
}
=
NetworkBalances
(
token
?.
address
)
const
{
data
:
networkData
}
=
NetworkBalances
(
token
?.
address
)
const
{
chainId
:
connectedChainId
}
=
useWeb3React
()
const
{
chainId
:
connectedChainId
,
account
}
=
useWeb3React
()
const
totalBalance
=
4.3
// dummy data
const
balance
=
useTokenBalance
(
account
,
token
??
undefined
)
const
balanceNumber
=
balance
?
formatToDecimal
(
balance
,
Math
.
min
(
balance
.
currency
.
decimals
,
6
))
:
undefined
const
balanceUsd
=
useStablecoinValue
(
balance
)?.
toFixed
(
2
)
const
balanceUsdNumber
=
balanceUsd
?
parseFloat
(
balanceUsd
)
:
undefined
const
chainsToList
=
useMemo
(()
=>
{
const
chainsToList
=
useMemo
(()
=>
{
let
chainIds
=
[...
L1_CHAIN_IDS
,
...
L2_CHAIN_IDS
]
let
chainIds
=
[...
L1_CHAIN_IDS
,
...
L2_CHAIN_IDS
]
...
@@ -185,13 +192,14 @@ export default function TokenDetails() {
...
@@ -185,13 +192,14 @@ export default function TokenDetails() {
<
RightPanel
>
<
RightPanel
>
<
Widget
defaultToken=
{
token
??
undefined
}
onReviewSwapClick=
{
onReviewSwap
}
/>
<
Widget
defaultToken=
{
token
??
undefined
}
onReviewSwapClick=
{
onReviewSwap
}
/>
{
tokenWarning
&&
<
TokenSafetyMessage
tokenAddress=
{
token
.
address
}
warning=
{
tokenWarning
}
/>
}
{
tokenWarning
&&
<
TokenSafetyMessage
tokenAddress=
{
token
.
address
}
warning=
{
tokenWarning
}
/>
}
<
BalanceSummary
address=
{
token
.
address
}
/>
<
BalanceSummary
address=
{
token
.
address
}
balanceNumber=
{
balanceNumber
}
balanceUsdNumber=
{
balanceUsdNumber
}
/>
</
RightPanel
>
</
RightPanel
>
<
Footer
>
<
Footer
>
<
FooterBalanceSummary
<
FooterBalanceSummary
address=
{
token
.
address
}
address=
{
token
.
address
}
totalBalance=
{
totalBalance
}
networkBalances=
{
balancesByNetwork
}
networkBalances=
{
balancesByNetwork
}
balanceNumber=
{
balanceNumber
}
balanceUsdNumber=
{
balanceUsdNumber
}
/>
/>
</
Footer
>
</
Footer
>
<
TokenSafetyModal
<
TokenSafetyModal
...
...
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