import React, { useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useAuth, useForum, useNetwork, useUIState } from '@/hooks'; import { EVerificationStatus } from '@opchan/core'; import { localDatabase } from '@opchan/core'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { LogOut, Terminal, AlertTriangle, CheckCircle, Key, CircleSlash, Home, Grid3X3, User, Bookmark, Settings, Menu, X, Clock, Trash2, } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog'; import { useToast } from '@/components/ui/use-toast'; import { useAppKitAccount, useDisconnect } from '@reown/appkit/react'; import { WalletWizard } from '@/components/ui/wallet-wizard'; import { WakuHealthDot } from '@/components/ui/waku-health-indicator'; const Header = () => { const { currentUser, delegationInfo } = useAuth(); const { statusMessage } = useNetwork(); const location = useLocation(); const { toast } = useToast(); const { content } = useForum(); const bitcoinAccount = useAppKitAccount({ namespace: 'bip122' }); const ethereumAccount = useAppKitAccount({ namespace: 'eip155' }); const { disconnect } = useDisconnect(); const isConnected = bitcoinAccount.isConnected || ethereumAccount.isConnected; const [walletWizardOpen, setWalletWizardOpen] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); // Use centralized UI state instead of direct LocalDatabase access const [hasShownWizard, setHasShownWizard] = useUIState( 'hasShownWalletWizard', false ); // Auto-open wizard when wallet connects for the first time React.useEffect(() => { if (isConnected && !hasShownWizard) { setWalletWizardOpen(true); setHasShownWizard(true); } }, [isConnected, hasShownWizard, setHasShownWizard]); const handleConnect = async () => { setWalletWizardOpen(true); }; const handleOpenWizard = () => { setWalletWizardOpen(true); }; const handleDisconnect = async () => { await disconnect(); setHasShownWizard(false); // Reset so wizard can show again on next connection toast({ title: 'Wallet Disconnected', description: 'Your wallet has been disconnected successfully.', }); }; const handleClearDatabase = async () => { try { await localDatabase.clearAll(); toast({ title: 'Database Cleared', description: 'All local data has been cleared successfully.', }); } catch (error) { console.error('Failed to clear database:', error); toast({ title: 'Error', description: 'Failed to clear local database. Please try again.', variant: 'destructive', }); } }; const getStatusIcon = () => { if (!isConnected) return ; if ( currentUser?.verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED && delegationInfo?.isValid ) { return ; } else if ( currentUser?.verificationStatus === EVerificationStatus.WALLET_CONNECTED ) { return ; } else if ( currentUser?.verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED ) { return ; } else { return ; } }; return ( <>
{/* Top Row - Logo, Network Status, User Actions */}
{/* Left: Logo */}
opchan
{/* Center: Network Status (Desktop) */}
{statusMessage} {content.lastSync && (
{new Date(content.lastSync).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', })}
)}
{/* Right: User Actions */}
{/* Network Status (Mobile) */}
{/* User Status & Actions */} {isConnected ? (
{/* Status Badge */} {getStatusIcon()} {currentUser?.verificationStatus === EVerificationStatus.WALLET_UNCONNECTED ? 'CONNECT' : delegationInfo?.isValid ? 'READY' : currentUser?.verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED ? 'EXPIRED' : 'DELEGATE'} {/* User Dropdown */} Profile Setup Wizard e.preventDefault()} className="flex items-center space-x-2 text-orange-400 focus:text-orange-400" > Clear Database Clear Local Database This will permanently delete all locally stored data including:
• Posts and comments
• User identities and preferences
• Bookmarks and votes
• UI state and settings

This action cannot be undone.
Cancel Clear Database
Disconnect
) : ( )} {/* Mobile Menu Toggle */}
{/* Navigation Bar (Desktop) */}
{/* Mobile Navigation */} {mobileMenuOpen && (
{/* Mobile Network Status */}
{statusMessage} {content.lastSync && ( {new Date(content.lastSync).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', })} )}
)}
{/* Wallet Wizard */} { setWalletWizardOpen(false); toast({ title: 'Setup Complete', description: 'Your wallet is ready to use!', }); }} /> ); }; export default Header;