import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import Box from '../../../../components/ui/box'; import LockIcon from '../../../../components/ui/lock-icon'; import Button from '../../../../components/ui/button'; import Snackbar from '../../../../components/ui/snackbar'; import { INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE, DEFAULT_ROUTE, INITIALIZE_SEED_PHRASE_INTRO_ROUTE, } from '../../../../helpers/constants/routes'; import { EVENT, EVENT_NAMES, } from '../../../../../shared/constants/metametrics'; import { returnToOnboardingInitiatorTab } from '../../onboarding-initiator-util'; import { exportAsFile } from '../../../../../shared/modules/export-utils'; export default class RevealSeedPhrase extends PureComponent { static contextTypes = { t: PropTypes.func, trackEvent: PropTypes.func, }; static propTypes = { history: PropTypes.object, seedPhrase: PropTypes.string, setSeedPhraseBackedUp: PropTypes.func, setCompletedOnboarding: PropTypes.func, onboardingInitiator: PropTypes.exact({ location: PropTypes.string, tabId: PropTypes.number, }), }; state = { isShowingSeedPhrase: false, }; handleExport = () => { exportAsFile('', this.props.seedPhrase, 'text/plain'); }; handleNext = () => { const { isShowingSeedPhrase } = this.state; const { history } = this.props; this.context.trackEvent({ category: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.SRP_TO_CONFIRM_BACKUP, properties: {}, }); if (!isShowingSeedPhrase) { return; } history.replace(INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE); }; handleSkip = async () => { const { history, setSeedPhraseBackedUp, setCompletedOnboarding, onboardingInitiator, } = this.props; await Promise.all([setCompletedOnboarding(), setSeedPhraseBackedUp(false)]) .then(() => { this.context.trackEvent({ category: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.WALLET_CREATED, properties: { account_type: EVENT.ACCOUNT_TYPES.DEFAULT, is_backup_skipped: true, }, }); }) .catch((error) => { console.error(error.message); this.context.trackEvent({ category: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.WALLET_SETUP_FAILED, properties: { account_type: EVENT.ACCOUNT_TYPES.DEFAULT, is_backup_skipped: true, reason: 'Seed Phrase Creation Error', error: error.message, }, }); }); if (onboardingInitiator) { await returnToOnboardingInitiatorTab(onboardingInitiator); } history.replace(DEFAULT_ROUTE); }; renderSecretWordsContainer() { const { t } = this.context; const { seedPhrase } = this.props; const { isShowingSeedPhrase } = this.state; return (
{seedPhrase}
{!isShowingSeedPhrase && (
{ this.context.trackEvent({ category: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.KEY_EXPORT_REVEALED, properties: {}, }); this.setState({ isShowingSeedPhrase: true }); }} >
{t('clickToRevealSeed')}
)}
); } render() { const { t } = this.context; const { isShowingSeedPhrase } = this.state; const { history, onboardingInitiator } = this.props; return (
{ e.preventDefault(); history.push(INITIALIZE_SEED_PHRASE_INTRO_ROUTE); }} > {`< ${t('back')}`}
{t('secretRecoveryPhrase')}
{t('secretBackupPhraseDescription')}
{t('secretBackupPhraseWarning')}
{this.renderSecretWordsContainer()}
{`${t('tips')}:`}
{t('storePhrase')}
{t('writePhrase')}
{t('memorizePhrase')}
{t('downloadSecretBackup')}
{onboardingInitiator ? ( ) : null}
); } }