import React, { useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useAuth, useNetworkStatus } from '@/hooks'; import { useAuth as useAuthContext } from '@/contexts/useAuth'; import { EVerificationStatus } from '@/types/identity'; import { useForum } from '@/contexts/useForum'; import { Button } from '@/components/ui/button'; import { LogOut, Terminal, AlertTriangle, CheckCircle, Key, CircleSlash, Home, Grid3X3, User, } 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 { useUserDisplay } from '@/hooks'; const Header = () => { const { verificationStatus } = useAuth(); const { getDelegationStatus } = useAuthContext(); const delegationInfo = getDelegationStatus(); const networkStatus = useNetworkStatus(); const location = useLocation(); const { toast } = useToast(); const forum = useForum(); // 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 enhanced 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 = () => { if (!isConnected) return 'Connect Wallet'; if (verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED) { return delegationInfo.isValid ? 'Ready to Post' : 'Delegation Expired'; } else if (verificationStatus === EVerificationStatus.WALLET_CONNECTED) { return 'Verified (Read-only)'; } else { return 'Verify Wallet'; } }; const getStatusColor = () => { if (!isConnected) return 'text-red-400'; if ( verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED && delegationInfo.isValid ) { return 'text-green-400'; } else if (verificationStatus === EVerificationStatus.WALLET_CONNECTED) { return 'text-yellow-400'; } else if ( verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED ) { return 'text-orange-400'; } else { return 'text-red-400'; } }; const getStatusIcon = () => { if (!isConnected) return ; if ( verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED && delegationInfo.isValid ) { return ; } else if (verificationStatus === EVerificationStatus.WALLET_CONNECTED) { return ; } else if ( verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED ) { return ; } else { return ; } }; return ( {/* Logo and Navigation */} opchan Home Cells {isConnected && ( Profile )} {/* Right side - Status and User */} {/* Network Status */} {networkStatus.getStatusMessage()} {forum.lastSync && ( Last updated{' '} {new Date(forum.lastSync).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit', })} {forum.isSyncing ? ' • syncing…' : ''} )} {/* User Status */} {isConnected ? ( {getStatusIcon()} {displayName} {getAccountStatusText()} Address: {address?.slice(0, 8)}... Status: {getAccountStatusText()} {delegationInfo.timeRemaining && ( Delegation: {delegationInfo.timeRemaining} remaining )} ) : ( Connect Wallet )} {/* Wallet Wizard */} { setWalletWizardOpen(false); toast({ title: 'Setup Complete', description: 'Your wallet is ready to use!', }); }} /> ); }; export default Header;