You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
4.9 KiB
176 lines
4.9 KiB
4 years ago
|
import React, { PureComponent } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { Switch, Route } from 'react-router-dom';
|
||
|
import Unlock from '../unlock-page';
|
||
6 years ago
|
import {
|
||
|
DEFAULT_ROUTE,
|
||
|
INITIALIZE_WELCOME_ROUTE,
|
||
|
INITIALIZE_CREATE_PASSWORD_ROUTE,
|
||
|
INITIALIZE_SEED_PHRASE_ROUTE,
|
||
|
INITIALIZE_UNLOCK_ROUTE,
|
||
6 years ago
|
INITIALIZE_SELECT_ACTION_ROUTE,
|
||
|
INITIALIZE_END_OF_FLOW_ROUTE,
|
||
6 years ago
|
INITIALIZE_METAMETRICS_OPT_IN_ROUTE,
|
||
5 years ago
|
INITIALIZE_BACKUP_SEED_PHRASE_ROUTE,
|
||
4 years ago
|
INITIALIZE_SEED_PHRASE_INTRO_ROUTE,
|
||
4 years ago
|
} from '../../helpers/constants/routes';
|
||
|
import FirstTimeFlowSwitch from './first-time-flow-switch';
|
||
|
import Welcome from './welcome';
|
||
|
import SelectAction from './select-action';
|
||
|
import EndOfFlow from './end-of-flow';
|
||
|
import CreatePassword from './create-password';
|
||
|
import SeedPhrase from './seed-phrase';
|
||
|
import MetaMetricsOptInScreen from './metametrics-opt-in';
|
||
6 years ago
|
|
||
|
export default class FirstTimeFlow extends PureComponent {
|
||
|
static propTypes = {
|
||
|
completedOnboarding: PropTypes.bool,
|
||
|
createNewAccount: PropTypes.func,
|
||
|
createNewAccountFromSeed: PropTypes.func,
|
||
|
history: PropTypes.object,
|
||
|
isInitialized: PropTypes.bool,
|
||
|
isUnlocked: PropTypes.bool,
|
||
|
unlockAccount: PropTypes.func,
|
||
5 years ago
|
nextRoute: PropTypes.string,
|
||
5 years ago
|
showingSeedPhraseBackupAfterOnboarding: PropTypes.bool,
|
||
|
seedPhraseBackedUp: PropTypes.bool,
|
||
|
verifySeedPhrase: PropTypes.func,
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
|
state = {
|
||
|
seedPhrase: '',
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
componentDidMount() {
|
||
5 years ago
|
const {
|
||
|
completedOnboarding,
|
||
|
history,
|
||
|
isInitialized,
|
||
|
isUnlocked,
|
||
|
showingSeedPhraseBackupAfterOnboarding,
|
||
|
seedPhraseBackedUp,
|
||
4 years ago
|
} = this.props;
|
||
6 years ago
|
|
||
4 years ago
|
if (
|
||
|
completedOnboarding &&
|
||
|
(!showingSeedPhraseBackupAfterOnboarding || seedPhraseBackedUp)
|
||
|
) {
|
||
4 years ago
|
history.push(DEFAULT_ROUTE);
|
||
|
return;
|
||
6 years ago
|
}
|
||
|
|
||
|
if (isInitialized && !isUnlocked) {
|
||
4 years ago
|
history.push(INITIALIZE_UNLOCK_ROUTE);
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
handleCreateNewAccount = async (password) => {
|
||
4 years ago
|
const { createNewAccount } = this.props;
|
||
6 years ago
|
|
||
|
try {
|
||
4 years ago
|
const seedPhrase = await createNewAccount(password);
|
||
|
this.setState({ seedPhrase });
|
||
6 years ago
|
} catch (error) {
|
||
4 years ago
|
throw new Error(error.message);
|
||
6 years ago
|
}
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
|
handleImportWithSeedPhrase = async (password, seedPhrase) => {
|
||
4 years ago
|
const { createNewAccountFromSeed } = this.props;
|
||
6 years ago
|
|
||
|
try {
|
||
4 years ago
|
const vault = await createNewAccountFromSeed(password, seedPhrase);
|
||
|
return vault;
|
||
6 years ago
|
} catch (error) {
|
||
4 years ago
|
throw new Error(error.message);
|
||
6 years ago
|
}
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
5 years ago
|
handleUnlock = async (password) => {
|
||
4 years ago
|
const { unlockAccount, history, nextRoute } = this.props;
|
||
6 years ago
|
|
||
|
try {
|
||
4 years ago
|
const seedPhrase = await unlockAccount(password);
|
||
6 years ago
|
this.setState({ seedPhrase }, () => {
|
||
4 years ago
|
history.push(nextRoute);
|
||
|
});
|
||
6 years ago
|
} catch (error) {
|
||
4 years ago
|
throw new Error(error.message);
|
||
6 years ago
|
}
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { seedPhrase } = this.state;
|
||
|
const { verifySeedPhrase } = this.props;
|
||
6 years ago
|
|
||
|
return (
|
||
|
<div className="first-time-flow">
|
||
|
<Switch>
|
||
|
<Route
|
||
|
path={INITIALIZE_SEED_PHRASE_ROUTE}
|
||
5 years ago
|
render={(routeProps) => (
|
||
6 years ago
|
<SeedPhrase
|
||
4 years ago
|
{...routeProps}
|
||
6 years ago
|
seedPhrase={seedPhrase}
|
||
5 years ago
|
verifySeedPhrase={verifySeedPhrase}
|
||
6 years ago
|
/>
|
||
|
)}
|
||
|
/>
|
||
5 years ago
|
<Route
|
||
|
path={INITIALIZE_BACKUP_SEED_PHRASE_ROUTE}
|
||
5 years ago
|
render={(routeProps) => (
|
||
5 years ago
|
<SeedPhrase
|
||
4 years ago
|
{...routeProps}
|
||
5 years ago
|
seedPhrase={seedPhrase}
|
||
|
verifySeedPhrase={verifySeedPhrase}
|
||
|
/>
|
||
|
)}
|
||
|
/>
|
||
4 years ago
|
<Route
|
||
|
path={INITIALIZE_SEED_PHRASE_INTRO_ROUTE}
|
||
|
render={(routeProps) => (
|
||
|
<SeedPhrase
|
||
|
{...routeProps}
|
||
|
seedPhrase={seedPhrase}
|
||
|
verifySeedPhrase={verifySeedPhrase}
|
||
|
/>
|
||
|
)}
|
||
|
/>
|
||
6 years ago
|
<Route
|
||
|
path={INITIALIZE_CREATE_PASSWORD_ROUTE}
|
||
5 years ago
|
render={(routeProps) => (
|
||
6 years ago
|
<CreatePassword
|
||
4 years ago
|
{...routeProps}
|
||
6 years ago
|
onCreateNewAccount={this.handleCreateNewAccount}
|
||
|
onCreateNewAccountFromSeed={this.handleImportWithSeedPhrase}
|
||
|
/>
|
||
|
)}
|
||
|
/>
|
||
6 years ago
|
<Route
|
||
|
path={INITIALIZE_SELECT_ACTION_ROUTE}
|
||
|
component={SelectAction}
|
||
|
/>
|
||
6 years ago
|
<Route
|
||
|
path={INITIALIZE_UNLOCK_ROUTE}
|
||
5 years ago
|
render={(routeProps) => (
|
||
4 years ago
|
<Unlock {...routeProps} onSubmit={this.handleUnlock} />
|
||
6 years ago
|
)}
|
||
|
/>
|
||
6 years ago
|
<Route
|
||
|
exact
|
||
|
path={INITIALIZE_END_OF_FLOW_ROUTE}
|
||
|
component={EndOfFlow}
|
||
|
/>
|
||
4 years ago
|
<Route exact path={INITIALIZE_WELCOME_ROUTE} component={Welcome} />
|
||
6 years ago
|
<Route
|
||
|
exact
|
||
|
path={INITIALIZE_METAMETRICS_OPT_IN_ROUTE}
|
||
|
component={MetaMetricsOptInScreen}
|
||
|
/>
|
||
4 years ago
|
<Route exact path="*" component={FirstTimeFlowSwitch} />
|
||
6 years ago
|
</Switch>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
6 years ago
|
}
|
||
|
}
|