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 | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/mascara/src/app/first-time/create-password-screen.js b/mascara/src/app/first-time/create-password-screen.js index 0b36c6815..c490d8831 100644 --- a/mascara/src/app/first-time/create-password-screen.js +++ b/mascara/src/app/first-time/create-password-screen.js @@ -1,23 +1,25 @@ -import EventEmitter from 'events' -import React, {Component, PropTypes} from 'react' -import {connect} from 'react-redux'; -import {createNewVaultAndKeychain} from '../../../../ui/app/actions' +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import {connect} from 'react-redux' +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' 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, } state = { password: '', - confirmPassword: '' + confirmPassword: '', } constructor () { @@ -25,34 +27,41 @@ class CreatePasswordScreen extends Component { this.animationEventEmitter = new EventEmitter() } - isValid() { - const {password, confirmPassword} = this.state; + componentWillMount () { + const { isInitialized, isUnlocked, history } = this.props + if (isInitialized || isUnlocked) { + history.push(DEFAULT_ROUTE) + } + } + + isValid () { + const { password, confirmPassword } = this.state if (!password || !confirmPassword) { - return false; + return false } if (password.length < 8) { - return false; + return false } - return password === confirmPassword; + return password === confirmPassword } createAccount = () => { if (!this.isValid()) { - return; + 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, goToImportAccount, goToImportWithSeedPhrase } = this.props + render () { + const { isLoading } = this.props return isLoading ? <LoadingScreen loadingMessage="Creating your new account" /> @@ -101,7 +110,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 @@ -126,8 +135,18 @@ class CreatePasswordScreen extends Component { } } +const mapStateToProps = state => { + const { metamask: { isInitialized, isUnlocked }, appState: { isLoading } } = state + + return { + isLoading, + isInitialized, + isUnlocked, + } +} + export default connect( - ({ appState: { isLoading } }) => ({ isLoading }), + mapStateToProps, dispatch => ({ createAccount: password => dispatch(createNewVaultAndKeychain(password)), }) |