All files / shared / components TokenDisplay.tsx

72% Statements 18/25
54.54% Branches 12/22
66.66% Functions 4/6
76.19% Lines 16/21

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 1650x     294x 98x 44x     294x 294x           50x
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>
}