/** * Live Traffic Cards * Ball Studios */ import React from 'react'; interface LiveStats { rx_bytes: number; tx_bytes: number; recorded_at: string; } function formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; if (bytes < 1024 ** 3) return `${(bytes / 1024 / 1024).toFixed(2)} MB`; return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`; } interface Props { live: LiveStats | null; } export default function LiveTrafficCards({ live }: Props) { return (
⬇ Inbound
{live ? formatBytes(live.rx_bytes) : '—'}
⬆ Outbound
{live ? formatBytes(live.tx_bytes) : '—'}
⇅ Total
{live ? formatBytes(live.rx_bytes + live.tx_bytes) : '—'}
🕐 Last Update
{live ? new Date(live.recorded_at).toLocaleTimeString() : '—'}
); }