import { Activity, Box, Cpu, ExternalLink, Gauge, Radio, RefreshCw } from 'lucide-react';
import { useLiveChain } from '../../hooks/useLiveChain';
import { endpoints } from '../../config/endpoints';
import { explorerBlockUrl } from '../../services/explorer';
function ago(date: Date | null): string {
if (!date) return '—';
const s = Math.round((Date.now() - date.getTime()) / 1000);
if (s < 60) return `${s}s ago`;
const m = Math.floor(s / 60);
if (m < 60) return `${m}m ago`;
return `${Math.floor(m / 60)}h ago`;
}
export default function LiveNetworkPanel() {
const { health, latestBlock, stats, loading, error, lastUpdated, refresh } = useLiveChain();
const chainOk = health && health.chainId === endpoints.chain138.chainId;
const statusLabel = error ? 'degraded' : chainOk ? 'live' : loading ? 'connecting' : 'offline';
const statusColor = error ? '#ef4444' : chainOk ? '#22c55e' : loading ? '#eab308' : '#6b7280';
return (
Chain 138 — Live Network
{statusLabel}
{ago(lastUpdated)}
} label="Latest block" mono value={health ? health.blockNumber.toLocaleString() : '—'} href={latestBlock ? explorerBlockUrl(latestBlock.number) : undefined} />
} label="Chain ID" mono value={health ? `${health.chainId}` : '—'} />
} label="Gas price" mono value={health ? `${health.gasPriceGwei.toFixed(2)} gwei` : '—'} />
} label="RPC latency" mono value={health ? `${health.latencyMs} ms` : '—'} />
} label="Total blocks" mono value={stats ? stats.total_blocks.toLocaleString() : '—'} />
} label="Total txns" mono value={stats ? stats.total_transactions.toLocaleString() : '—'} />
} label="Txns today" mono value={stats ? stats.transactions_today.toLocaleString() : '—'} />
} label="Addresses" mono value={stats ? stats.total_addresses.toLocaleString() : '—'} />
);
}
function Stat({ icon, label, value, mono, href }: { icon: React.ReactNode; label: string; value: string; mono?: boolean; href?: string }) {
const valueEl = (
{value}
);
return (
);
}