import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' 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, } from '../../../../helpers/constants/routes' import { exportAsFile } from '../../../../helpers/utils/util' import { returnToOnboardingInitiator } from '../../onboarding-initiator-util' export default class RevealSeedPhrase extends PureComponent { static contextTypes = { t: PropTypes.func, metricsEvent: 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.metricsEvent({ eventOpts: { category: 'Onboarding', action: 'Seed Phrase Setup', name: 'Advance to Verify', }, }) if (!isShowingSeedPhrase) { return } history.push(INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE) } handleSkip = async () => { const { history, setSeedPhraseBackedUp, setCompletedOnboarding, onboardingInitiator, } = this.props this.context.metricsEvent({ eventOpts: { category: 'Onboarding', action: 'Seed Phrase Setup', name: 'Remind me later', }, }) await Promise.all([setCompletedOnboarding(), setSeedPhraseBackedUp(false)]) if (onboardingInitiator) { await returnToOnboardingInitiator(onboardingInitiator) } history.push(DEFAULT_ROUTE) } renderSecretWordsContainer() { const { t } = this.context const { seedPhrase } = this.props const { isShowingSeedPhrase } = this.state return (
{seedPhrase}
{!isShowingSeedPhrase && (
{ this.context.metricsEvent({ eventOpts: { category: 'Onboarding', action: 'Seed Phrase Setup', name: 'Revealed Words', }, }) this.setState({ isShowingSeedPhrase: true }) }} >
{t('clickToRevealSeed')}
)}
) } render() { const { t } = this.context const { isShowingSeedPhrase } = this.state const { onboardingInitiator } = this.props return (
{t('secretBackupPhrase')}
{t('secretBackupPhraseDescription')}
{t('secretBackupPhraseWarning')}
{this.renderSecretWordsContainer()}
{`${t('tips')}:`}
{t('storePhrase')}
{t('writePhrase')}
{t('memorizePhrase')}
{t('downloadSecretBackup')}
{onboardingInitiator ? ( ) : null}
) } }