From 091ea61dd8efa0a013769e32d6b5962828065681 Mon Sep 17 00:00:00 2001 From: Tien Nam Dao Date: Fri, 4 Nov 2022 17:18:57 +0700 Subject: [PATCH] fix: update token page meta tag + parse BigNumber with decimals --- pages/tokens.tsx | 28 +++++++++++++++++++ utils/helper.ts | 3 ++ views/tokens/TokenOverview.tsx | 20 ++++++------- views/tokens/TokenRow.tsx | 2 +- .../TokenTransactionTab/TokenTransaction.tsx | 6 ++-- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/pages/tokens.tsx b/pages/tokens.tsx index 1ddb6b6f..862878b3 100644 --- a/pages/tokens.tsx +++ b/pages/tokens.tsx @@ -26,6 +26,34 @@ const AllTokensPage: React.FC = _ => { Tokens | {process.env.NEXT_PUBLIC_TITLE} + + + + + + + + + + {/* */} + {/* */} + + + + + {/* */} diff --git a/utils/helper.ts b/utils/helper.ts index 12d52acc..8ab3bb41 100644 --- a/utils/helper.ts +++ b/utils/helper.ts @@ -22,6 +22,9 @@ export const ellipseLeftText = (address: string, to: number) => { } export const convertBalanceToView = (value: number | string, decimals = 18) => { + if (!value) return '' + if (!decimals) decimals = 1 + const big = BigNumber.from(value) const valueInWei = formatUnits(big, decimals).valueOf() return valueInWei diff --git a/views/tokens/TokenOverview.tsx b/views/tokens/TokenOverview.tsx index d2336fca..f8da1632 100644 --- a/views/tokens/TokenOverview.tsx +++ b/views/tokens/TokenOverview.tsx @@ -1,4 +1,4 @@ -import { Typography as TypographyUI, useMobileLayout } from '@astraprotocol/astra-ui' +import { Typography as TypographyUI } from '@astraprotocol/astra-ui' import clsx from 'clsx' import CopyButton from 'components/Button/CopyButton' import BackgroundCard from 'components/Card/Background/BackgroundCard' @@ -14,8 +14,6 @@ interface Props { } const TokenOverview = ({ token, tokenData }: Props) => { - const { isMobile } = useMobileLayout() - return ( @@ -37,8 +35,8 @@ const TokenOverview = ({ token, tokenData }: Props) => { currency={tokenData.symbol} value={ tokenData.totalSupply - ? convertBalanceToView(tokenData.totalSupply, parseInt(tokenData.decimals)) - : 'NaN' + ? convertBalanceToView(tokenData.totalSupply, parseInt(tokenData.decimals || '1')) + : '' } fixNumber={5} /> @@ -65,11 +63,13 @@ const TokenOverview = ({ token, tokenData }: Props) => {
{tokenData.type} -
- Decimals: -
- {tokenData.decimals} -
+ {tokenData.decimals && ( +
+ Decimals: +
+ {tokenData.decimals} +
+ )}
) diff --git a/views/tokens/TokenRow.tsx b/views/tokens/TokenRow.tsx index 720715c2..06bde3bd 100644 --- a/views/tokens/TokenRow.tsx +++ b/views/tokens/TokenRow.tsx @@ -38,7 +38,7 @@ export default function TokenRow({ index, token }: Props) {
{formatNumber( - convertBalanceToView(token.totalSupply, parseInt(token.decimals)), + convertBalanceToView(token.totalSupply, parseInt(token.decimals || '1')), getEnvNumber('NEXT_PUBLIC_MAXIMUM_FRACTION_DIGITS') )} diff --git a/views/tokens/tabs/TokenTransactionTab/TokenTransaction.tsx b/views/tokens/tabs/TokenTransactionTab/TokenTransaction.tsx index db79a365..40f327a4 100644 --- a/views/tokens/tabs/TokenTransactionTab/TokenTransaction.tsx +++ b/views/tokens/tabs/TokenTransactionTab/TokenTransaction.tsx @@ -4,7 +4,7 @@ import GradientRow from 'components/Row/GradientRow' import Timer from 'components/Timer' import Typography from 'components/Typography' import { evmAddressName } from 'utils/evm' -import { convertBalanceToView, ellipseBetweenText, ellipseRightText, LinkMaker } from 'utils/helper' +import { convertBalanceToView, ellipseBetweenText, LinkMaker } from 'utils/helper' import styles from './style.module.scss' interface Props { @@ -35,7 +35,7 @@ const AddressTransaction = ({ transaction }: Props) => { classes={'margin-right-xs'} fontType="Titi" > - {ellipseRightText(transaction.transactionHash, 30)} + {ellipseBetweenText(transaction.transactionHash, 16, 16)} {/* { <>