All files / shared / components TokenDisplay.tsx

78.12% Statements 25/32
65.62% Branches 21/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 1654x     452x 138x 72x 10x 6x 452x 452x     10x 10x   54x
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>
}