1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/ui/pages/onboarding-flow/recovery-phrase/confirm-recovery-phrase.js
dragana8 d01a2ad7e5
Overall CSS #13441 (#13902)
* styling updates

Co-authored-by: Alex Donesky <adonesky@gmail.com>
Co-authored-by: George Marshall <george.marshall@consensys.net>
Co-authored-by: David Walsh <davidwalsh83@gmail.com>
2022-05-16 13:38:04 -05:00

108 lines
3.2 KiB
JavaScript

import React, { useState, useMemo } from 'react';
import { useHistory } from 'react-router-dom';
import { debounce } from 'lodash';
import PropTypes from 'prop-types';
import Box from '../../../components/ui/box';
import Button from '../../../components/ui/button';
import Typography from '../../../components/ui/typography';
import {
TEXT_ALIGN,
TYPOGRAPHY,
JUSTIFY_CONTENT,
FONT_WEIGHT,
} from '../../../helpers/constants/design-system';
import {
ThreeStepProgressBar,
threeStepStages,
} from '../../../components/app/step-progress-bar';
import { ONBOARDING_COMPLETION_ROUTE } from '../../../helpers/constants/routes';
import { useI18nContext } from '../../../hooks/useI18nContext';
import RecoveryPhraseChips from './recovery-phrase-chips';
export default function ConfirmRecoveryPhrase({ secretRecoveryPhrase = '' }) {
const history = useHistory();
const t = useI18nContext();
const splitSecretRecoveryPhrase = secretRecoveryPhrase.split(' ');
const indicesToCheck = [2, 3, 7];
const [matching, setMatching] = useState(false);
// Removes seed phrase words from chips corresponding to the
// indicesToCheck so that user has to complete the phrase and confirm
// they have saved it.
const initializePhraseElements = () => {
const phraseElements = { ...splitSecretRecoveryPhrase };
indicesToCheck.forEach((i) => {
phraseElements[i] = '';
});
return phraseElements;
};
const [phraseElements, setPhraseElements] = useState(
initializePhraseElements(),
);
const validate = useMemo(
() =>
debounce((elements) => {
setMatching(Object.values(elements).join(' ') === secretRecoveryPhrase);
}, 500),
[setMatching, secretRecoveryPhrase],
);
const handleSetPhraseElements = (values) => {
setPhraseElements(values);
validate(values);
};
return (
<div className="recovery-phrase__confirm">
<ThreeStepProgressBar
stage={threeStepStages.RECOVERY_PHRASE_CONFIRM}
marginBottom={4}
/>
<Box
justifyContent={JUSTIFY_CONTENT.CENTER}
textAlign={TEXT_ALIGN.CENTER}
marginBottom={4}
>
<Typography variant={TYPOGRAPHY.H2} fontWeight={FONT_WEIGHT.BOLD}>
{t('seedPhraseConfirm')}
</Typography>
</Box>
<Box
justifyContent={JUSTIFY_CONTENT.CENTER}
textAlign={TEXT_ALIGN.CENTER}
marginBottom={4}
>
<Typography variant={TYPOGRAPHY.H4}>
{t('seedPhraseEnterMissingWords')}
</Typography>
</Box>
<RecoveryPhraseChips
secretRecoveryPhrase={splitSecretRecoveryPhrase}
confirmPhase
setInputValue={handleSetPhraseElements}
inputValue={phraseElements}
indicesToCheck={indicesToCheck}
/>
<div className="recovery-phrase__footer__confirm">
<Button
data-testid="recovery-phrase-confirm"
type="primary"
large
className="recovery-phrase__footer__confirm--button"
onClick={() => {
history.push(ONBOARDING_COMPLETION_ROUTE);
}}
disabled={!matching}
>
{t('confirm')}
</Button>
</div>
</div>
);
}
ConfirmRecoveryPhrase.propTypes = {
secretRecoveryPhrase: PropTypes.string,
};