2017-01-18 01:22:22 +01:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
2018-02-01 03:08:49 +01:00
|
|
|
const { withRouter } = require('react-router-dom')
|
|
|
|
const { compose } = require('recompose')
|
|
|
|
const { connect } = require('react-redux')
|
|
|
|
const actions = require('../../../../actions')
|
|
|
|
const { DEFAULT_ROUTE } = require('../../../../routes')
|
2017-01-18 01:22:22 +01:00
|
|
|
|
2018-02-01 03:08:49 +01:00
|
|
|
module.exports = compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
)(PrivateKeyImportView)
|
2017-01-18 01:22:22 +01:00
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
error: state.appState.warning,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 19:25:38 +01:00
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
importNewAccount: (strategy, [ privateKey ]) => {
|
2018-02-01 03:08:49 +01:00
|
|
|
return dispatch(actions.importNewAccount(strategy, [ privateKey ]))
|
2018-01-10 19:25:38 +01:00
|
|
|
},
|
|
|
|
displayWarning: () => dispatch(actions.displayWarning(null)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 01:22:22 +01:00
|
|
|
inherits(PrivateKeyImportView, Component)
|
|
|
|
function PrivateKeyImportView () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
PrivateKeyImportView.prototype.render = function () {
|
2018-02-01 03:08:49 +01:00
|
|
|
const { error } = this.props
|
2017-01-18 01:22:22 +01:00
|
|
|
|
|
|
|
return (
|
2018-01-10 19:25:38 +01:00
|
|
|
h('div.new-account-import-form__private-key', [
|
2017-01-18 01:22:22 +01:00
|
|
|
|
2018-01-31 22:41:13 +01:00
|
|
|
h('div.new-account-import-form__private-key-password-container', [
|
2017-01-18 01:22:22 +01:00
|
|
|
|
2018-01-31 22:41:13 +01:00
|
|
|
h('span.new-account-import-form__instruction', 'Paste your private key string here:'),
|
|
|
|
|
|
|
|
h('input.new-account-import-form__input-password', {
|
|
|
|
type: 'password',
|
|
|
|
id: 'private-key-box',
|
|
|
|
onKeyPress: () => this.createKeyringOnEnter(),
|
|
|
|
}),
|
|
|
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('div.new-account-import-form__buttons', {}, [
|
2018-01-10 19:25:38 +01:00
|
|
|
|
|
|
|
h('button.new-account-create-form__button-cancel', {
|
2018-02-01 03:08:49 +01:00
|
|
|
onClick: () => this.props.history.push(DEFAULT_ROUTE),
|
2018-01-10 19:25:38 +01:00
|
|
|
}, [
|
|
|
|
'CANCEL',
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('button.new-account-create-form__button-create', {
|
|
|
|
onClick: () => this.createNewKeychain(),
|
|
|
|
}, [
|
|
|
|
'IMPORT',
|
|
|
|
]),
|
|
|
|
|
|
|
|
]),
|
2017-01-18 01:22:22 +01:00
|
|
|
|
2017-03-22 21:54:10 +01:00
|
|
|
error ? h('span.error', error) : null,
|
2017-01-18 01:22:22 +01:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PrivateKeyImportView.prototype.createKeyringOnEnter = function (event) {
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
event.preventDefault()
|
|
|
|
this.createNewKeychain()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PrivateKeyImportView.prototype.createNewKeychain = function () {
|
|
|
|
const input = document.getElementById('private-key-box')
|
|
|
|
const privateKey = input.value
|
2018-02-01 03:08:49 +01:00
|
|
|
const { importNewAccount, history } = this.props
|
2018-01-10 19:25:38 +01:00
|
|
|
|
2018-02-01 03:08:49 +01:00
|
|
|
importNewAccount('Private Key', [ privateKey ])
|
|
|
|
.then(() => history.push(DEFAULT_ROUTE))
|
2017-01-18 01:22:22 +01:00
|
|
|
}
|