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 78f01e7 + 9083e0a commit ce31336
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
21 changes: 15 additions & 6 deletions src/ui/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export const numberWithCommasIsLtOne = (
export const formatNumber = (
num: string | number,
decimal = 2,
opt = {} as BigNumber.Format
opt = {} as BigNumber.Format,
roundingMode = BigNumber.ROUND_UP as BigNumber.RoundingMode
) => {
const n = new BigNumber(num);
const format = {
Expand All @@ -87,11 +88,11 @@ export const formatNumber = (
// hide the after-point part if number is more than 1000000
if (n.isGreaterThan(1000000)) {
if (n.gte(1e9)) {
return `${n.div(1e9).toFormat(decimal, format)}B`;
return `${n.div(1e9).toFormat(decimal, roundingMode, format)}B`;
}
return n.decimalPlaces(0).toFormat(format);
}
return n.toFormat(decimal, format);
return n.toFormat(decimal, roundingMode, format);
};

export const formatPrice = (price: string | number) => {
Expand All @@ -116,13 +117,21 @@ export const intToHex = (n: number) => {
return `0x${n.toString(16)}`;
};

export const formatUsdValue = (value: string | number) => {
export const formatUsdValue = (
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)))}`;
return `-$${formatNumber(
Math.abs(Number(value)),
2,
undefined,
roundingMode
)}`;
}
if (bnValue.gte(0.01) || bnValue.eq(0)) {
return `$${formatNumber(value)}`;
return `$${formatNumber(value, 2, undefined, roundingMode)}`;
}
return '<$0.01';
};
Expand Down
6 changes: 4 additions & 2 deletions src/ui/views/GasAccount/components/DashBoardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ const formatUsdValue = (usd: string | number) => {
return `$${formatTokenAmount(Number(v).toFixed(0), 0)}`;
}
if (v >= 100) {
return `$${Number(v).toFixed(1)}`;
const fixDown = Math.floor(v * 10) / 10;
return `$${Number(fixDown).toFixed(1)}`;
}
return `$${Number(v).toFixed(2)}`;
const fixDown = Math.floor(v * 100) / 100;
return `$${Number(fixDown).toFixed(2)}`;
};

export const GasAccountDashBoardHeader = () => {
Expand Down
19 changes: 18 additions & 1 deletion src/ui/views/GasAccount/components/History.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import React from 'react';
import { ReactComponent as RcIconEmptyCC } from '@/ui/assets/empty-cc.svg';
import { useTranslation } from 'react-i18next';
import { formatUsdValue, sinceTime } from '@/ui/utils';
import { formatNumber, sinceTime } from '@/ui/utils';
import clsx from 'clsx';
import { useGasAccountHistory } from '../hooks';
import { Skeleton } from 'antd';
import { ReactComponent as RcIconPendingCC } from '@/ui/assets/pending-cc.svg';
import { ReactComponent as RcIconOpenExternalCC } from '@/ui/assets/open-external-cc.svg';
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,
Expand Down
6 changes: 3 additions & 3 deletions src/ui/views/GasAccount/components/LoginPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const GasACcountCurrentAddress = ({
const [alias] = useAlias(account?.address || currentAccount?.address || '');

const addressTypeIcon = useBrandIcon({
address: currentAccount!.address,
brandName: currentAccount!.brandName,
type: currentAccount!.type,
address: account?.address || currentAccount!.address,
brandName: account?.brandName || currentAccount!.brandName,
type: account?.type || currentAccount!.type,
});
return (
<div className="mb-[20px] py-12 px-16 rounded-[6px] flex items-center bg-r-neutral-card-2">
Expand Down
3 changes: 2 additions & 1 deletion src/ui/views/GasAccount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useHistory } from 'react-router-dom';
import { GasAccountRefreshIdProvider } from './hooks/context';
import { GasAccountWrapperBg } from './components/WrapperBg';
import { GasAccountBlueLogo } from './components/GasAccountBlueLogo';
import BigNumber from 'bignumber.js';

const DEPOSIT_LIMIT = 1000;

Expand Down Expand Up @@ -112,7 +113,7 @@ const GasAccountInner = () => {
<GasAccountWrapperBg className="mb-[20px] flex flex-col items-center h-[260px] bg-r-neutral-card1 rounded-[8px] py-20 px-16 pt-24">
<GasAccountBlueLogo />
<div className="text-r-neutral-title-1 text-[32px] leading-normal font-bold mt-24">
{formatUsdValue(balance)}
{formatUsdValue(balance, BigNumber.ROUND_DOWN)}
</div>

<div className="w-full mt-auto flex gap-12 items-center justify-center">
Expand Down

0 comments on commit ce31336

Please sign in to comment.