2019-01-23 16:25:34 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Switch, Route } from 'react-router-dom'
|
|
|
|
import Unlock from '../unlock-page'
|
|
|
|
import {
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
INITIALIZE_WELCOME_ROUTE,
|
|
|
|
INITIALIZE_CREATE_PASSWORD_ROUTE,
|
|
|
|
INITIALIZE_SEED_PHRASE_ROUTE,
|
|
|
|
INITIALIZE_UNLOCK_ROUTE,
|
2019-02-27 15:46:41 +01:00
|
|
|
INITIALIZE_SELECT_ACTION_ROUTE,
|
|
|
|
INITIALIZE_END_OF_FLOW_ROUTE,
|
2019-03-05 16:45:01 +01:00
|
|
|
INITIALIZE_METAMETRICS_OPT_IN_ROUTE,
|
2019-08-06 05:24:19 +02:00
|
|
|
INITIALIZE_BACKUP_SEED_PHRASE_ROUTE,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../helpers/constants/routes'
|
2020-08-18 21:18:25 +02:00
|
|
|
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'
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
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,
|
2019-06-27 15:11:16 +02:00
|
|
|
nextRoute: PropTypes.string,
|
2019-08-02 05:57:26 +02:00
|
|
|
showingSeedPhraseBackupAfterOnboarding: PropTypes.bool,
|
|
|
|
seedPhraseBackedUp: PropTypes.bool,
|
|
|
|
verifySeedPhrase: PropTypes.func,
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
seedPhrase: '',
|
|
|
|
isImportedKeyring: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
2019-08-02 05:57:26 +02:00
|
|
|
const {
|
|
|
|
completedOnboarding,
|
|
|
|
history,
|
|
|
|
isInitialized,
|
|
|
|
isUnlocked,
|
|
|
|
showingSeedPhraseBackupAfterOnboarding,
|
|
|
|
seedPhraseBackedUp,
|
|
|
|
} = this.props
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2019-08-02 05:57:26 +02:00
|
|
|
if (completedOnboarding && (!showingSeedPhraseBackupAfterOnboarding || seedPhraseBackedUp)) {
|
2019-01-23 16:25:34 +01:00
|
|
|
history.push(DEFAULT_ROUTE)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInitialized && !isUnlocked) {
|
|
|
|
history.push(INITIALIZE_UNLOCK_ROUTE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
handleCreateNewAccount = async (password) => {
|
2019-01-23 16:25:34 +01:00
|
|
|
const { createNewAccount } = this.props
|
|
|
|
|
|
|
|
try {
|
|
|
|
const seedPhrase = await createNewAccount(password)
|
|
|
|
this.setState({ seedPhrase })
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(error.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleImportWithSeedPhrase = async (password, seedPhrase) => {
|
|
|
|
const { createNewAccountFromSeed } = this.props
|
|
|
|
|
|
|
|
try {
|
2019-09-16 19:11:01 +02:00
|
|
|
const vault = await createNewAccountFromSeed(password, seedPhrase)
|
2019-01-23 16:25:34 +01:00
|
|
|
this.setState({ isImportedKeyring: true })
|
2019-09-16 19:11:01 +02:00
|
|
|
return vault
|
2019-01-23 16:25:34 +01:00
|
|
|
} catch (error) {
|
|
|
|
throw new Error(error.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
handleUnlock = async (password) => {
|
2019-03-05 16:45:01 +01:00
|
|
|
const { unlockAccount, history, nextRoute } = this.props
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
const seedPhrase = await unlockAccount(password)
|
|
|
|
this.setState({ seedPhrase }, () => {
|
2019-03-05 16:45:01 +01:00
|
|
|
history.push(nextRoute)
|
2019-01-23 16:25:34 +01:00
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(error.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { seedPhrase, isImportedKeyring } = this.state
|
2019-08-02 05:57:26 +02:00
|
|
|
const { verifySeedPhrase } = this.props
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="first-time-flow">
|
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
path={INITIALIZE_SEED_PHRASE_ROUTE}
|
2020-02-15 21:34:12 +01:00
|
|
|
render={(routeProps) => (
|
2019-01-23 16:25:34 +01:00
|
|
|
<SeedPhrase
|
2019-12-06 14:43:50 +01:00
|
|
|
{ ...routeProps }
|
2019-01-23 16:25:34 +01:00
|
|
|
seedPhrase={seedPhrase}
|
2019-08-02 05:57:26 +02:00
|
|
|
verifySeedPhrase={verifySeedPhrase}
|
2019-01-23 16:25:34 +01:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2019-08-06 05:24:19 +02:00
|
|
|
<Route
|
|
|
|
path={INITIALIZE_BACKUP_SEED_PHRASE_ROUTE}
|
2020-02-15 21:34:12 +01:00
|
|
|
render={(routeProps) => (
|
2019-08-06 05:24:19 +02:00
|
|
|
<SeedPhrase
|
2019-12-06 14:43:50 +01:00
|
|
|
{ ...routeProps }
|
2019-08-06 05:24:19 +02:00
|
|
|
seedPhrase={seedPhrase}
|
|
|
|
verifySeedPhrase={verifySeedPhrase}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2019-01-23 16:25:34 +01:00
|
|
|
<Route
|
|
|
|
path={INITIALIZE_CREATE_PASSWORD_ROUTE}
|
2020-02-15 21:34:12 +01:00
|
|
|
render={(routeProps) => (
|
2019-01-23 16:25:34 +01:00
|
|
|
<CreatePassword
|
2019-12-06 14:43:50 +01:00
|
|
|
{ ...routeProps }
|
2019-02-27 15:46:41 +01:00
|
|
|
isImportedKeyring={isImportedKeyring}
|
2019-01-23 16:25:34 +01:00
|
|
|
onCreateNewAccount={this.handleCreateNewAccount}
|
|
|
|
onCreateNewAccountFromSeed={this.handleImportWithSeedPhrase}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2019-02-27 15:46:41 +01:00
|
|
|
<Route
|
|
|
|
path={INITIALIZE_SELECT_ACTION_ROUTE}
|
|
|
|
component={SelectAction}
|
|
|
|
/>
|
2019-01-23 16:25:34 +01:00
|
|
|
<Route
|
|
|
|
path={INITIALIZE_UNLOCK_ROUTE}
|
2020-02-15 21:34:12 +01:00
|
|
|
render={(routeProps) => (
|
2019-01-23 16:25:34 +01:00
|
|
|
<Unlock
|
2019-12-06 14:43:50 +01:00
|
|
|
{ ...routeProps }
|
2019-01-23 16:25:34 +01:00
|
|
|
onSubmit={this.handleUnlock}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2019-02-27 15:46:41 +01:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={INITIALIZE_END_OF_FLOW_ROUTE}
|
|
|
|
component={EndOfFlow}
|
|
|
|
/>
|
2019-01-23 16:25:34 +01:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={INITIALIZE_WELCOME_ROUTE}
|
|
|
|
component={Welcome}
|
|
|
|
/>
|
2019-03-05 16:45:01 +01:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={INITIALIZE_METAMETRICS_OPT_IN_ROUTE}
|
|
|
|
component={MetaMetricsOptInScreen}
|
|
|
|
/>
|
2019-01-23 16:25:34 +01:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="*"
|
|
|
|
component={FirstTimeFlowSwitch}
|
|
|
|
/>
|
|
|
|
</Switch>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|