import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Column, Text } from '../../components/ui'; import { Theme } from '../../components/ui/styleUtils'; import { Dimensions, Keyboard, KeyboardAvoidingView, TouchableWithoutFeedback, View, ModalProps } from 'react-native'; import { isIOS } from '../../shared/constants'; import { SvgImage } from '../../components/ui/svg'; import { getScreenHeight } from '../../shared/commonUtil'; import { PinInput } from '../../components/PinInput'; import { Modal } from '../../components/ui/Modal'; import { CancelDownloadModal } from './ConfirmationModal'; import { Icon, Input } from 'react-native-elements'; export const TransactionCodeModal: React.FC = props => { const { t } = useTranslation('transactionCodeScreen'); const { isSmallScreen, screenHeight } = getScreenHeight(); const [transactionCode, setTransactionCode] = useState(''); const [errorMessage, setErrorMessage] = useState(''); const [showCancelConfirm, setShowCancelConfirm] = useState(false); const [showCode, setShowCode] = useState(false); const [touched, setTouched] = useState(false); const [showFullDescription, setShowFullDescription] = useState(false); const [textLineCount, setTextLineCount] = useState(0); const maxLines = 2; const validateCode = (code: string): string => { if (!code.trim()) return t('emptyCodeError'); if (!/^[a-zA-Z0-9]+$/.test(code)) return t('invalidCharacters'); return ''; }; const handleVerify = () => { const error = validateCode(transactionCode); if (error) { setErrorMessage(error); return; } setErrorMessage(''); props.onVerify?.(transactionCode); }; const handleChange = (text: string) => { if (!touched) setTouched(true); setTransactionCode(text); let error; if (touched) error = validateCode(text); setErrorMessage(error); }; return ( <> {showCancelConfirm ? ( setShowCancelConfirm(false)} onConfirm={props.onDismiss ?? (() => { })} visible={showCancelConfirm} /> ) : ( setShowCancelConfirm(true)}> {SvgImage.OtpVerificationIcon()} {t('TransactionCode')} { if (textLineCount !== e.nativeEvent.lines.length) { setTextLineCount(e.nativeEvent.lines.length); } }} > {t( `${props.description || t('description') }`, )} {textLineCount >= maxLines && setShowFullDescription(prev => !prev)} style={Theme.TransactionCodeScreenStyle.showMoreButton} > {showFullDescription ? t('Show less ↑') : t('Show more ↓')} } {(props.error || errorMessage) && ( {errorMessage || props.error} )} {((!props.inputMode || (props.inputMode && props.inputMode === 'numeric')) && props.length && props.length <= 6) ? ( <> { const error = validateCode(code); if (error) { setErrorMessage(error); return; } setErrorMessage(''); props.onVerify?.(code); props.onDismiss?.(); }} />