'use client'; import { useEffect, useState } from 'react'; import { checkHealth } from '@/lib/api/gateway'; import { useAuth } from '@/lib/auth'; import { Shield, LogOut } from 'lucide-react'; // NOTE: PortalHeader fetches node status + auth internally via useEffect. // Pages that need a custom header can pass one via PortalLayout's `header` slot // instead of modifying this component. See layout-portal.tsx PortalLayoutProps. export default function PortalHeader() { const { user, logout } = useAuth(); const [nodeStatus, setNodeStatus] = useState<'online' | 'offline' | 'checking'>('checking'); const [nodeVersion, setNodeVersion] = useState(''); useEffect(() => { let mounted = true; async function poll() { try { const h = await checkHealth(); if (!mounted) return; setNodeStatus('online'); setNodeVersion(h.node); } catch (err) { console.error('[PortalHeader] Health check failed:', err); if (!mounted) return; setNodeStatus('offline'); } } poll(); const iv = setInterval(poll, 30_000); return () => { mounted = false; clearInterval(iv); }; }, []); return (
{/* Page title slot — parent fills with children */}
{/* Right side */}
{/* Node status */}
{nodeStatus === 'online' ? `Node ${nodeVersion}` : 'Offline'}
{/* Wallet badge */} {user && (
{user.address.slice(0, 6)}...{user.address.slice(-4)}
)}
); }