/** * Wallet Import Component * Import existing wallet with seed phrase */ import { useState } from 'react'; import { Eye, EyeOff, ArrowLeft, ArrowRight, Check, AlertTriangle } from 'lucide-react'; import { useWallet } from '@/contexts/WalletContext'; import { useTelegram } from '@/hooks/useTelegram'; import { validatePassword } from '@/lib/crypto'; interface Props { onComplete: () => void; onBack: () => void; } export function WalletImport({ onComplete, onBack }: Props) { const { importWallet } = useWallet(); const { hapticImpact, hapticNotification } = useTelegram(); const [mnemonic, setMnemonic] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); // Password strength validation rules (must match crypto.ts validatePassword) const passwordRules = { minLength: password.length >= 12, hasLowercase: /[a-z]/.test(password), hasUppercase: /[A-Z]/.test(password), hasNumber: /[0-9]/.test(password), hasSpecialChar: /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password), passwordsMatch: password === confirmPassword && password.length > 0, }; const allPasswordRulesPass = passwordRules.minLength && passwordRules.hasLowercase && passwordRules.hasUppercase && passwordRules.hasNumber && passwordRules.hasSpecialChar && passwordRules.passwordsMatch; const handleImport = async () => { setError(''); // Validate mnemonic const words = mnemonic.trim().split(/\s+/); if (words.length !== 12 && words.length !== 24) { setError('Seed phrase divê 12 an 24 peyv be'); return; } // Validate password using crypto.ts rules const passwordValidation = validatePassword(password); if (!passwordValidation.valid) { setError(passwordValidation.message || 'Şîfre (password) ne derbasdar e'); return; } if (password !== confirmPassword) { setError('Şîfre (password) hev nagirin'); return; } setIsLoading(true); hapticImpact('medium'); try { await importWallet(mnemonic.trim().toLowerCase(), password); hapticNotification('success'); onComplete(); } catch (err) { setError(err instanceof Error ? err.message : 'Import neserketî'); hapticNotification('error'); } finally { setIsLoading(false); } }; return (
Seed phrase'ê wallet'ê xwe yê heyî binivîse
Şertên Şîfre (Password):