2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
2018-07-05 19:09:55 +02:00
|
|
|
import {
|
|
|
|
createNewVaultAndRestore,
|
|
|
|
unMarkPasswordForgotten,
|
2019-09-26 09:24:52 +02:00
|
|
|
initializeThreeBox,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
|
|
|
import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
2022-02-03 15:06:43 +01:00
|
|
|
import CreateNewVault from '../../components/app/create-new-vault';
|
2021-07-22 19:34:53 +02:00
|
|
|
|
2018-07-05 19:09:55 +02:00
|
|
|
class RestoreVaultPage extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2018-07-05 19:09:55 +02:00
|
|
|
static propTypes = {
|
|
|
|
createNewVaultAndRestore: PropTypes.func.isRequired,
|
|
|
|
leaveImportSeedScreenState: PropTypes.func,
|
|
|
|
history: PropTypes.object,
|
|
|
|
isLoading: PropTypes.bool,
|
2019-09-26 09:24:52 +02:00
|
|
|
initializeThreeBox: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-05 19:09:55 +02:00
|
|
|
|
2022-02-03 15:06:43 +01:00
|
|
|
handleImport = async (password, seedPhrase) => {
|
2018-07-05 19:09:55 +02:00
|
|
|
const {
|
2020-08-18 18:36:45 +02:00
|
|
|
// eslint-disable-next-line no-shadow
|
2018-07-05 19:09:55 +02:00
|
|
|
createNewVaultAndRestore,
|
|
|
|
leaveImportSeedScreenState,
|
|
|
|
history,
|
2020-08-18 18:36:45 +02:00
|
|
|
// eslint-disable-next-line no-shadow
|
2019-09-26 09:24:52 +02:00
|
|
|
initializeThreeBox,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-07-05 19:09:55 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
leaveImportSeedScreenState();
|
2022-02-03 15:06:43 +01:00
|
|
|
await createNewVaultAndRestore(password, seedPhrase);
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Retention',
|
|
|
|
action: 'userEntersSeedPhrase',
|
|
|
|
name: 'onboardingRestoredVault',
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2022-02-03 15:06:43 +01:00
|
|
|
});
|
|
|
|
initializeThreeBox();
|
|
|
|
history.push(DEFAULT_ROUTE);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-09-02 17:45:09 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
const { isLoading } = this.props;
|
2017-11-29 05:24:35 +01:00
|
|
|
|
|
|
|
return (
|
2018-07-05 19:09:55 +02:00
|
|
|
<div className="first-view-main-wrapper">
|
|
|
|
<div className="first-view-main">
|
|
|
|
<div className="import-account">
|
|
|
|
<a
|
|
|
|
className="import-account__back-button"
|
2020-02-15 21:34:12 +01:00
|
|
|
onClick={(e) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
e.preventDefault();
|
|
|
|
this.props.leaveImportSeedScreenState();
|
|
|
|
this.props.history.goBack();
|
2018-07-05 19:09:55 +02:00
|
|
|
}}
|
|
|
|
href="#"
|
|
|
|
>
|
2021-06-08 19:02:34 +02:00
|
|
|
{`< ${t('back')}`}
|
2018-07-05 19:09:55 +02:00
|
|
|
</a>
|
|
|
|
<div className="import-account__title">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('restoreAccountWithSeed')}
|
2018-07-05 19:09:55 +02:00
|
|
|
</div>
|
|
|
|
<div className="import-account__selector-label">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('secretPhrase')}
|
2018-07-05 19:09:55 +02:00
|
|
|
</div>
|
2021-10-21 10:50:17 +02:00
|
|
|
<div className="import-account__selector-typography">
|
|
|
|
{this.context.t('secretPhraseWarning')}
|
|
|
|
</div>
|
2022-02-03 15:06:43 +01:00
|
|
|
<CreateNewVault
|
|
|
|
disabled={isLoading}
|
2021-12-10 20:32:13 +01:00
|
|
|
onSubmit={this.handleImport}
|
2022-02-03 15:06:43 +01:00
|
|
|
submitText={t('restore')}
|
|
|
|
/>
|
2018-07-05 19:09:55 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 19:09:55 +02:00
|
|
|
export default connect(
|
2019-12-08 04:10:47 +01:00
|
|
|
({ appState: { isLoading } }) => ({ isLoading }),
|
2020-02-15 21:34:12 +01:00
|
|
|
(dispatch) => ({
|
2018-07-05 19:09:55 +02:00
|
|
|
leaveImportSeedScreenState: () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(unMarkPasswordForgotten());
|
2017-11-29 05:24:35 +01:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
createNewVaultAndRestore: (pw, seed) =>
|
|
|
|
dispatch(createNewVaultAndRestore(pw, seed)),
|
2019-09-26 09:24:52 +02:00
|
|
|
initializeThreeBox: () => dispatch(initializeThreeBox()),
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(RestoreVaultPage);
|