import React, { useState } from 'react'; import { useHistory } from 'react-router-dom'; import { ethers } from 'ethers'; import classnames from 'classnames'; import PropTypes from 'prop-types'; import { TwoStepProgressBar, twoStepStages, } from '../../../components/app/step-progress-bar'; import Box from '../../../components/ui/box'; import Button from '../../../components/ui/button'; import Typography from '../../../components/ui/typography'; import { FONT_WEIGHT, TEXT_ALIGN, TYPOGRAPHY, } from '../../../helpers/constants/design-system'; import { ONBOARDING_CREATE_PASSWORD_ROUTE } from '../../../helpers/constants/routes'; import { clearClipboard } from '../../../helpers/utils/util'; import { useI18nContext } from '../../../hooks/useI18nContext'; export default function ImportSRP({ submitSecretRecoveryPhrase }) { const [secretRecoveryPhrase, setSecretRecoveryPhrase] = useState(''); const [revealSRP, setRevealSRP] = useState(true); const [error, setError] = useState(''); const history = useHistory(); const t = useI18nContext(); const { isValidMnemonic } = ethers.utils; const parseSeedPhrase = (seedPhrase) => (seedPhrase || '').trim().toLowerCase().match(/\w+/gu)?.join(' ') || ''; const handleSecretRecoveryPhraseChange = (recoveryPhrase) => { setError(''); if (recoveryPhrase) { const parsedSecretRecoveryPhrase = parseSeedPhrase(recoveryPhrase); const wordCount = parsedSecretRecoveryPhrase.split(/\s/u).length; if (wordCount % 3 !== 0 || wordCount > 24 || wordCount < 12) { setError(t('seedPhraseReq')); } else if (!isValidMnemonic(parsedSecretRecoveryPhrase)) { setError(t('invalidSeedPhrase')); } } setSecretRecoveryPhrase(recoveryPhrase); }; return (