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' class ImportSeedPhraseScreen extends Component { static propTypes = { warning: PropTypes.string, back: PropTypes.func.isRequired, next: PropTypes.func.isRequired, createNewVaultAndRestore: PropTypes.func.isRequired, hideWarning: PropTypes.func.isRequired, displayWarning: PropTypes.func, leaveImportSeedScreenState: PropTypes.func, }; 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, next, displayWarning, leaveImportSeedScreenState, } = this.props leaveImportSeedScreenState() createNewVaultAndRestore(password, this.parseSeedPhrase(seedPhrase)) .then(next) } render () { const { seedPhrase, password, confirmPassword } = this.state const { warning } = this.props const importDisabled = warning || !seedPhrase || !password || !confirmPassword return (
{ e.preventDefault() this.props.back() }} href="#" > {`< Back`}
Import an Account with Seed Phrase
Enter your secret twelve word phrase here to restore your vault.