"use client" import { useState } from "react" import { Wallet, HelpCircle, Check, AlertTriangle, Loader2 } from "lucide-react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { useWalletStore } from "@/lib/wallet-store" import { cn } from "@/lib/utils" const walletOptions = [ { id: "metamask", name: "MetaMask", icon: "/images/wallets/metamask.svg", description: "Connect to your MetaMask wallet", popular: true, verifiesAutomatically: false }, { id: "walletconnect", name: "WalletConnect", icon: "/images/wallets/walletconnect.svg", description: "Connect using WalletConnect", popular: true, verifiesAutomatically: false }, { id: "coinbase", name: "Coinbase Wallet", icon: "/images/wallets/coinbase.svg", description: "Connect to your Coinbase wallet", popular: false, verifiesAutomatically: false }, { id: "privadoid", name: "Privado ID", icon: "/images/wallets/privado.svg", description: "Connect with automatic identity verification", popular: true, verifiesAutomatically: true } ] export function WalletConnectionModal() { const { walletConnected, connectWallet } = useWalletStore() const [isOpen, setIsOpen] = useState(false) const [selectedWallet, setSelectedWallet] = useState(null) const [connectionState, setConnectionState] = useState<"idle" | "connecting" | "success" | "error">("idle") const [errorMessage, setErrorMessage] = useState("") const handleWalletSelect = (walletId: string) => { setSelectedWallet(walletId) } const handleConnect = async () => { if (!selectedWallet) return setConnectionState("connecting") setErrorMessage("") try { // This would connect to the actual wallet in production await new Promise(resolve => setTimeout(resolve, 2000)) // Simulate connection delay // Simulate success or failure (in production, would use actual wallet connection) const success = Math.random() > 0.2 // 80% success rate for demo if (success) { // Check if the selected wallet provides automatic verification const selectedWalletDetails = walletOptions.find(w => w.id === selectedWallet); const isVerified = selectedWalletDetails?.verifiesAutomatically || false; // Connect the wallet and update verification status connectWallet(undefined, undefined, isVerified); setConnectionState("success") setTimeout(() => { setIsOpen(false) setConnectionState("idle") setSelectedWallet(null) }, 1500) } else { throw new Error("Could not connect to wallet. Please try again.") } } catch (error) { console.error("Wallet connection error:", error) setConnectionState("error") setErrorMessage(error instanceof Error ? error.message : "An unknown error occurred") } } const closeAndReset = () => { setIsOpen(false) setTimeout(() => { setConnectionState("idle") setSelectedWallet(null) setErrorMessage("") }, 300) } return ( Connect your wallet Select a wallet to connect and authenticate with the platform. Privado ID provides automatic identity verification. {connectionState === "success" ? (

Connected Successfully

Your wallet is now connected

{selectedWallet === "privadoid" && (
Identity verified automatically
)} {selectedWallet && selectedWallet !== "privadoid" && (

Your wallet is connected but your identity is not verified.

)}
) : connectionState === "error" ? (

Connection Failed

{errorMessage}

) : ( <>

Popular Wallets

{walletOptions.filter(w => w.popular).map((wallet) => (
handleWalletSelect(wallet.id)} >
{wallet.name} { const target = e.target as HTMLImageElement; target.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='6' width='20' height='12' rx='2'/%3E%3Cpath d='M22 10H18a2 2 0 0 0-2 2v0a2 2 0 0 0 2 2h4'/%3E%3C/svg%3E"; }} />

{wallet.name}

{wallet.verifiesAutomatically && ( Verifies Identity )}

{wallet.description}

{selectedWallet === wallet.id && }
))}

Other Wallets

{walletOptions.filter(w => !w.popular).map((wallet) => (
handleWalletSelect(wallet.id)} >
{wallet.name} { const target = e.target as HTMLImageElement; target.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='6' width='20' height='12' rx='2'/%3E%3Cpath d='M22 10H18a2 2 0 0 0-2 2v0a2 2 0 0 0 2 2h4'/%3E%3C/svg%3E"; }} />

{wallet.name}

{wallet.description}

{selectedWallet === wallet.id && }
))}
)}
) }