import React, { useState, useEffect } from 'react'; import { View, Text, StyleSheet, Pressable, Alert, } from 'react-native'; import { useBiometricAuth } from '../contexts/BiometricAuthContext'; import { AppColors, KurdistanColors } from '../theme/colors'; import { Button, Input } from '../components'; /** * Lock Screen * Shown when app is locked - requires biometric or PIN * * PRIVACY: All authentication happens locally */ export default function LockScreen() { const { isBiometricSupported, isBiometricEnrolled, isBiometricEnabled, biometricType, authenticate, verifyPinCode, } = useBiometricAuth(); const [showPinInput, setShowPinInput] = useState(false); const [pin, setPin] = useState(''); const [verifying, setVerifying] = useState(false); const handleBiometricAuth = React.useCallback(async () => { const success = await authenticate(); if (!success) { // Biometric failed, show PIN option setShowPinInput(true); } }, [authenticate]); useEffect(() => { // Auto-trigger biometric on mount if enabled if (isBiometricEnabled && isBiometricSupported && isBiometricEnrolled) { handleBiometricAuth(); } }, [isBiometricEnabled, isBiometricSupported, isBiometricEnrolled, handleBiometricAuth]); const handlePinSubmit = async () => { if (!pin || pin.length < 4) { Alert.alert('Error', 'Please enter your PIN'); return; } try { setVerifying(true); const success = await verifyPinCode(pin); if (!success) { Alert.alert('Error', 'Incorrect PIN. Please try again.'); setPin(''); } } catch { Alert.alert('Error', 'Failed to verify PIN'); } finally { setVerifying(false); } }; const getBiometricIcon = () => { switch (biometricType) { case 'facial': return '😊'; case 'fingerprint': return '👆'; case 'iris': return '👁️'; default: return '🔒'; } }; const getBiometricLabel = () => { switch (biometricType) { case 'facial': return 'Face ID'; case 'fingerprint': return 'Fingerprint'; case 'iris': return 'Iris'; default: return 'Biometric'; } }; return ( {/* Logo */} 🌟 PezkuwiChain Digital Kurdistan {/* Lock Icon */} 🔒 {/* Title */} App Locked Authenticate to unlock and access your wallet {/* Biometric or PIN */} {!showPinInput ? ( // Biometric Button isBiometricEnabled && isBiometricSupported && isBiometricEnrolled ? ( {getBiometricIcon()} Tap to use {getBiometricLabel()} setShowPinInput(true)} style={styles.usePinButton} > Use PIN instead ) : ( // No biometric, show PIN immediately Biometric authentication not available