import { useState } from 'react'; import { Wallet, Plus, Trash2, Zap, Globe, WalletMinimal, CheckCircle, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger, DrawerClose, } from '@/components/ui/drawer'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Badge } from '@/components/ui/badge'; import { Separator } from '@/components/ui/separator'; import { useNWC } from '@/hooks/useNWCContext'; import { useWallet } from '@/hooks/useWallet'; import { useToast } from '@/hooks/useToast'; import { useIsMobile } from '@/hooks/useIsMobile'; interface WalletModalProps { children?: React.ReactNode; className?: string; } export function WalletModal({ children, className }: WalletModalProps) { const [open, setOpen] = useState(false); const [addDialogOpen, setAddDialogOpen] = useState(false); const [connectionUri, setConnectionUri] = useState(''); const [alias, setAlias] = useState(''); const [isConnecting, setIsConnecting] = useState(false); const isMobile = useIsMobile(); const { connections, activeConnection, connectionInfo, addConnection, removeConnection, setActiveConnection } = useNWC(); const { hasWebLN, isDetecting } = useWallet(); // Calculate hasNWC directly from connections to ensure reactivity const hasNWC = connections.length > 0 && connections.some(c => c.isConnected); const { toast } = useToast(); const handleAddConnection = async () => { if (!connectionUri.trim()) { toast({ title: 'Connection URI required', description: 'Please enter a valid NWC connection URI.', variant: 'destructive', }); return; } setIsConnecting(true); try { const success = await addConnection(connectionUri.trim(), alias.trim() || undefined); if (success) { setConnectionUri(''); setAlias(''); setAddDialogOpen(false); } } finally { setIsConnecting(false); } }; const handleRemoveConnection = (connectionString: string) => { removeConnection(connectionString); }; const handleSetActive = (connectionString: string) => { setActiveConnection(connectionString); toast({ title: 'Active wallet changed', description: 'The selected wallet is now active for zaps.', }); }; // Shared content component const WalletContent = () => (
WebLN
Browser extension
Nostr Wallet Connect
{connections.length > 0 ? `${connections.length} wallet${connections.length !== 1 ? 's' : ''} connected` : "Remote wallet connection" }
No wallets connected
{connection.alias || info?.alias || 'Lightning Wallet'}
NWC Connection
Install a WebLN extension or connect a NWC wallet for zaps.