/** * Wallet Connect Component * Unlock wallet with password */ import { useState } from 'react'; import { Eye, EyeOff, Wallet, Unlock, Trash2 } from 'lucide-react'; import { useWallet } from '@/contexts/WalletContext'; import { useTelegram } from '@/hooks/useTelegram'; import { formatAddress } from '@/lib/wallet-service'; import { useTranslation } from '@/i18n'; interface Props { onConnected: () => void; onDelete: () => void; } export function WalletConnect({ onConnected, onDelete }: Props) { const { address, connect, error: walletError } = useWallet(); const { hapticImpact, hapticNotification } = useTelegram(); const { t } = useTranslation(); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const handleConnect = async () => { if (!password) { setError(t('walletConnect.enterPassword')); return; } setIsLoading(true); setError(''); hapticImpact('medium'); try { await connect(password); hapticNotification('success'); onConnected(); } catch (err) { setError(err instanceof Error ? err.message : t('walletConnect.wrongPassword')); hapticNotification('error'); } finally { setIsLoading(false); } }; const handleDelete = () => { hapticImpact('heavy'); onDelete(); }; if (showDeleteConfirm) { return (

{t('walletConnect.deleteTitle')}

{t('walletConnect.deleteDescription')}

); } return (

{t('walletConnect.openWallet')}

{address && (

{formatAddress(address)}

)}
setPassword(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleConnect()} className="w-full px-4 py-3 bg-muted rounded-xl pr-12" placeholder={t('walletConnect.passwordPlaceholder')} autoFocus />
{(error || walletError) && (
{error || walletError}
)}
); }