import React, { useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useAuth } from '@/contexts/useAuth'; import { useForum } from '@/contexts/useForum'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { LogOut, Terminal, Wifi, WifiOff, AlertTriangle, CheckCircle, Key, RefreshCw, CircleSlash, Home, Grid3X3, } from 'lucide-react'; import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import { useToast } from '@/components/ui/use-toast'; import { useAppKitAccount, useDisconnect } from '@reown/appkit/react'; import { WalletWizard } from '@/components/ui/wallet-wizard'; import { CallSignSetupDialog } from '@/components/ui/call-sign-setup-dialog'; import { useUserDisplay } from '@/hooks/useUserDisplay'; const Header = () => { const { verificationStatus, getDelegationStatus } = useAuth(); const { isNetworkConnected, isRefreshing } = useForum(); const location = useLocation(); const { toast } = useToast(); // Use AppKit hooks for multi-chain support const bitcoinAccount = useAppKitAccount({ namespace: 'bip122' }); const ethereumAccount = useAppKitAccount({ namespace: 'eip155' }); const { disconnect } = useDisconnect(); // Determine which account is connected const isBitcoinConnected = bitcoinAccount.isConnected; const isEthereumConnected = ethereumAccount.isConnected; const isConnected = isBitcoinConnected || isEthereumConnected; const address = isConnected ? isBitcoinConnected ? bitcoinAccount.address : ethereumAccount.address : undefined; const [walletWizardOpen, setWalletWizardOpen] = useState(false); // Get display name from hook const { displayName } = useUserDisplay(address || ''); // Use sessionStorage to persist wizard state across navigation const getHasShownWizard = () => { try { return sessionStorage.getItem('hasShownWalletWizard') === 'true'; } catch { return false; } }; const setHasShownWizard = (value: boolean) => { try { sessionStorage.setItem('hasShownWalletWizard', value.toString()); } catch { // Fallback if sessionStorage is not available } }; // Auto-open wizard when wallet connects for the first time React.useEffect(() => { if (isConnected && !getHasShownWizard()) { setWalletWizardOpen(true); setHasShownWizard(true); } }, [isConnected]); const handleConnect = async () => { 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 getAccountStatusText = () => { switch (verificationStatus) { case 'unverified': return 'Setup Required'; case 'verifying': return 'Verifying...'; case 'verified-none': return 'Read-Only Access'; case 'verified-basic': return getDelegationStatus().isValid ? 'Full Access' : 'Setup Key'; case 'verified-owner': return getDelegationStatus().isValid ? 'Premium Access' : 'Setup Key'; default: return 'Setup Account'; } }; const getAccountStatusIcon = () => { switch (verificationStatus) { case 'unverified': return ; case 'verifying': return ; case 'verified-none': return ; case 'verified-basic': return getDelegationStatus().isValid ? ( ) : ( ); case 'verified-owner': return getDelegationStatus().isValid ? ( ) : ( ); default: return ; } }; const getAccountStatusVariant = () => { switch (verificationStatus) { case 'unverified': return 'destructive'; case 'verifying': return 'outline'; case 'verified-none': return 'secondary'; case 'verified-basic': return getDelegationStatus().isValid ? 'default' : 'outline'; case 'verified-owner': return getDelegationStatus().isValid ? 'default' : 'outline'; default: return 'outline'; } }; return ( <>
OpChan
{/* Navigation Tabs */}
{isNetworkConnected ? ( <> WAKU: Connected ) : ( <> WAKU: Offline )}

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

{isRefreshing &&

Refreshing data...

}
{!isConnected ? ( ) : (

Account Setup

Click to view and manage your wallet connection, verification status, and key delegation.

{displayName}

{displayName !== `${address?.slice(0, 5)}...${address?.slice(-4)}` ? `${displayName} (${address})` : address}

Disconnect Wallet
)}
{ toast({ title: 'Setup Complete', description: 'You can now use all OpChan features!', }); }} /> ); }; export default Header;