2016-04-14 00:28:44 +02:00
|
|
|
const inherits = require('util').inherits
|
2016-11-01 19:25:38 +01:00
|
|
|
const PersistentForm = require('../../../lib/persistent-form')
|
2016-04-14 00:28:44 +02:00
|
|
|
const connect = require('react-redux').connect
|
|
|
|
const h = require('react-hyperscript')
|
2016-11-01 19:25:38 +01:00
|
|
|
const actions = require('../../actions')
|
2016-04-14 00:28:44 +02:00
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(RestoreVaultScreen)
|
|
|
|
|
2016-08-25 21:18:04 +02:00
|
|
|
inherits(RestoreVaultScreen, PersistentForm)
|
2016-06-21 22:18:32 +02:00
|
|
|
function RestoreVaultScreen () {
|
2016-08-25 21:18:04 +02:00
|
|
|
PersistentForm.call(this)
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function mapStateToProps (state) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
|
|
|
warning: state.appState.warning,
|
2016-12-19 23:54:24 +01:00
|
|
|
forgottenPassword: state.appState.forgottenPassword,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
RestoreVaultScreen.prototype.render = function () {
|
2016-04-14 00:28:44 +02:00
|
|
|
var state = this.props
|
2016-08-25 21:18:04 +02:00
|
|
|
this.persistentFormParentId = 'restore-vault-form'
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
return (
|
|
|
|
|
|
|
|
h('.initialize-screen.flex-column.flex-center.flex-grow', [
|
|
|
|
|
2016-05-27 00:11:22 +02:00
|
|
|
h('h3.flex-center.text-transform-uppercase', {
|
|
|
|
style: {
|
|
|
|
background: '#EBEBEB',
|
|
|
|
color: '#AEAEAE',
|
|
|
|
marginBottom: 24,
|
|
|
|
width: '100%',
|
|
|
|
fontSize: '20px',
|
|
|
|
padding: 6,
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
'Restore Vault',
|
2016-04-14 00:28:44 +02:00
|
|
|
]),
|
|
|
|
|
|
|
|
// wallet seed entry
|
|
|
|
h('h3', 'Wallet Seed'),
|
2016-05-27 00:11:22 +02:00
|
|
|
h('textarea.twelve-word-phrase.letter-spacey', {
|
2016-09-12 19:34:06 +02:00
|
|
|
dataset: {
|
2016-08-25 21:18:04 +02:00
|
|
|
persistentFormId: 'wallet-seed',
|
|
|
|
},
|
2016-06-21 22:18:32 +02:00
|
|
|
placeholder: 'Enter your secret twelve word phrase here to restore your vault.',
|
2016-04-14 00:28:44 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
// password
|
2016-05-27 00:11:22 +02:00
|
|
|
h('input.large-input.letter-spacey', {
|
2016-04-14 00:28:44 +02:00
|
|
|
type: 'password',
|
|
|
|
id: 'password-box',
|
2016-05-27 00:11:22 +02:00
|
|
|
placeholder: 'New Password (min 8 chars)',
|
2016-09-12 19:34:06 +02:00
|
|
|
dataset: {
|
2016-08-25 21:18:04 +02:00
|
|
|
persistentFormId: 'password',
|
|
|
|
},
|
2016-05-27 00:11:22 +02:00
|
|
|
style: {
|
|
|
|
width: 260,
|
|
|
|
marginTop: 12,
|
|
|
|
},
|
2016-04-14 00:28:44 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
// confirm password
|
2016-05-27 00:11:22 +02:00
|
|
|
h('input.large-input.letter-spacey', {
|
2016-04-14 00:28:44 +02:00
|
|
|
type: 'password',
|
|
|
|
id: 'password-box-confirm',
|
2016-05-27 00:11:22 +02:00
|
|
|
placeholder: 'Confirm Password',
|
2016-11-01 19:51:51 +01:00
|
|
|
onKeyPress: this.createOnEnter.bind(this),
|
2016-09-12 19:34:06 +02:00
|
|
|
dataset: {
|
2016-08-25 21:18:04 +02:00
|
|
|
persistentFormId: 'password-confirmation',
|
|
|
|
},
|
2016-05-27 00:11:22 +02:00
|
|
|
style: {
|
|
|
|
width: 260,
|
|
|
|
marginTop: 16,
|
|
|
|
},
|
2016-04-14 00:28:44 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
(state.warning) && (
|
|
|
|
h('span.error.in-progress-notification', state.warning)
|
|
|
|
),
|
|
|
|
|
|
|
|
// submit
|
2016-05-27 00:11:22 +02:00
|
|
|
|
|
|
|
h('.flex-row.flex-space-between', {
|
|
|
|
style: {
|
|
|
|
marginTop: 30,
|
|
|
|
width: '50%',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
|
|
|
|
// cancel
|
|
|
|
h('button.primary', {
|
|
|
|
onClick: this.showInitializeMenu.bind(this),
|
|
|
|
}, 'CANCEL'),
|
|
|
|
|
|
|
|
// submit
|
|
|
|
h('button.primary', {
|
2016-11-01 19:25:38 +01:00
|
|
|
onClick: this.createNewVaultAndRestore.bind(this),
|
2016-05-27 00:11:22 +02:00
|
|
|
}, 'OK'),
|
|
|
|
|
|
|
|
]),
|
2016-04-14 00:28:44 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
RestoreVaultScreen.prototype.showInitializeMenu = function () {
|
2018-03-08 16:29:29 +01:00
|
|
|
const { dispatch, forgottenPassword } = this.props
|
|
|
|
dispatch(actions.unMarkPasswordForgotten())
|
|
|
|
.then(() => {
|
|
|
|
if (forgottenPassword) {
|
|
|
|
dispatch(actions.backToUnlockView())
|
|
|
|
} else {
|
|
|
|
dispatch(actions.showInitializeMenu())
|
|
|
|
}
|
|
|
|
})
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-11-01 19:51:51 +01:00
|
|
|
RestoreVaultScreen.prototype.createOnEnter = function (event) {
|
2016-04-14 00:28:44 +02:00
|
|
|
if (event.key === 'Enter') {
|
2016-11-01 19:51:51 +01:00
|
|
|
this.createNewVaultAndRestore()
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-01 19:25:38 +01:00
|
|
|
RestoreVaultScreen.prototype.createNewVaultAndRestore = function () {
|
2016-04-14 00:28:44 +02:00
|
|
|
// check password
|
|
|
|
var passwordBox = document.getElementById('password-box')
|
|
|
|
var password = passwordBox.value
|
|
|
|
var passwordConfirmBox = document.getElementById('password-box-confirm')
|
|
|
|
var passwordConfirm = passwordConfirmBox.value
|
|
|
|
if (password.length < 8) {
|
|
|
|
this.warning = 'Password not long enough'
|
|
|
|
|
|
|
|
this.props.dispatch(actions.displayWarning(this.warning))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (password !== passwordConfirm) {
|
|
|
|
this.warning = 'Passwords don\'t match'
|
|
|
|
this.props.dispatch(actions.displayWarning(this.warning))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// check seed
|
|
|
|
var seedBox = document.querySelector('textarea.twelve-word-phrase')
|
|
|
|
var seed = seedBox.value.trim()
|
2018-03-06 04:43:12 +01:00
|
|
|
|
|
|
|
// true if the string has more than a space between words.
|
|
|
|
if (seed.split(' ').length > 1) {
|
2018-03-14 17:34:25 +01:00
|
|
|
this.warning = 'there can only be a space between words'
|
2018-03-06 04:43:12 +01:00
|
|
|
this.props.dispatch(actions.displayWarning(this.warning))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// true if seed contains a character that is not between a-z or a space
|
2018-03-13 22:41:54 +01:00
|
|
|
if (!seed.match(/^[a-z ]+$/)) {
|
2018-03-06 04:43:12 +01:00
|
|
|
this.warning = 'seed words only have lowercase characters'
|
|
|
|
this.props.dispatch(actions.displayWarning(this.warning))
|
|
|
|
return
|
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
if (seed.split(' ').length !== 12) {
|
|
|
|
this.warning = 'seed phrases are 12 words long'
|
|
|
|
this.props.dispatch(actions.displayWarning(this.warning))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// submit
|
|
|
|
this.warning = null
|
|
|
|
this.props.dispatch(actions.displayWarning(this.warning))
|
2016-11-01 19:25:38 +01:00
|
|
|
this.props.dispatch(actions.createNewVaultAndRestore(password, seed))
|
2018-03-08 16:29:29 +01:00
|
|
|
.catch(err => log.error(err.message))
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|