import React, { Component } from 'react' import PropTypes from 'prop-types' import {connect} from 'react-redux' import classnames from 'classnames' import { createNewVaultAndRestore, hideWarning, displayWarning, unMarkPasswordForgotten, } from '../../../../ui/app/actions' import { DEFAULT_ROUTE, INITIALIZE_NOTICE_ROUTE } from '../../../../ui/app/routes' class ImportSeedPhraseScreen extends Component { static propTypes = { warning: PropTypes.string, createNewVaultAndRestore: PropTypes.func.isRequired, hideWarning: PropTypes.func.isRequired, displayWarning: PropTypes.func, leaveImportSeedScreenState: PropTypes.func, history: PropTypes.object, }; state = { seedPhrase: '', password: '', confirmPassword: '', } parseSeedPhrase = (seedPhrase) => { return seedPhrase .match(/\w+/g) .join(' ') } onChange = ({ seedPhrase, password, confirmPassword }) => { const { password: prevPassword, confirmPassword: prevConfirmPassword, } = this.state const { displayWarning, hideWarning } = this.props let warning = null if (seedPhrase && this.parseSeedPhrase(seedPhrase).split(' ').length !== 12) { warning = 'Seed Phrases are 12 words long' } else if (password && password.length < 8) { warning = 'Passwords require a mimimum length of 8' } else if ((password || prevPassword) !== (confirmPassword || prevConfirmPassword)) { warning = 'Confirmed password does not match' } if (warning) { displayWarning(warning) } else { hideWarning() } seedPhrase && this.setState({ seedPhrase }) password && this.setState({ password }) confirmPassword && this.setState({ confirmPassword }) } onClick = () => { const { password, seedPhrase } = this.state const { createNewVaultAndRestore, displayWarning, leaveImportSeedScreenState, history, } = this.props leaveImportSeedScreenState() createNewVaultAndRestore(password, this.parseSeedPhrase(seedPhrase)) .then(() => history.push(INITIALIZE_NOTICE_ROUTE)) } render () { const { seedPhrase, password, confirmPassword } = this.state const { warning, isLoading } = this.props const importDisabled = warning || !seedPhrase || !password || !confirmPassword || isLoading return (
{ e.preventDefault() this.props.history.goBack() }} href="#" > {`< Back`}
Import an Account with Seed Phrase
Enter your secret twelve word phrase here to restore your vault.