You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.5 KiB
96 lines
2.5 KiB
8 years ago
|
const inherits = require('util').inherits
|
||
|
const Component = require('react').Component
|
||
|
const h = require('react-hyperscript')
|
||
7 years ago
|
const { withRouter } = require('react-router-dom')
|
||
|
const { compose } = require('recompose')
|
||
7 years ago
|
const PropTypes = require('prop-types')
|
||
|
const connect = require('react-redux').connect
|
||
7 years ago
|
const actions = require('../../../../actions')
|
||
|
const { DEFAULT_ROUTE } = require('../../../../routes')
|
||
8 years ago
|
|
||
7 years ago
|
PrivateKeyImportView.contextTypes = {
|
||
|
t: PropTypes.func,
|
||
|
}
|
||
|
|
||
7 years ago
|
module.exports = compose(
|
||
|
withRouter,
|
||
|
connect(mapStateToProps, mapDispatchToProps)
|
||
|
)(PrivateKeyImportView)
|
||
8 years ago
|
|
||
7 years ago
|
|
||
8 years ago
|
function mapStateToProps (state) {
|
||
|
return {
|
||
|
error: state.appState.warning,
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
function mapDispatchToProps (dispatch) {
|
||
|
return {
|
||
|
importNewAccount: (strategy, [ privateKey ]) => {
|
||
7 years ago
|
return dispatch(actions.importNewAccount(strategy, [ privateKey ]))
|
||
7 years ago
|
},
|
||
|
displayWarning: () => dispatch(actions.displayWarning(null)),
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
inherits(PrivateKeyImportView, Component)
|
||
|
function PrivateKeyImportView () {
|
||
7 years ago
|
this.createKeyringOnEnter = this.createKeyringOnEnter.bind(this)
|
||
8 years ago
|
Component.call(this)
|
||
|
}
|
||
|
|
||
|
PrivateKeyImportView.prototype.render = function () {
|
||
7 years ago
|
const { error } = this.props
|
||
8 years ago
|
|
||
|
return (
|
||
7 years ago
|
h('div.new-account-import-form__private-key', [
|
||
8 years ago
|
|
||
7 years ago
|
h('span.new-account-create-form__instruction', this.context.t('pastePrivateKey')),
|
||
8 years ago
|
|
||
7 years ago
|
h('div.new-account-import-form__private-key-password-container', [
|
||
|
|
||
|
h('input.new-account-import-form__input-password', {
|
||
|
type: 'password',
|
||
|
id: 'private-key-box',
|
||
7 years ago
|
onKeyPress: e => this.createKeyringOnEnter(e),
|
||
7 years ago
|
}),
|
||
|
|
||
|
]),
|
||
|
|
||
|
h('div.new-account-import-form__buttons', {}, [
|
||
7 years ago
|
|
||
7 years ago
|
h('button.btn-secondary--lg.new-account-create-form__button', {
|
||
7 years ago
|
onClick: () => this.props.history.push(DEFAULT_ROUTE),
|
||
7 years ago
|
}, [
|
||
7 years ago
|
this.context.t('cancel'),
|
||
7 years ago
|
]),
|
||
|
|
||
7 years ago
|
h('button.btn-primary--lg.new-account-create-form__button', {
|
||
7 years ago
|
onClick: () => this.createNewKeychain(),
|
||
|
}, [
|
||
7 years ago
|
this.context.t('import'),
|
||
7 years ago
|
]),
|
||
|
|
||
|
]),
|
||
8 years ago
|
|
||
8 years ago
|
error ? h('span.error', error) : null,
|
||
8 years ago
|
])
|
||
|
)
|
||
|
}
|
||
|
|
||
|
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
|
||
7 years ago
|
const { importNewAccount, history } = this.props
|
||
7 years ago
|
|
||
7 years ago
|
importNewAccount('Private Key', [ privateKey ])
|
||
|
.then(() => history.push(DEFAULT_ROUTE))
|
||
8 years ago
|
}
|