Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Aug 29, 2024
1 parent 7add7f5 commit 989d81e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
19 changes: 11 additions & 8 deletions packages/extension-polkagate/src/components/FormatPrice.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

import type { BN } from '@polkadot/util';

import { Grid, Skeleton } from '@mui/material';
import React, { useMemo } from 'react';

import { BN } from '@polkadot/util';

import { useCurrency } from '../hooks';
import { amountToHuman } from '../util/utils';

Expand All @@ -15,14 +14,14 @@ interface Props {
decimalPoint?: number;
decimals?: number;
num?: number | string;
price?: number,
price?: number | null,
textAlign?: 'left' | 'right';
width?: string;
mt?: string;
skeletonHeight?: number;
}

export function nFormatter(num: number, decimalPoint: number) {
export function nFormatter (num: number, decimalPoint: number) {
const lookup = [
{ value: 1, symbol: '' },
{ value: 1e3, symbol: 'k' },
Expand All @@ -45,7 +44,7 @@ export function nFormatter(num: number, decimalPoint: number) {
return item ? (num / item.value).toFixed(decimalPoint).replace(rx, '$1') + item.symbol : '0';
}

function FormatPrice({ amount, decimalPoint = 2, decimals, mt = '0px', num, price, skeletonHeight = 15, textAlign = 'left', width = '90px' }: Props): React.ReactElement<Props> {
function FormatPrice ({ amount, decimalPoint = 2, decimals, mt = '0px', num, price, skeletonHeight = 15, textAlign = 'left', width = '90px' }: Props): React.ReactElement<Props> {
const currency = useCurrency();

const total = useMemo(() => {
Expand All @@ -54,14 +53,18 @@ function FormatPrice({ amount, decimalPoint = 2, decimals, mt = '0px', num, pric
}

if (amount && decimals && price !== undefined) {
return parseFloat(amountToHuman(amount, decimals)) * price;
return parseFloat(amountToHuman(amount, decimals)) * (price || 0);
}

return undefined;
}, [amount, decimals, num, price]);

return (
<Grid item mt={mt} textAlign={textAlign}>
<Grid
item
mt={mt}
textAlign={textAlign}
>
{total !== undefined
? `${currency?.sign || ''}${nFormatter(total as number, decimalPoint)}`
: <Skeleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

/* eslint-disable react/jsx-max-props-per-line */

import type { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import type { Balance } from '@polkadot/types/interfaces';
import type { BN } from '@polkadot/util';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { ArrowForwardIosRounded as ArrowForwardIosRoundedIcon } from '@mui/icons-material';
Expand All @@ -16,7 +16,6 @@ import { useTranslation } from '@polkadot/extension-polkagate/src/components/tra
import { useInfo, useNativeTokenPrice } from '@polkadot/extension-polkagate/src/hooks';
import { DATE_OPTIONS } from '@polkadot/extension-polkagate/src/util/constants';
import { noop } from '@polkadot/extension-polkagate/src/util/utils';
import { BN } from '@polkadot/util';

import { FormatPrice, ShowBalance } from '../../../components';

Expand Down Expand Up @@ -64,7 +63,7 @@ const ToBeReleased = ({ decimal, showUnstaking, text, toBeReleased, token }: ToB
</Collapse>
);

export default function DisplayBalance({ actions, address, amount, icons, isUnstaking, marginTop = '10px', onClicks, title, toBeReleased }: DisplayBalanceProps): React.ReactElement {
export default function DisplayBalance ({ actions, address, amount, icons, isUnstaking, marginTop = '10px', onClicks, title, toBeReleased }: DisplayBalanceProps): React.ReactElement {
const theme = useTheme();
const { t } = useTranslation();
const price = useNativeTokenPrice(address);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

/* eslint-disable react/jsx-max-props-per-line */

Expand Down Expand Up @@ -38,7 +37,7 @@ interface Props {
unlockingAmount: BN | undefined;
}

export default function PoolStaked({ address, balances, pool, redeemable, setShow, toBeReleased, unlockingAmount }: Props): React.ReactElement {
export default function PoolStaked ({ address, balances, pool, redeemable, setShow, toBeReleased, unlockingAmount }: Props): React.ReactElement {
const { t } = useTranslation();
const theme = useTheme();
const { api, chain } = useInfo(address);
Expand Down

0 comments on commit 989d81e

Please sign in to comment.