2019-01-23 16:25:34 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import classnames from 'classnames'
|
2019-03-22 00:03:30 +01:00
|
|
|
import LockIcon from '../../../../components/ui/lock-icon'
|
|
|
|
import Button from '../../../../components/ui/button'
|
2019-11-22 18:03:51 +01:00
|
|
|
import Snackbar from '../../../../components/ui/snackbar'
|
2019-08-02 05:57:26 +02:00
|
|
|
import { INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE, DEFAULT_ROUTE } from '../../../../helpers/constants/routes'
|
2019-03-22 00:03:30 +01:00
|
|
|
import { exportAsFile } from '../../../../helpers/utils/util'
|
2019-11-22 18:03:51 +01:00
|
|
|
import { returnToOnboardingInitiator } from '../../onboarding-initiator-util'
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
export default class RevealSeedPhrase extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
history: PropTypes.object,
|
|
|
|
seedPhrase: PropTypes.string,
|
2019-08-02 05:57:26 +02:00
|
|
|
setSeedPhraseBackedUp: PropTypes.func,
|
|
|
|
setCompletedOnboarding: PropTypes.func,
|
2019-11-22 18:03:51 +01:00
|
|
|
onboardingInitiator: PropTypes.exact({
|
|
|
|
location: PropTypes.string,
|
|
|
|
tabId: PropTypes.number,
|
|
|
|
}),
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
isShowingSeedPhrase: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
handleExport = () => {
|
2020-01-22 02:22:55 +01:00
|
|
|
exportAsFile('', this.props.seedPhrase, 'text/plain')
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2019-11-22 18:03:51 +01:00
|
|
|
handleNext = () => {
|
2019-01-23 16:25:34 +01:00
|
|
|
const { isShowingSeedPhrase } = this.state
|
|
|
|
const { history } = this.props
|
|
|
|
|
2019-03-05 16:45:01 +01:00
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Onboarding',
|
|
|
|
action: 'Seed Phrase Setup',
|
|
|
|
name: 'Advance to Verify',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
if (!isShowingSeedPhrase) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
history.push(INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE)
|
|
|
|
}
|
|
|
|
|
2019-11-22 18:03:51 +01:00
|
|
|
handleSkip = async () => {
|
|
|
|
const { history, setSeedPhraseBackedUp, setCompletedOnboarding, onboardingInitiator } = this.props
|
2019-08-02 05:57:26 +02:00
|
|
|
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Onboarding',
|
|
|
|
action: 'Seed Phrase Setup',
|
|
|
|
name: 'Remind me later',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-11-22 18:03:51 +01:00
|
|
|
await Promise.all([setCompletedOnboarding(), setSeedPhraseBackedUp(false)])
|
|
|
|
|
|
|
|
if (onboardingInitiator) {
|
|
|
|
await returnToOnboardingInitiator(onboardingInitiator)
|
|
|
|
}
|
|
|
|
history.push(DEFAULT_ROUTE)
|
2019-08-02 05:57:26 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
renderSecretWordsContainer () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { seedPhrase } = this.props
|
|
|
|
const { isShowingSeedPhrase } = this.state
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="reveal-seed-phrase__secret">
|
2019-12-03 17:35:44 +01:00
|
|
|
<div
|
|
|
|
className={classnames(
|
|
|
|
'reveal-seed-phrase__secret-words notranslate', {
|
|
|
|
'reveal-seed-phrase__secret-words--hidden': !isShowingSeedPhrase,
|
2020-08-19 18:27:05 +02:00
|
|
|
},
|
|
|
|
)}
|
2019-12-03 17:35:44 +01:00
|
|
|
>
|
2019-01-23 16:25:34 +01:00
|
|
|
{ seedPhrase }
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
!isShowingSeedPhrase && (
|
|
|
|
<div
|
|
|
|
className="reveal-seed-phrase__secret-blocker"
|
2019-03-05 16:45:01 +01:00
|
|
|
onClick={() => {
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Onboarding',
|
|
|
|
action: 'Seed Phrase Setup',
|
|
|
|
name: 'Revealed Words',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
this.setState({ isShowingSeedPhrase: true })
|
|
|
|
}}
|
2019-01-23 16:25:34 +01:00
|
|
|
>
|
|
|
|
<LockIcon
|
|
|
|
width="28px"
|
|
|
|
height="35px"
|
|
|
|
fill="#FFFFFF"
|
|
|
|
/>
|
|
|
|
<div className="reveal-seed-phrase__reveal-button">
|
|
|
|
{ t('clickToRevealSeed') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { isShowingSeedPhrase } = this.state
|
2019-11-22 18:03:51 +01:00
|
|
|
const { onboardingInitiator } = this.props
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
return (
|
2019-02-27 15:46:41 +01:00
|
|
|
<div className="reveal-seed-phrase">
|
2019-01-23 16:25:34 +01:00
|
|
|
<div className="seed-phrase__sections">
|
|
|
|
<div className="seed-phrase__main">
|
|
|
|
<div className="first-time-flow__header">
|
|
|
|
{ t('secretBackupPhrase') }
|
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
|
|
|
{ t('secretBackupPhraseDescription') }
|
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
|
|
|
{ t('secretBackupPhraseWarning') }
|
|
|
|
</div>
|
|
|
|
{ this.renderSecretWordsContainer() }
|
|
|
|
</div>
|
|
|
|
<div className="seed-phrase__side">
|
|
|
|
<div className="first-time-flow__text-block">
|
|
|
|
{ `${t('tips')}:` }
|
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
|
|
|
{ t('storePhrase') }
|
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
|
|
|
{ t('writePhrase') }
|
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
|
|
|
{ t('memorizePhrase') }
|
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
|
|
|
<a
|
|
|
|
className="reveal-seed-phrase__export-text"
|
2019-12-03 17:35:44 +01:00
|
|
|
onClick={this.handleExport}
|
|
|
|
>
|
2019-01-23 16:25:34 +01:00
|
|
|
{ t('downloadSecretBackup') }
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-08-02 05:57:26 +02:00
|
|
|
<div className="reveal-seed-phrase__buttons">
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
className="first-time-flow__button"
|
|
|
|
onClick={this.handleSkip}
|
|
|
|
>
|
|
|
|
{ t('remindMeLater') }
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
className="first-time-flow__button"
|
|
|
|
onClick={this.handleNext}
|
|
|
|
disabled={!isShowingSeedPhrase}
|
|
|
|
>
|
|
|
|
{ t('next') }
|
|
|
|
</Button>
|
|
|
|
</div>
|
2019-11-22 18:03:51 +01:00
|
|
|
{
|
|
|
|
onboardingInitiator ?
|
2019-12-03 17:35:44 +01:00
|
|
|
(
|
|
|
|
<Snackbar
|
|
|
|
content={t('onboardingReturnNotice', [t('remindMeLater'), onboardingInitiator.location])}
|
|
|
|
/>
|
|
|
|
) :
|
2019-11-22 18:03:51 +01:00
|
|
|
null
|
|
|
|
}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|