forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken-amount.tsx
More file actions
40 lines (37 loc) · 1.06 KB
/
Copy pathtoken-amount.tsx
File metadata and controls
40 lines (37 loc) · 1.06 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
import { cn } from '@/lib/utils'
import { formatTokenAmount, formatCompactAmount } from '@/lib/stream-utils'
import type { TokenInfo } from '@/types/stream'
interface TokenAmountProps {
amount: bigint
token: TokenInfo
className?: string
symbolClassName?: string
maxFractionDigits?: number
showSymbol?: boolean
/** Display amount in compact notation (e.g., "1.2K"). @default false */
compact?: boolean
}
/** Formats a raw bigint token amount with correct decimals + symbol. */
export function TokenAmount({
amount,
token,
className,
symbolClassName,
maxFractionDigits = 4,
showSymbol = true,
compact = false,
}: TokenAmountProps) {
const formattedAmount = compact
? formatCompactAmount(amount, token.decimals)
: formatTokenAmount(amount, token.decimals, maxFractionDigits)
return (
<span className={cn('font-mono tabular-nums', className)}>
{formattedAmount}
{showSymbol && (
<span className={cn('ml-1 text-muted-foreground', symbolClassName)}>
{token.symbol}
</span>
)}
</span>
)
}