All files / shared / components TokenDisplay.tsx

78.12% Statements 25/32
68.75% Branches 22/32
75% Functions 6/8
80% Lines 20/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1637x     964x 130x 40x 10x 6x 964x 964x     10x 10x   37x
interface TokenDisplayProps {
  value: number
  label?: string
}
 
function abbreviate(n: number): string {
  if (n < 1000) return String(n)
  if (n < 1_000_000) return `${(n / 1000).toFixed(n % 1000 === 0 ? 0 : 1)}K`
  return `${(n / 1_000_000).toFixed(n % 1_000_000 === 0 ? 0 : 1)}M`
}
 
export function TokenDisplay({ value, label }: TokenDisplayProps) {
  const text = abbreviate(value)
  return <span>{label ? `${label}: ${text}` : text}</span>
}