diff options
Diffstat (limited to 'mascara/src/app/first-time/create-password-screen.js')
-rw-r--r-- | mascara/src/app/first-time/create-password-screen.js | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/mascara/src/app/first-time/create-password-screen.js b/mascara/src/app/first-time/create-password-screen.js index 192da3399..8fee04d1c 100644 --- a/mascara/src/app/first-time/create-password-screen.js +++ b/mascara/src/app/first-time/create-password-screen.js @@ -1,20 +1,21 @@ -import EventEmitter from 'events' import React, { Component } from 'react' import PropTypes from 'prop-types' import {connect} from 'react-redux' -import classnames from 'classnames' -import {createNewVaultAndKeychain} from '../../../../ui/app/actions' +import { createNewVaultAndKeychain } from '../../../../ui/app/actions' import LoadingScreen from './loading-screen' import Breadcrumbs from './breadcrumbs' +import { DEFAULT_ROUTE, IMPORT_ACCOUNT_ROUTE } from '../../../../ui/app/routes' +import EventEmitter from 'events' import Mascot from '../../../../ui/app/components/mascot' +import classnames from 'classnames' class CreatePasswordScreen extends Component { static propTypes = { isLoading: PropTypes.bool.isRequired, createAccount: PropTypes.func.isRequired, - goToImportWithSeedPhrase: PropTypes.func.isRequired, - goToImportAccount: PropTypes.func.isRequired, - next: PropTypes.func.isRequired, + history: PropTypes.object.isRequired, + isInitialized: PropTypes.bool, + isUnlocked: PropTypes.bool, isMascara: PropTypes.bool.isRequired, } @@ -28,8 +29,15 @@ class CreatePasswordScreen extends Component { this.animationEventEmitter = new EventEmitter() } + componentWillMount () { + const { isInitialized, isUnlocked, history } = this.props + if (isInitialized || isUnlocked) { + history.push(DEFAULT_ROUTE) + } + } + isValid () { - const {password, confirmPassword} = this.state + const { password, confirmPassword } = this.state if (!password || !confirmPassword) { return false @@ -47,15 +55,15 @@ class CreatePasswordScreen extends Component { return } - const {password} = this.state - const {createAccount, next} = this.props + const { password } = this.state + const { createAccount, history } = this.props createAccount(password) - .then(next) + .then(() => history.push(DEFAULT_ROUTE)) } render () { - const { isLoading, goToImportWithSeedPhrase, isMascara } = this.props + const { isLoading, isMascara } = this.props return isLoading ? <LoadingScreen loadingMessage="Creating your new account" /> @@ -106,7 +114,7 @@ class CreatePasswordScreen extends Component { className="first-time-flow__link create-password__import-link" onClick={e => { e.preventDefault() - goToImportWithSeedPhrase() + history.push(IMPORT_ACCOUNT_ROUTE) }} > Import with seed phrase @@ -131,8 +139,18 @@ class CreatePasswordScreen extends Component { } } +const mapStateToProps = state => { + const { metamask: { isInitialized, isUnlocked }, appState: { isLoading } } = state + + return { + isLoading, + isInitialized, + isUnlocked, + } +} + export default connect( - ({ appState: { isLoading }, metamask: { isMascara } }) => ({ isLoading, isMascara }), + mapStateToProps, dispatch => ({ createAccount: password => dispatch(createNewVaultAndKeychain(password)), }) |