import React, { useState } from 'react'; import { usePolkadot } from '@/contexts/PolkadotContext'; 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 PolkadotWalletButton: React.FC = () => { const { accounts, selectedAccount, setSelectedAccount, connectWallet, disconnectWallet, error } = usePolkadot(); const [isOpen, setIsOpen] = useState(false); const [balance, setBalance] = useState('0'); 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 Polkadot account
Account Name
{selectedAccount.meta.name || 'Unnamed Account'}
Address
{selectedAccount.address}
Source
{selectedAccount.meta.source || 'polkadot-js'}
{accounts.length > 1 && (
Switch Account
{accounts.map((account) => ( ))}
)}
); } return ( <> {error && error.includes('install Polkadot.js') && ( {}}> Install Polkadot.js Extension You need the Polkadot.js browser extension to connect your wallet

The Polkadot.js 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) => ( ))}
); };