import React, { useCallback } from 'react'; import { useWallet } from '@solana/wallet-adapter-react'; import { WalletMultiButton, WalletDisconnectButton } from '@solana/wallet-adapter-react-ui'; import { Button } from '@/components/ui/button'; import { Wallet, Power, AlertCircle, ExternalLink } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useToast } from '@/hooks/use-toast'; import { useWalletDetection } from '@/hooks/useWalletDetection'; interface WalletButtonProps { variant?: "default" | "hero" | "outline"; className?: string; } export const WalletButton: React.FC = ({ variant = "default", className }) => { const { connected, disconnect, publicKey, connecting, wallet, connect } = useWallet(); const { toast } = useToast(); const { isPhantomInstalled, isWalletReady } = useWalletDetection(); const handleDirectPhantomConnect = useCallback(async () => { if (typeof window === 'undefined') return; try { const windowAny = window as any; const phantom = windowAny.phantom?.solana || windowAny.solana; if (phantom?.isPhantom) { console.log('Attempting direct Phantom connection...'); const response = await phantom.connect(); console.log('Direct connection response:', response); toast({ title: "Wallet Connected", description: "Successfully connected to Phantom wallet", }); } else { throw new Error('Phantom not found'); } } catch (error) { console.error('Direct connection failed:', error); toast({ title: "Connection Failed", description: "Please make sure Phantom is installed and unlocked", variant: "destructive", }); } }, [toast]); if (connected && publicKey) { return (
{publicKey.toBase58().slice(0, 4)}...{publicKey.toBase58().slice(-4)}
Connected
); } // Show install prompt if Phantom is not detected if (!isPhantomInstalled) { return (
); } return (
{/* Standard wallet adapter button */}
} />
{/* Fallback direct connection button */} {!connected && !connecting && ( )}
); };