import React, { useCallback, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import PropTypes from 'prop-types'; import { Display, FontWeight, Severity, TextVariant, } from '../../../helpers/constants/design-system'; import { BannerAlert, ButtonPrimary, ButtonSecondary, FormTextField, Box, } from '../../component-library'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { exportAccount, hideWarning } from '../../../store/actions'; export const AccountDetailsAuthenticate = ({ address, onCancel }) => { const t = useI18nContext(); const dispatch = useDispatch(); const [password, setPassword] = useState(''); // Password error would result from appState const warning = useSelector((state) => state.appState.warning); const onSubmit = useCallback(() => { dispatch(exportAccount(password, address)).then((res) => { dispatch(hideWarning()); return res; }); }, [dispatch, password, address]); const handleKeyPress = useCallback( (e) => { if (e.key === 'Enter') { onSubmit(); } }, [onSubmit], ); return ( <> setPassword(e.target.value)} value={password} variant={TextVariant.bodySm} type="password" inputProps={{ onKeyPress: handleKeyPress }} labelProps={{ fontWeight: FontWeight.Medium }} autoFocus /> {t('cancel')} {t('confirm')} ); }; AccountDetailsAuthenticate.propTypes = { address: PropTypes.string.isRequired, onCancel: PropTypes.func.isRequired, };