import React, { useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useAuth, useNetworkStatus } from '@/hooks'; import { Button } from '@/components/ui/button'; import { LogOut, Terminal, AlertTriangle, CheckCircle, Key, 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 { useUserDisplay } from '@/hooks'; const Header = () => { const { verificationStatus, delegationInfo } = useAuth(); const networkStatus = useNetworkStatus(); 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 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.level === 'verified-owner') { return delegationInfo.isActive ? 'Ready to Post' : 'Delegation Expired'; } else if (verificationStatus.level === 'verified-basic') { return 'Verified (Read-only)'; } else if (verificationStatus.level === 'unverified') { return verificationStatus.hasOrdinal ? 'Verify Wallet' : 'No Ordinals Found'; } else { return 'Verify Wallet'; } }; const getStatusColor = () => { if (!isConnected) return 'text-red-400'; if ( verificationStatus.level === 'verified-owner' && delegationInfo.isActive ) { return 'text-green-400'; } else if (verificationStatus.level === 'verified-basic') { return 'text-yellow-400'; } else if (verificationStatus.hasOrdinal || verificationStatus.hasENS) { return 'text-orange-400'; } else { return 'text-red-400'; } }; const getStatusIcon = () => { if (!isConnected) return ; if ( verificationStatus.level === 'verified-owner' && delegationInfo.isActive ) { return ; } else if (verificationStatus.level === 'verified-basic') { return ; } else if (verificationStatus.hasOrdinal || verificationStatus.hasENS) { return ; } else { return ; } }; return (
{/* Logo and Navigation */}
opchan
{/* Right side - Status and User */}
{/* Network Status */}
{networkStatus.getStatusMessage()}
{/* User Status */} {isConnected ? (
{getStatusIcon()}
{displayName}
{getAccountStatusText()}
Address: {address?.slice(0, 8)}...
Status: {getAccountStatusText()}
{delegationInfo.timeRemaining && (
Delegation: {delegationInfo.timeRemaining} remaining
)}
) : ( )}
{/* Wallet Wizard */} { setWalletWizardOpen(false); toast({ title: 'Setup Complete', description: 'Your wallet is ready to use!', }); }} />
); }; export default Header;