import React, { useState } from 'react'; import { usePezkuwi } from '@/contexts/PezkuwiContext'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Wallet, Check, ExternalLink, Copy, LogOut } from 'lucide-react'; import { useToast } from '@/hooks/use-toast'; export const PezkuwiWalletButton: React.FC = () => { const { accounts, selectedAccount, setSelectedAccount, connectWallet, disconnectWallet, error } = usePezkuwi(); const [isOpen, setIsOpen] = useState(false); const { toast } = useToast(); const handleConnect = async () => { await connectWallet(); if (accounts.length > 0) { setIsOpen(true); } }; const handleSelectAccount = (account: typeof accounts[0]) => { setSelectedAccount(account); setIsOpen(false); toast({ title: "Account Connected", description: `${account.meta.name} - ${formatAddress(account.address)}`, }); }; const handleDisconnect = () => { disconnectWallet(); toast({ title: "Wallet Disconnected", description: "Your wallet has been disconnected", }); }; const formatAddress = (address: string) => { return `${address.slice(0, 6)}...${address.slice(-4)}`; }; const copyAddress = () => { if (selectedAccount) { navigator.clipboard.writeText(selectedAccount.address); toast({ title: "Address Copied", description: "Address copied to clipboard", }); } }; if (selectedAccount) { return (
Account Details Your connected Pezkuwi account
Account Name
{selectedAccount.meta.name || 'Unnamed Account'}
Address
{selectedAccount.address}
Source
{selectedAccount.meta.source || 'pezkuwi'}
{accounts.length > 1 && (
Switch Account
{accounts.map((account) => ( ))}
)}
); } return ( <> {error && error.includes('not found') && ( {}}> Install Pezkuwi Wallet Extension You need the Pezkuwi Wallet browser extension to connect

The Pezkuwi Wallet extension allows you to manage your accounts and sign transactions securely.

After installing, refresh this page and click "Connect Wallet" again.

)} 0} onOpenChange={setIsOpen}> Select Account Choose an account to connect
{accounts.map((account) => ( ))}
); };