2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-01-23 16:25:34 +01:00
|
|
|
import {
|
2019-02-27 15:46:41 +01:00
|
|
|
INITIALIZE_SELECT_ACTION_ROUTE,
|
2019-03-05 16:45:01 +01:00
|
|
|
INITIALIZE_END_OF_FLOW_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../helpers/constants/routes';
|
2022-02-03 15:06:43 +01:00
|
|
|
import CreateNewVault from '../../../../components/app/create-new-vault';
|
2022-08-18 23:31:07 +02:00
|
|
|
import {
|
|
|
|
EVENT,
|
|
|
|
EVENT_NAMES,
|
|
|
|
} from '../../../../../shared/constants/metametrics';
|
2020-09-28 23:13:42 +02:00
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
export default class ImportWithSeedPhrase 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,
|
|
|
|
onSubmit: PropTypes.func.isRequired,
|
2019-08-02 05:57:26 +02:00
|
|
|
setSeedPhraseBackedUp: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
UNSAFE_componentWillMount() {
|
|
|
|
this._onBeforeUnload = () =>
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.ONBOARDING,
|
2022-08-18 23:31:07 +02:00
|
|
|
event: EVENT_NAMES.WALLET_SETUP_FAILED,
|
2022-03-29 15:46:24 +02:00
|
|
|
properties: {
|
2022-08-18 23:31:07 +02:00
|
|
|
account_type: EVENT.ACCOUNT_TYPES.IMPORTED,
|
|
|
|
account_import_type: EVENT.ACCOUNT_IMPORT_TYPES.SRP,
|
|
|
|
reason: 'Seed Phrase Error',
|
|
|
|
error: this.state.seedPhraseError,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
window.addEventListener('beforeunload', this._onBeforeUnload);
|
2019-10-31 17:27:22 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentWillUnmount() {
|
2021-02-04 19:15:23 +01:00
|
|
|
window.removeEventListener('beforeunload', this._onBeforeUnload);
|
2019-04-05 05:16:25 +02:00
|
|
|
}
|
|
|
|
|
2022-02-03 15:06:43 +01:00
|
|
|
handleImport = async (password, seedPhrase) => {
|
2022-10-31 17:20:50 +01:00
|
|
|
const { history, onSubmit, setSeedPhraseBackedUp } = this.props;
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2022-02-03 15:06:43 +01:00
|
|
|
await onSubmit(password, seedPhrase);
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.ONBOARDING,
|
2022-08-18 23:31:07 +02:00
|
|
|
event: EVENT_NAMES.WALLET_CREATED,
|
2022-03-29 15:46:24 +02:00
|
|
|
properties: {
|
2022-08-18 23:31:07 +02:00
|
|
|
account_type: EVENT.ACCOUNT_TYPES.IMPORTED,
|
|
|
|
account_import_type: EVENT.ACCOUNT_IMPORT_TYPES.SRP,
|
2019-03-05 16:45:01 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-02-27 15:46:41 +01:00
|
|
|
|
2022-02-03 15:06:43 +01:00
|
|
|
await setSeedPhraseBackedUp(true);
|
|
|
|
history.replace(INITIALIZE_END_OF_FLOW_ROUTE);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-06-11 16:24:13 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
return (
|
2022-02-03 15:06:43 +01:00
|
|
|
<div className="first-time-flow__import">
|
2019-02-27 15:46:41 +01:00
|
|
|
<div className="first-time-flow__create-back">
|
2019-01-23 16:25:34 +01:00
|
|
|
<a
|
2020-02-15 21:34:12 +01:00
|
|
|
onClick={(e) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
e.preventDefault();
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.ONBOARDING,
|
2022-08-18 23:31:07 +02:00
|
|
|
event: EVENT_NAMES.WALLET_SETUP_CANCELED,
|
2022-03-29 15:46:24 +02:00
|
|
|
properties: {
|
2022-08-18 23:31:07 +02:00
|
|
|
account_type: EVENT.ACCOUNT_TYPES.IMPORTED,
|
|
|
|
account_import_type: EVENT.ACCOUNT_IMPORT_TYPES.SRP,
|
|
|
|
text: 'Back',
|
2019-03-05 16:45:01 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
this.props.history.push(INITIALIZE_SELECT_ACTION_ROUTE);
|
2019-01-23 16:25:34 +01:00
|
|
|
}}
|
|
|
|
href="#"
|
|
|
|
>
|
2021-06-08 19:02:34 +02:00
|
|
|
{`< ${t('back')}`}
|
2019-01-23 16:25:34 +01:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div className="first-time-flow__header">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('importAccountSeedPhrase')}
|
2019-01-23 16:25:34 +01:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="first-time-flow__text-block">{t('secretPhrase')}</div>
|
2022-02-03 15:06:43 +01:00
|
|
|
<CreateNewVault
|
|
|
|
includeTerms
|
|
|
|
onSubmit={this.handleImport}
|
|
|
|
submitText={t('import')}
|
2019-01-23 16:25:34 +01:00
|
|
|
/>
|
2022-02-03 15:06:43 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
}
|