import { memo, useState } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import type { GlobalState } from '../../global/types'; import useLang from '../../hooks/useLang'; import useLastCallback from '../../hooks/useLastCallback'; import ConfirmDialog from '../ui/ConfirmDialog'; import PasswordForm from './PasswordForm'; import PasswordMonkey from './PasswordMonkey'; import styles from './PasswordConfirmModal.module.scss'; type OwnProps = { isOpen: boolean; title?: string; confirmLabel?: string; description?: string; onClose: NoneToVoidFunction; onSubmit: (password: string) => void; }; type StateProps = { error?: GlobalState['twoFaSettings']['errorKey']; hint?: string; isLoading?: boolean; }; const PasswordConfirmModal = ({ isOpen, title, confirmLabel, description, error, hint, isLoading, onClose, onSubmit, }: OwnProps & StateProps) => { const { checkPassword, clearTwoFaError } = getActions(); const lang = useLang(); const [shouldShowPassword, setShouldShowPassword] = useState(false); const [password, setPassword] = useState(''); const handlePasswordChange = useLastCallback((value: string) => { setPassword(value); }); const handleSubmit = useLastCallback(() => { checkPassword({ currentPassword: password, onSuccess: () => { onSubmit(password); setPassword(''); setShouldShowPassword(false); }, }); }); const handleClose = useLastCallback(() => { onClose(); clearTwoFaError(); setPassword(''); setShouldShowPassword(false); }); return ( {description &&

{description}

}
); }; export default memo(withGlobal( (global): Complete => { const { errorKey, hint, isLoading } = global.twoFaSettings; return { error: errorKey, hint, isLoading, }; }, )(PasswordConfirmModal));