import React from 'react'; import { Link } from 'react-router-dom'; import { useAuth } from '@/contexts/AuthContext'; import { useForum } from '@/contexts/ForumContext'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { ShieldCheck, LogOut, Terminal, Wifi, WifiOff, AlertTriangle, CheckCircle, Key, RefreshCw, CircleSlash } from 'lucide-react'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { SDSStatus } from './SDSStatus'; const Header = () => { const { currentUser, isAuthenticated, verificationStatus, connectWallet, disconnectWallet, verifyOrdinal, delegateKey, isDelegationValid, delegationTimeRemaining } = useAuth(); const { isNetworkConnected, isRefreshing } = useForum(); const handleConnect = async () => { await connectWallet(); }; const handleDisconnect = () => { disconnectWallet(); }; const handleVerify = async () => { await verifyOrdinal(); }; const handleDelegateKey = async () => { await delegateKey(); }; const formatDelegationTime = () => { if (!isDelegationValid()) return null; const timeRemaining = delegationTimeRemaining(); const hours = Math.floor(timeRemaining / (1000 * 60 * 60)); const minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60)); return `${hours}h ${minutes}m`; }; const renderDelegationButton = () => { if (verificationStatus !== 'verified-owner') return null; const hasValidDelegation = isDelegationValid(); const timeRemaining = formatDelegationTime(); return ( {hasValidDelegation ? (

Browser key active for ~{timeRemaining}. Wallet signatures not needed for most actions.

) : (

Delegate a browser key for 24h to avoid constant wallet signing.

)}
); }; const renderAccessBadge = () => { if (verificationStatus === 'unverified') { return (

Action Required

Verify your Ordinal ownership to enable posting, commenting, and voting.

); } if (verificationStatus === 'verifying') { return ( [VERIFYING...] ); } if (verificationStatus === 'verified-none') { return ( [VERIFIED | READ-ONLY]

Wallet Verified - No Ordinals

No Ordinal Operators found. Read-only access granted.

); } // Verified - Ordinal Owner if (verificationStatus === 'verified-owner') { return ( [OWNER ✔]

Ordinal Owner Verified!

Full forum access granted.

); } return null; }; return (
OpChan
{isNetworkConnected ? ( <> WAKU: Connected ) : ( <> WAKU: Offline )}

{isNetworkConnected ? "Waku network connection active." : "Waku network connection lost."}

{isRefreshing &&

Refreshing data...

}
{!currentUser ? ( ) : (
{renderAccessBadge()} {renderDelegationButton()} {currentUser.address.slice(0, 5)}...{currentUser.address.slice(-4)}

{currentUser.address}

Disconnect Wallet
)}
); }; export default Header;