import { cn } from '@/lib/utils'; import { useEffect, useState } from 'react'; interface LedDisplayProps { value: number; className?: string; animate?: boolean; onClick?: () => void; } export default function LedDisplay({ value, className, animate = true, onClick }: LedDisplayProps) { const [displayValue, setDisplayValue] = useState(0); // Animate number changes useEffect(() => { if (!animate) { setDisplayValue(value); return; } const duration = 1000; // 1 second animation const steps = 60; // 60fps const stepValue = (value - displayValue) / steps; if (Math.abs(stepValue) < 0.01) { setDisplayValue(value); return; } const timer = setInterval(() => { setDisplayValue(prev => { const next = prev + stepValue; if (Math.abs(next - value) < Math.abs(stepValue)) { clearInterval(timer); return value; } return next; }); }, duration / steps); return () => clearInterval(timer); }, [value, displayValue, animate]); // Format number appropriately for shares const formatValue = (value: number) => { // If it's a whole number, show it as integer if (value % 1 === 0) { return value.toString(); } // Otherwise show up to 6 decimal places, removing trailing zeros return value.toFixed(6).replace(/\.?0+$/, ''); }; const formattedValue = formatValue(displayValue); return (
{/* Background glow effect */}
{formattedValue}
{/* Main LED text */}
{formattedValue}
{/* Subtle scan line effect */}
{/* Label */}
total shares
); }