-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtokenValue.tsx
More file actions
47 lines (41 loc) · 1.08 KB
/
tokenValue.tsx
File metadata and controls
47 lines (41 loc) · 1.08 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
import * as React from 'react';
import { Link } from 'react-router-dom';
import { observer } from 'mobx-react';
import { BigIntType } from 'jsbi-utils';
import { tokensStore } from '../stores/tokens';
interface TokenValueProps {
value: BigIntType | BigIntType[];
color: number;
precision?: number;
tokenLink?: boolean;
}
const round = (n: number, precision?: number) => {
if (precision === undefined) {
return n;
}
const dec = 10 ** precision;
return Math.round(n * dec) / dec;
};
const TokenValue: React.FC<TokenValueProps> = ({
value,
color,
precision,
tokenLink,
}) => {
const token = tokensStore.tokenForColor(color);
if (!token || !token.ready || value === undefined) {
return null;
}
return (
<React.Fragment>
{token.isNft
? (value as BigIntType[]).length
: round(token.toTokens(value as BigIntType), precision)}{' '}
{!tokenLink && token.symbol}
{tokenLink && (
<Link to={`/explorer/address/${token.address}`}>{token.symbol}</Link>
)}
</React.Fragment>
);
};
export default observer(TokenValue);