Skip to content

Commit

Permalink
Merge branch 'feat/revoke-gas-account' into tmp/20241025
Browse files Browse the repository at this point in the history
  • Loading branch information
kim12322222 committed Oct 25, 2024
2 parents ce31336 + 11c1ab2 commit 7fc69d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
9 changes: 6 additions & 3 deletions src/ui/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,18 @@ export const formatGasCostUsd = (gasCostUsd: BigNumber) => {
return formatTokenAmount(value);
};

export const formatGasHeaderUsdValue = (value: string | number) => {
export const formatGasHeaderUsdValue = (
value: string | number,
roundingMode = BigNumber.ROUND_UP as BigNumber.RoundingMode
) => {
const bnValue = new BigNumber(value);
if (bnValue.lt(0)) {
return `-$${formatNumber(Math.abs(Number(value)))}`;
}
if (bnValue.gte(0.01)) {
return `$${formatNumber(value)}`;
return `$${formatNumber(value, 2, undefined, roundingMode)}`;
}
if (bnValue.lt(0.0001)) return '<$0.0001';

return `$${formatNumber(value, 4)}`;
return `$${formatNumber(value, 4, undefined, roundingMode)}`;
};
20 changes: 2 additions & 18 deletions src/ui/views/GasAccount/components/History.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { ReactComponent as RcIconEmptyCC } from '@/ui/assets/empty-cc.svg';
import { useTranslation } from 'react-i18next';
import { formatNumber, sinceTime } from '@/ui/utils';
import { formatGasHeaderUsdValue, sinceTime } from '@/ui/utils';
import clsx from 'clsx';
import { useGasAccountHistory } from '../hooks';
import { Skeleton } from 'antd';
Expand All @@ -10,22 +10,6 @@ import { ReactComponent as RcIconOpenExternalCC } from '@/ui/assets/open-externa
import { findChainByServerID } from '@/utils/chain';
import BigNumber from 'bignumber.js';

const formatUsdValue = (value: string | number) => {
const bnValue = new BigNumber(value);
if (bnValue.lt(0)) {
return `-$${formatNumber(
Math.abs(Number(value)),
4,
undefined,
BigNumber.ROUND_DOWN
)}`;
}
if (bnValue.gte(0.0001) || bnValue.eq(0)) {
return `$${formatNumber(value, 4, undefined, BigNumber.ROUND_DOWN)}`;
}
return '<$0.0001';
};

const HistoryItem = ({
time,
isPending = false,
Expand Down Expand Up @@ -90,7 +74,7 @@ const HistoryItem = ({
)}
<div className="text-14 font-medium text-r-neutral-title-1">
{sign}
{formatUsdValue(value)}{' '}
{formatGasHeaderUsdValue(value, BigNumber.ROUND_DOWN)}{' '}
</div>
</div>
);
Expand Down

0 comments on commit 7fc69d3

Please sign in to comment.