1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/pages/onboarding-flow/recovery-phrase/review-recovery-phrase.js
Elliot Winkler 1304ec7af5
Convert shared/constants/metametrics to TS (#18353)
We want to convert NetworkController to TypeScript in order to be able
to compare differences in the controller between in this repo and the
core repo. To do this, however, we need to convert the dependencies of
the controller to TypeScript.

As a part of this effort, this commit converts
`shared/constants/metametrics` to TypeScript. Note that simple objects
have been largely replaced with enums. There are some cases where I even
split up some of these objects into multiple enums.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2023-04-03 09:31:04 -06:00

179 lines
6.0 KiB
JavaScript

import React, { useState, useContext } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
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';
import { ONBOARDING_CONFIRM_SRP_ROUTE } from '../../../helpers/constants/routes';
import {
TEXT_ALIGN,
TypographyVariant,
JustifyContent,
FONT_WEIGHT,
IconColor,
} from '../../../helpers/constants/design-system';
import {
ThreeStepProgressBar,
threeStepStages,
} from '../../../components/app/step-progress-bar';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import { Icon, ICON_NAMES } from '../../../components/component-library';
import RecoveryPhraseChips from './recovery-phrase-chips';
export default function RecoveryPhrase({ secretRecoveryPhrase }) {
const history = useHistory();
const t = useI18nContext();
const { search } = useLocation();
const [copied, handleCopy] = useCopyToClipboard();
const [phraseRevealed, setPhraseRevealed] = useState(false);
const [hiddenPhrase, setHiddenPhrase] = useState(false);
const searchParams = new URLSearchParams(search);
const isFromReminderParam = searchParams.get('isFromReminder')
? '/?isFromReminder=true'
: '';
const trackEvent = useContext(MetaMetricsContext);
return (
<div className="recovery-phrase" data-testid="recovery-phrase">
<ThreeStepProgressBar stage={threeStepStages.RECOVERY_PHRASE_REVIEW} />
<Box
justifyContent={JustifyContent.center}
textAlign={TEXT_ALIGN.CENTER}
marginBottom={4}
>
<Typography
variant={TypographyVariant.H2}
fontWeight={FONT_WEIGHT.BOLD}
className="recovery-phrase__header"
>
{t('seedPhraseWriteDownHeader')}
</Typography>
</Box>
<Box
justifyContent={JustifyContent.center}
textAlign={TEXT_ALIGN.CENTER}
marginBottom={4}
>
<Typography variant={TypographyVariant.H4}>
{t('seedPhraseWriteDownDetails')}
</Typography>
</Box>
<Box
textAlign={TEXT_ALIGN.LEFT}
marginBottom={4}
className="recovery-phrase__tips"
>
<Typography
variant={TypographyVariant.H4}
fontWeight={FONT_WEIGHT.BOLD}
>
{t('tips')}:
</Typography>
<ul>
<li>
<Typography variant={TypographyVariant.H4}>
{t('seedPhraseIntroSidebarBulletOne')}
</Typography>
</li>
<li>
<Typography variant={TypographyVariant.H4}>
{t('seedPhraseIntroSidebarBulletThree')}
</Typography>
</li>
<li>
<Typography variant={TypographyVariant.H4}>
{t('seedPhraseIntroSidebarBulletFour')}
</Typography>
</li>
</ul>
</Box>
<RecoveryPhraseChips
secretRecoveryPhrase={secretRecoveryPhrase.split(' ')}
phraseRevealed={phraseRevealed && !hiddenPhrase}
hiddenPhrase={hiddenPhrase}
/>
<div className="recovery-phrase__footer">
{phraseRevealed ? (
<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'}`}
color="var(--color-primary-default)"
/>
}
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);
}}
icon={
<Icon
name={copied ? ICON_NAMES.COPY_SUCCESS : ICON_NAMES.COPY}
color={IconColor.primaryDefault}
/>
}
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>
<Button
data-testid="recovery-phrase-next"
type="primary"
className="recovery-phrase__footer--button"
onClick={() => {
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event:
MetaMetricsEventName.OnboardingWalletSecurityPhraseWrittenDown,
});
history.push(
`${ONBOARDING_CONFIRM_SRP_ROUTE}${isFromReminderParam}`,
);
}}
>
{t('next')}
</Button>
</div>
) : (
<Button
data-testid="recovery-phrase-reveal"
type="primary"
className="recovery-phrase__footer--button"
onClick={() => {
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event:
MetaMetricsEventName.OnboardingWalletSecurityPhraseRevealed,
});
setPhraseRevealed(true);
}}
>
{t('revealSeedWords')}
</Button>
)}
</div>
</div>
);
}
RecoveryPhrase.propTypes = {
secretRecoveryPhrase: PropTypes.string,
};