-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverview-item-value.tsx
More file actions
51 lines (45 loc) · 1.25 KB
/
overview-item-value.tsx
File metadata and controls
51 lines (45 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { type FC, useMemo } from 'react';
import { InlineLoader } from 'shared/components';
import { FormatToken } from 'shared/formatters';
import { isBigint } from 'utils';
import { WEI_PER_ETHER } from 'consts/tx';
import { ContentText } from './styles';
export interface ItemValueProps {
content: string | number | undefined | boolean | bigint;
isLoading?: boolean;
color?: string;
symbol?: string;
textSize?: 'lg' | 'xl';
}
const countMaxDecimalDigits = (amount: bigint) => {
return amount / WEI_PER_ETHER > 1000 ? 1 : 4;
};
export const OverviewItemValue: FC<ItemValueProps> = (props) => {
const { content, isLoading, color, textSize = 'xl', symbol = '' } = props;
const contentView = useMemo(
() =>
isBigint(content) ? (
<FormatToken
amount={content}
maxDecimalDigits={countMaxDecimalDigits(content)}
showAmountTip={false}
symbol={symbol}
/>
) : (
content
),
[content, symbol],
);
return (
<InlineLoader isLoading={isLoading} width={100} height={28}>
<ContentText
data-testid="blockValue"
size={textSize}
style={{ color }}
strong
>
{contentView || '-'}
</ContentText>
</InlineLoader>
);
};