2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
2021-06-08 19:02:34 +02:00
|
|
|
import Box from '../../../../components/ui/box';
|
2021-02-04 19:15:23 +01:00
|
|
|
import LockIcon from '../../../../components/ui/lock-icon';
|
|
|
|
import Button from '../../../../components/ui/button';
|
|
|
|
import Snackbar from '../../../../components/ui/snackbar';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE,
|
|
|
|
DEFAULT_ROUTE,
|
2021-06-08 19:02:34 +02:00
|
|
|
INITIALIZE_SEED_PHRASE_INTRO_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../helpers/constants/routes';
|
|
|
|
import { exportAsFile } from '../../../../helpers/utils/util';
|
2022-04-22 18:09:10 +02:00
|
|
|
import { EVENT } from '../../../../../shared/constants/metametrics';
|
2022-06-29 14:51:35 +02:00
|
|
|
import { returnToOnboardingInitiatorTab } from '../../onboarding-initiator-util';
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
export default class RevealSeedPhrase extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2022-03-29 15:46:24 +02:00
|
|
|
trackEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
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,
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
state = {
|
|
|
|
isShowingSeedPhrase: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
handleExport = () => {
|
2021-02-04 19:15:23 +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 = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { isShowingSeedPhrase } = this.state;
|
|
|
|
const { history } = this.props;
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.ONBOARDING,
|
2022-03-29 15:46:24 +02:00
|
|
|
event: 'Advance to Verify',
|
|
|
|
properties: {
|
2019-03-05 16:45:01 +01:00
|
|
|
action: 'Seed Phrase Setup',
|
2022-03-29 15:46:24 +02:00
|
|
|
legacy_event: true,
|
2019-03-05 16:45:01 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
if (!isShowingSeedPhrase) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2021-11-15 20:16:11 +01:00
|
|
|
history.replace(INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2019-11-22 18:03:51 +01:00
|
|
|
handleSkip = async () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
history,
|
|
|
|
setSeedPhraseBackedUp,
|
|
|
|
setCompletedOnboarding,
|
|
|
|
onboardingInitiator,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-08-02 05:57:26 +02:00
|
|
|
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.ONBOARDING,
|
2022-03-29 15:46:24 +02:00
|
|
|
event: 'Remind me later',
|
|
|
|
properties: {
|
2019-08-02 05:57:26 +02:00
|
|
|
action: 'Seed Phrase Setup',
|
2022-03-29 15:46:24 +02:00
|
|
|
legacy_event: true,
|
2019-08-02 05:57:26 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-08-02 05:57:26 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await Promise.all([setCompletedOnboarding(), setSeedPhraseBackedUp(false)]);
|
2019-11-22 18:03:51 +01:00
|
|
|
|
|
|
|
if (onboardingInitiator) {
|
2022-06-29 14:51:35 +02:00
|
|
|
await returnToOnboardingInitiatorTab(onboardingInitiator);
|
2019-11-22 18:03:51 +01:00
|
|
|
}
|
2021-11-15 20:16:11 +01:00
|
|
|
history.replace(DEFAULT_ROUTE);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-08-02 05:57:26 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderSecretWordsContainer() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
const { seedPhrase } = this.props;
|
|
|
|
const { isShowingSeedPhrase } = this.state;
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="reveal-seed-phrase__secret">
|
2019-12-03 17:35:44 +01:00
|
|
|
<div
|
|
|
|
className={classnames(
|
2020-11-03 00:41:28 +01:00
|
|
|
'reveal-seed-phrase__secret-words notranslate',
|
|
|
|
{
|
2019-12-03 17:35:44 +01:00
|
|
|
'reveal-seed-phrase__secret-words--hidden': !isShowingSeedPhrase,
|
2020-08-19 18:27:05 +02:00
|
|
|
},
|
|
|
|
)}
|
2019-12-03 17:35:44 +01:00
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{seedPhrase}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
{!isShowingSeedPhrase && (
|
|
|
|
<div
|
|
|
|
className="reveal-seed-phrase__secret-blocker"
|
|
|
|
onClick={() => {
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.ONBOARDING,
|
2022-03-29 15:46:24 +02:00
|
|
|
event: 'Revealed Words',
|
|
|
|
properties: {
|
2020-11-03 00:41:28 +01:00
|
|
|
action: 'Seed Phrase Setup',
|
2022-03-29 15:46:24 +02:00
|
|
|
legacy_event: true,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
this.setState({ isShowingSeedPhrase: true });
|
2020-11-03 00:41:28 +01:00
|
|
|
}}
|
|
|
|
>
|
2022-03-24 21:27:41 +01:00
|
|
|
<LockIcon
|
|
|
|
width="28px"
|
|
|
|
height="35px"
|
|
|
|
fill="var(--color-overlay-inverse)"
|
|
|
|
/>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="reveal-seed-phrase__reveal-button">
|
|
|
|
{t('clickToRevealSeed')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
const { isShowingSeedPhrase } = this.state;
|
2021-06-08 19:02:34 +02:00
|
|
|
const { history, 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">
|
2021-06-08 19:02:34 +02:00
|
|
|
<Box marginBottom={4}>
|
|
|
|
<a
|
|
|
|
href="#"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
history.push(INITIALIZE_SEED_PHRASE_INTRO_ROUTE);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{`< ${t('back')}`}
|
|
|
|
</a>
|
|
|
|
</Box>
|
2019-01-23 16:25:34 +01:00
|
|
|
<div className="first-time-flow__header">
|
2021-10-13 19:41:24 +02:00
|
|
|
{t('secretRecoveryPhrase')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('secretBackupPhraseDescription')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('secretBackupPhraseWarning')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderSecretWordsContainer()}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
|
|
|
<div className="seed-phrase__side">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="first-time-flow__text-block">{`${t('tips')}:`}</div>
|
2019-01-23 16:25:34 +01:00
|
|
|
<div className="first-time-flow__text-block">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('storePhrase')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('writePhrase')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__text-block">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('memorizePhrase')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</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}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('downloadSecretBackup')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</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}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('remindMeLater')}
|
2019-08-02 05:57:26 +02:00
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
className="first-time-flow__button"
|
|
|
|
onClick={this.handleNext}
|
|
|
|
disabled={!isShowingSeedPhrase}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('next')}
|
2019-08-02 05:57:26 +02:00
|
|
|
</Button>
|
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
{onboardingInitiator ? (
|
|
|
|
<Snackbar
|
|
|
|
content={t('onboardingReturnNotice', [
|
|
|
|
t('remindMeLater'),
|
|
|
|
onboardingInitiator.location,
|
|
|
|
])}
|
|
|
|
/>
|
|
|
|
) : null}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
}
|