2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Switch, Route } from 'react-router-dom';
|
|
|
|
import HTML5Backend from 'react-dnd-html5-backend';
|
|
|
|
import { DragDropContextProvider } from 'react-dnd';
|
2019-01-23 16:25:34 +01:00
|
|
|
import {
|
|
|
|
INITIALIZE_SEED_PHRASE_ROUTE,
|
|
|
|
INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE,
|
2019-08-06 05:24:19 +02:00
|
|
|
INITIALIZE_BACKUP_SEED_PHRASE_ROUTE,
|
2021-04-14 00:29:44 +02:00
|
|
|
INITIALIZE_SEED_PHRASE_INTRO_ROUTE,
|
2019-01-23 16:25:34 +01:00
|
|
|
DEFAULT_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../helpers/constants/routes';
|
|
|
|
import MetaFoxLogo from '../../../components/ui/metafox-logo';
|
|
|
|
import ConfirmSeedPhrase from './confirm-seed-phrase';
|
|
|
|
import RevealSeedPhrase from './reveal-seed-phrase';
|
2021-04-14 00:29:44 +02:00
|
|
|
import SeedPhraseIntro from './seed-phrase-intro';
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
export default class SeedPhrase extends PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
history: PropTypes.object,
|
|
|
|
seedPhrase: PropTypes.string,
|
2019-08-02 05:57:26 +02:00
|
|
|
verifySeedPhrase: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-08-02 05:57:26 +02:00
|
|
|
|
|
|
|
state = {
|
|
|
|
verifiedSeedPhrase: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidMount() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { seedPhrase, history, verifySeedPhrase } = this.props;
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
if (!seedPhrase) {
|
2020-11-03 00:41:28 +01:00
|
|
|
verifySeedPhrase().then((verifiedSeedPhrase) => {
|
|
|
|
if (verifiedSeedPhrase) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ verifiedSeedPhrase });
|
2020-11-03 00:41:28 +01:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
history.push(DEFAULT_ROUTE);
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
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-04-14 00:29:44 +02:00
|
|
|
const { seedPhrase, history } = this.props;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { verifiedSeedPhrase } = this.state;
|
2021-04-14 00:29:44 +02:00
|
|
|
const pathname = history?.location?.pathname;
|
|
|
|
const introClass =
|
|
|
|
pathname === INITIALIZE_SEED_PHRASE_INTRO_ROUTE ? 'intro' : '';
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
return (
|
2019-05-07 17:03:27 +02:00
|
|
|
<DragDropContextProvider backend={HTML5Backend}>
|
2021-04-14 00:29:44 +02:00
|
|
|
<div className={`first-time-flow__wrapper ${introClass}`}>
|
2019-07-09 19:17:58 +02:00
|
|
|
<MetaFoxLogo />
|
2019-05-07 17:03:27 +02:00
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={INITIALIZE_CONFIRM_SEED_PHRASE_ROUTE}
|
2020-02-15 21:34:12 +01:00
|
|
|
render={(routeProps) => (
|
2019-05-07 17:03:27 +02:00
|
|
|
<ConfirmSeedPhrase
|
2020-11-03 00:41:28 +01:00
|
|
|
{...routeProps}
|
2019-08-02 05:57:26 +02:00
|
|
|
seedPhrase={seedPhrase || verifiedSeedPhrase}
|
2019-05-07 17:03:27 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={INITIALIZE_SEED_PHRASE_ROUTE}
|
2020-02-15 21:34:12 +01:00
|
|
|
render={(routeProps) => (
|
2019-05-07 17:03:27 +02:00
|
|
|
<RevealSeedPhrase
|
2020-11-03 00:41:28 +01:00
|
|
|
{...routeProps}
|
2019-08-02 05:57:26 +02:00
|
|
|
seedPhrase={seedPhrase || verifiedSeedPhrase}
|
2019-05-07 17:03:27 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2019-08-06 05:24:19 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={INITIALIZE_BACKUP_SEED_PHRASE_ROUTE}
|
2020-02-15 21:34:12 +01:00
|
|
|
render={(routeProps) => (
|
2019-08-06 05:24:19 +02:00
|
|
|
<RevealSeedPhrase
|
2020-11-03 00:41:28 +01:00
|
|
|
{...routeProps}
|
2019-08-06 05:24:19 +02:00
|
|
|
seedPhrase={seedPhrase || verifiedSeedPhrase}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2021-04-14 00:29:44 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={INITIALIZE_SEED_PHRASE_INTRO_ROUTE}
|
|
|
|
render={(routeProps) => (
|
|
|
|
<SeedPhraseIntro
|
|
|
|
{...routeProps}
|
|
|
|
seedPhrase={seedPhrase || verifiedSeedPhrase}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2019-05-07 17:03:27 +02:00
|
|
|
</Switch>
|
2019-02-27 15:46:41 +01:00
|
|
|
</div>
|
2019-05-07 17:03:27 +02:00
|
|
|
</DragDropContextProvider>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
}
|