From 622581ee0aeaa6c72aa8345fe607810278ae5e0b Mon Sep 17 00:00:00 2001
From: lynn <41491154+lynnshaoyu@users.noreply.github.com>
Date: Tue, 6 Sep 2022 11:50:02 -0400
Subject: [PATCH] feat: show real values for current network balance (#4565)
* init
* remove card when balance is zero
* remove commented code
* remove commented
---
.../Tokens/TokenDetails/BalanceSummary.tsx | 72 ++++++-------------
src/pages/TokenDetails/index.tsx | 2 +-
2 files changed, 23 insertions(+), 51 deletions(-)
diff --git a/src/components/Tokens/TokenDetails/BalanceSummary.tsx b/src/components/Tokens/TokenDetails/BalanceSummary.tsx
index 48527b497b..de1980d3f4 100644
--- a/src/components/Tokens/TokenDetails/BalanceSummary.tsx
+++ b/src/components/Tokens/TokenDetails/BalanceSummary.tsx
@@ -1,12 +1,12 @@
import { Trans } from '@lingui/macro'
import { useWeb3React } from '@web3-react/core'
-import { getChainInfoOrDefault } from 'constants/chainInfo'
+import { formatToDecimal } from 'components/AmplitudeAnalytics/utils'
import { useToken } from 'hooks/Tokens'
import { useNetworkTokenBalances } from 'hooks/useNetworkTokenBalances'
+import { useStablecoinValue } from 'hooks/useStablecoinPrice'
+import { useTokenBalance } from 'lib/hooks/useCurrencyBalance'
import { AlertTriangle } from 'react-feather'
-import styled, { useTheme } from 'styled-components/macro'
-
-import NetworkBalance from './NetworkBalance'
+import styled from 'styled-components/macro'
const BalancesCard = styled.div`
width: 100%;
@@ -33,14 +33,9 @@ const ErrorText = styled.span`
display: flex;
flex-wrap: wrap;
`
-const NetworkBalancesSection = styled.div`
- height: fit-content;
-`
+
const TotalBalanceSection = styled.div`
height: fit-content;
- border-bottom: 1px solid ${({ theme }) => theme.backgroundOutline};
- margin-bottom: 20px;
- padding-bottom: 20px;
`
const TotalBalance = styled.div`
display: flex;
@@ -54,58 +49,35 @@ const TotalBalanceItem = styled.div`
display: flex;
`
-export default function BalanceSummary({
- address,
- networkBalances,
- totalBalance,
-}: {
- address: string
- networkBalances: (JSX.Element | null)[] | null
- totalBalance: number
-}) {
- const theme = useTheme()
- const tokenSymbol = useToken(address)?.symbol
- const { loading, error, data } = useNetworkTokenBalances({ address })
+export default function BalanceSummary({ address }: { address: string }) {
+ const token = useToken(address)
+ const { loading, error } = useNetworkTokenBalances({ address })
- const { chainId: connectedChainId } = useWeb3React()
+ 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
- const { label: connectedLabel, logoUrl: connectedLogoUrl } = getChainInfoOrDefault(connectedChainId)
- const connectedFiatValue = 1
- const multipleBalances = true // for testing purposes
-
- if (loading) return null
+ if (loading || (!error && !balanceNumber && !balanceUsdNumber)) return null
return (
{error ? (
- There was an error loading your {tokenSymbol} balance
+ There was an error loading your {token?.symbol} balance
- ) : multipleBalances ? (
- <>
-
- Your balance across all networks
-
- {`${totalBalance} ${tokenSymbol}`}
- $4,210.12
-
-
- Your balances by network
- {data && networkBalances}
- >
) : (
<>
- Your balance on {connectedLabel}
-
+
+ Your balance
+
+ {`${balanceNumber} ${token?.symbol}`}
+ {`$${balanceUsdNumber}`}
+
+
>
)}
diff --git a/src/pages/TokenDetails/index.tsx b/src/pages/TokenDetails/index.tsx
index 2bbfdbcf1c..c991f3719b 100644
--- a/src/pages/TokenDetails/index.tsx
+++ b/src/pages/TokenDetails/index.tsx
@@ -130,7 +130,7 @@ export default function TokenDetails() {
{tokenWarning && }
-
+