import { useAlipayStrings } from '../hooks/useAlipayStrings'; import React, { useEffect, useRef, useState } from 'react'; import { IcDelete, IcClose } from '../res/icons'; import { useAlipayGestures } from '../hooks/useAlipayGestures'; interface SimplePaymentPasswordModalProps { visible: boolean; expectedPassword?: string; onSuccess: () => void; } export const SimplePaymentPasswordModal: React.FC = ({ visible, expectedPassword = '000000', onSuccess, }) => { const s = useAlipayStrings(); const { bindTap, bindBack } = useAlipayGestures(); const [password, setPassword] = useState(''); const [error, setError] = useState(false); const calledRef = useRef(false); useEffect(() => { if (visible) { setPassword(''); setError(false); calledRef.current = false; } }, [visible]); useEffect(() => { if (password.length === 6) { if (calledRef.current) return; if (password === expectedPassword) { calledRef.current = true; setTimeout(() => { onSuccess(); }, 200); } else { setError(true); setPassword(''); } } else { if (error && password.length > 0) setError(false); } }, [password, expectedPassword, error, onSuccess]); const handleNumberClick = (num: string) => { if (password.length < 6) setPassword((prev) => prev + num); }; const handleDelete = () => { setPassword((prev) => prev.slice(0, -1)); }; if (!visible) return null; return (
{s.enter_payment_password}
{error ? {s.incorrect_payment_password} : {s.placeholder}}
{[0, 1, 2, 3, 4, 5].map((index) => (
{password.length > index &&
}
))}
{[1, 2, 3, 4, 5, 6, 7, 8, 9].map((num) => ( ))}
); };