2017-08-09 03:34:04 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2018-03-16 01:29:45 +01:00
|
|
|
const connect = require('../../metamask-connect')
|
2017-08-21 04:10:49 +02:00
|
|
|
const actions = require('../../actions')
|
2017-08-21 13:46:38 +02:00
|
|
|
const { getSelectedAccount } = require('../../selectors')
|
2017-08-09 03:34:04 +02:00
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
2017-08-21 13:46:38 +02:00
|
|
|
selectedAccount: getSelectedAccount(state),
|
|
|
|
identity: state.appState.modal.modalState.identity,
|
2017-08-09 03:34:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2017-08-10 01:27:55 +02:00
|
|
|
hideModal: () => {
|
|
|
|
dispatch(actions.hideModal())
|
2017-08-21 13:46:38 +02:00
|
|
|
},
|
|
|
|
saveAccountLabel: (account, label) => {
|
|
|
|
dispatch(actions.saveAccountLabel(account, label))
|
|
|
|
},
|
2017-08-09 03:34:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 13:46:38 +02:00
|
|
|
inherits(EditAccountNameModal, Component)
|
2017-10-05 01:31:12 +02:00
|
|
|
function EditAccountNameModal (props) {
|
2017-08-09 03:34:04 +02:00
|
|
|
Component.call(this)
|
2017-10-05 01:31:12 +02:00
|
|
|
|
2017-08-21 13:46:38 +02:00
|
|
|
this.state = {
|
2017-10-05 01:31:12 +02:00
|
|
|
inputText: props.identity.name,
|
2017-08-21 13:46:38 +02:00
|
|
|
}
|
2017-08-09 03:34:04 +02:00
|
|
|
}
|
|
|
|
|
2017-08-21 13:46:38 +02:00
|
|
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(EditAccountNameModal)
|
2017-08-09 03:34:04 +02:00
|
|
|
|
2017-08-21 13:46:38 +02:00
|
|
|
EditAccountNameModal.prototype.render = function () {
|
|
|
|
const { hideModal, saveAccountLabel, identity } = this.props
|
|
|
|
|
2017-08-09 03:34:04 +02:00
|
|
|
return h('div', {}, [
|
2017-08-21 13:46:38 +02:00
|
|
|
h('div.flex-column.edit-account-name-modal-content', {
|
2017-08-09 03:34:04 +02:00
|
|
|
}, [
|
|
|
|
|
2017-08-21 13:53:30 +02:00
|
|
|
h('div.edit-account-name-modal-cancel', {
|
|
|
|
onClick: () => {
|
|
|
|
hideModal()
|
|
|
|
},
|
|
|
|
}, [
|
2017-08-21 13:46:38 +02:00
|
|
|
h('i.fa.fa-times'),
|
|
|
|
]),
|
2017-08-09 03:34:04 +02:00
|
|
|
|
2017-08-21 13:46:38 +02:00
|
|
|
h('div.edit-account-name-modal-title', {
|
2018-03-22 01:41:47 +01:00
|
|
|
}, [this.props.t('editAccountName')]),
|
2017-08-09 03:34:04 +02:00
|
|
|
|
2017-08-21 13:46:38 +02:00
|
|
|
h('input.edit-account-name-modal-input', {
|
|
|
|
placeholder: identity.name,
|
|
|
|
onChange: (event) => {
|
|
|
|
this.setState({ inputText: event.target.value })
|
|
|
|
},
|
|
|
|
value: this.state.inputText,
|
|
|
|
}, []),
|
2017-08-09 03:34:04 +02:00
|
|
|
|
2018-01-29 21:29:01 +01:00
|
|
|
h('button.btn-clear.edit-account-name-modal-save-button.allcaps', {
|
2017-08-21 13:46:38 +02:00
|
|
|
onClick: () => {
|
|
|
|
if (this.state.inputText.length !== 0) {
|
|
|
|
saveAccountLabel(identity.address, this.state.inputText)
|
|
|
|
hideModal()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
disabled: this.state.inputText.length === 0,
|
|
|
|
}, [
|
2018-03-22 01:41:47 +01:00
|
|
|
this.props.t('save'),
|
2017-08-09 03:34:04 +02:00
|
|
|
]),
|
|
|
|
|
2017-08-29 16:50:48 +02:00
|
|
|
]),
|
2017-08-09 03:34:04 +02:00
|
|
|
])
|
|
|
|
}
|