forked from koshikraj/ottopus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken-amount.tsx
More file actions
47 lines (43 loc) · 1.2 KB
/
Copy pathtoken-amount.tsx
File metadata and controls
47 lines (43 loc) · 1.2 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 { cn } from '@/lib/cn'
import { formatAmount } from '@/lib/format'
export interface TokenAmountProps {
/** Integer base units as a string. Never a number — precision would be lost. */
value: string
decimals: number
symbol?: string
/** Signed rendering for balance deltas on a review page. */
direction?: 'in' | 'out' | 'neutral'
className?: string
}
const DIRECTION_CLASS = {
in: 'text-[var(--ot-ok-text)]',
out: 'text-[var(--ot-text)]',
neutral: 'text-[var(--ot-text)]',
} as const
/**
* Amounts are tabular so digits align down a column of balance changes, and a
* differing magnitude is visible as a differing width.
*/
export function TokenAmount({
value,
decimals,
symbol,
direction = 'neutral',
className,
}: TokenAmountProps) {
const formatted = formatAmount(value, decimals)
const sign = direction === 'in' ? '+' : direction === 'out' ? '−' : ''
return (
<span
className={cn(
'font-mono text-[14px] font-medium tabular-nums tracking-[-0.02em]',
DIRECTION_CLASS[direction],
className,
)}
>
{sign}
{formatted}
{symbol ? <span className="ml-1 text-[var(--ot-text-3)]">{symbol}</span> : null}
</span>
)
}