2023-01-13 17:11:27 +01:00
|
|
|
import React, { useState, useContext } from 'react';
|
2023-01-06 07:14:32 +01:00
|
|
|
import { useHistory, useLocation } from 'react-router-dom';
|
2021-07-08 02:10:12 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Box from '../../../components/ui/box';
|
|
|
|
import Button from '../../../components/ui/button';
|
|
|
|
import Typography from '../../../components/ui/typography';
|
|
|
|
import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2021-10-14 19:46:43 +02:00
|
|
|
import { ONBOARDING_CONFIRM_SRP_ROUTE } from '../../../helpers/constants/routes';
|
2021-07-08 02:10:12 +02:00
|
|
|
import {
|
|
|
|
TEXT_ALIGN,
|
2023-02-02 21:15:26 +01:00
|
|
|
TypographyVariant,
|
|
|
|
JustifyContent,
|
2021-07-08 02:10:12 +02:00
|
|
|
FONT_WEIGHT,
|
2023-02-02 21:15:26 +01:00
|
|
|
IconColor,
|
2021-07-08 02:10:12 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
2021-10-13 19:41:24 +02:00
|
|
|
import {
|
|
|
|
ThreeStepProgressBar,
|
|
|
|
threeStepStages,
|
|
|
|
} from '../../../components/app/step-progress-bar';
|
2023-04-03 17:31:04 +02:00
|
|
|
import {
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventName,
|
|
|
|
} from '../../../../shared/constants/metametrics';
|
2023-01-13 17:11:27 +01:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2023-04-24 16:19:19 +02:00
|
|
|
import { Icon, IconName } from '../../../components/component-library';
|
2021-07-08 02:10:12 +02:00
|
|
|
import RecoveryPhraseChips from './recovery-phrase-chips';
|
|
|
|
|
2021-10-13 19:41:24 +02:00
|
|
|
export default function RecoveryPhrase({ secretRecoveryPhrase }) {
|
2021-07-08 02:10:12 +02:00
|
|
|
const history = useHistory();
|
|
|
|
const t = useI18nContext();
|
2023-01-06 07:14:32 +01:00
|
|
|
const { search } = useLocation();
|
2021-07-08 02:10:12 +02:00
|
|
|
const [copied, handleCopy] = useCopyToClipboard();
|
2021-10-13 19:41:24 +02:00
|
|
|
const [phraseRevealed, setPhraseRevealed] = useState(false);
|
2022-03-08 16:38:07 +01:00
|
|
|
const [hiddenPhrase, setHiddenPhrase] = useState(false);
|
2023-01-06 07:14:32 +01:00
|
|
|
const searchParams = new URLSearchParams(search);
|
|
|
|
const isFromReminderParam = searchParams.get('isFromReminder')
|
|
|
|
? '/?isFromReminder=true'
|
|
|
|
: '';
|
2023-01-13 17:11:27 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2022-03-08 16:38:07 +01:00
|
|
|
|
2021-07-08 02:10:12 +02:00
|
|
|
return (
|
2022-08-31 01:53:24 +02:00
|
|
|
<div className="recovery-phrase" data-testid="recovery-phrase">
|
2021-10-13 19:41:24 +02:00
|
|
|
<ThreeStepProgressBar stage={threeStepStages.RECOVERY_PHRASE_REVIEW} />
|
2021-07-08 02:10:12 +02:00
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2021-07-08 02:10:12 +02:00
|
|
|
textAlign={TEXT_ALIGN.CENTER}
|
|
|
|
marginBottom={4}
|
|
|
|
>
|
2022-05-16 20:38:04 +02:00
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H2}
|
2022-05-16 20:38:04 +02:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
className="recovery-phrase__header"
|
|
|
|
>
|
2021-07-08 02:10:12 +02:00
|
|
|
{t('seedPhraseWriteDownHeader')}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2021-07-08 02:10:12 +02:00
|
|
|
textAlign={TEXT_ALIGN.CENTER}
|
|
|
|
marginBottom={4}
|
|
|
|
>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H4}>
|
2021-07-08 02:10:12 +02:00
|
|
|
{t('seedPhraseWriteDownDetails')}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
textAlign={TEXT_ALIGN.LEFT}
|
|
|
|
marginBottom={4}
|
|
|
|
className="recovery-phrase__tips"
|
|
|
|
>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography
|
|
|
|
variant={TypographyVariant.H4}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
2021-07-08 02:10:12 +02:00
|
|
|
{t('tips')}:
|
|
|
|
</Typography>
|
|
|
|
<ul>
|
|
|
|
<li>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H4}>
|
2022-03-08 16:38:07 +01:00
|
|
|
{t('seedPhraseIntroSidebarBulletOne')}
|
2021-07-08 02:10:12 +02:00
|
|
|
</Typography>
|
|
|
|
</li>
|
|
|
|
<li>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H4}>
|
2021-07-08 02:10:12 +02:00
|
|
|
{t('seedPhraseIntroSidebarBulletThree')}
|
|
|
|
</Typography>
|
|
|
|
</li>
|
|
|
|
<li>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H4}>
|
2021-07-08 02:10:12 +02:00
|
|
|
{t('seedPhraseIntroSidebarBulletFour')}
|
|
|
|
</Typography>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</Box>
|
|
|
|
<RecoveryPhraseChips
|
2021-10-13 19:41:24 +02:00
|
|
|
secretRecoveryPhrase={secretRecoveryPhrase.split(' ')}
|
2022-03-08 16:38:07 +01:00
|
|
|
phraseRevealed={phraseRevealed && !hiddenPhrase}
|
|
|
|
hiddenPhrase={hiddenPhrase}
|
2021-07-08 02:10:12 +02:00
|
|
|
/>
|
|
|
|
<div className="recovery-phrase__footer">
|
2021-10-13 19:41:24 +02:00
|
|
|
{phraseRevealed ? (
|
2022-03-08 16:38:07 +01:00
|
|
|
<div className="recovery-phrase__footer__copy-and-hide">
|
|
|
|
<div className="recovery-phrase__footer__copy-and-hide__area">
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
icon={
|
|
|
|
<i
|
|
|
|
className={`far fa-eye${hiddenPhrase ? '' : '-slash'}`}
|
2022-03-25 23:15:31 +01:00
|
|
|
color="var(--color-primary-default)"
|
2022-03-08 16:38:07 +01:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
className="recovery-phrase__footer__copy-and-hide__button recovery-phrase__footer__copy-and-hide__button__hide-seed"
|
|
|
|
onClick={() => {
|
|
|
|
setHiddenPhrase(!hiddenPhrase);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{hiddenPhrase ? t('revealTheSeedPhrase') : t('hideSeedPhrase')}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
handleCopy(secretRecoveryPhrase);
|
|
|
|
}}
|
2022-03-25 23:15:31 +01:00
|
|
|
icon={
|
2023-01-31 18:00:26 +01:00
|
|
|
<Icon
|
2023-04-24 16:19:19 +02:00
|
|
|
name={copied ? IconName.CopySuccess : IconName.Copy}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={IconColor.primaryDefault}
|
2023-01-31 18:00:26 +01:00
|
|
|
/>
|
2022-03-25 23:15:31 +01:00
|
|
|
}
|
2022-03-08 16:38:07 +01:00
|
|
|
className="recovery-phrase__footer__copy-and-hide__button recovery-phrase__footer__copy-and-hide__button__copy-to-clipboard"
|
|
|
|
type="link"
|
|
|
|
>
|
|
|
|
{copied ? t('copiedExclamation') : t('copyToClipboard')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2021-07-08 02:10:12 +02:00
|
|
|
<Button
|
2021-11-10 18:27:10 +01:00
|
|
|
data-testid="recovery-phrase-next"
|
2021-07-08 02:10:12 +02:00
|
|
|
type="primary"
|
|
|
|
className="recovery-phrase__footer--button"
|
|
|
|
onClick={() => {
|
2023-01-13 17:11:27 +01:00
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Onboarding,
|
2023-01-13 17:11:27 +01:00
|
|
|
event:
|
2023-04-03 17:31:04 +02:00
|
|
|
MetaMetricsEventName.OnboardingWalletSecurityPhraseWrittenDown,
|
2023-01-13 17:11:27 +01:00
|
|
|
});
|
2023-01-06 07:14:32 +01:00
|
|
|
history.push(
|
|
|
|
`${ONBOARDING_CONFIRM_SRP_ROUTE}${isFromReminderParam}`,
|
|
|
|
);
|
2021-07-08 02:10:12 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('next')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Button
|
2021-11-10 18:27:10 +01:00
|
|
|
data-testid="recovery-phrase-reveal"
|
2021-07-08 02:10:12 +02:00
|
|
|
type="primary"
|
|
|
|
className="recovery-phrase__footer--button"
|
|
|
|
onClick={() => {
|
2023-01-13 17:11:27 +01:00
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
|
|
event:
|
|
|
|
MetaMetricsEventName.OnboardingWalletSecurityPhraseRevealed,
|
2023-01-13 17:11:27 +01:00
|
|
|
});
|
2021-10-13 19:41:24 +02:00
|
|
|
setPhraseRevealed(true);
|
2021-07-08 02:10:12 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('revealSeedWords')}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
RecoveryPhrase.propTypes = {
|
2021-10-13 19:41:24 +02:00
|
|
|
secretRecoveryPhrase: PropTypes.string,
|
2021-07-08 02:10:12 +02:00
|
|
|
};
|