1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/app/components/modals/edit-account-name-modal.js
Dan J Miller 3b6e96bac9 Update hide-token-confirmation-modal.js to use new modalState schema (#4482)
* Update hide-token-confirmation-modal.js to use new modalState schema (added in 41e38fe55).

* Fix modalState props
2018-06-04 16:13:32 -07:00

84 lines
2.1 KiB
JavaScript

const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('react-redux').connect
const actions = require('../../actions')
const { getSelectedAccount } = require('../../selectors')
function mapStateToProps (state) {
return {
selectedAccount: getSelectedAccount(state),
identity: state.appState.modal.modalState.props.identity,
}
}
function mapDispatchToProps (dispatch) {
return {
hideModal: () => {
dispatch(actions.hideModal())
},
setAccountLabel: (account, label) => {
dispatch(actions.setAccountLabel(account, label))
},
}
}
inherits(EditAccountNameModal, Component)
function EditAccountNameModal (props) {
Component.call(this)
this.state = {
inputText: props.identity.name,
}
}
EditAccountNameModal.contextTypes = {
t: PropTypes.func,
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(EditAccountNameModal)
EditAccountNameModal.prototype.render = function () {
const { hideModal, setAccountLabel, identity } = this.props
return h('div', {}, [
h('div.flex-column.edit-account-name-modal-content', {
}, [
h('div.edit-account-name-modal-cancel', {
onClick: () => {
hideModal()
},
}, [
h('i.fa.fa-times'),
]),
h('div.edit-account-name-modal-title', {
}, [this.context.t('editAccountName')]),
h('input.edit-account-name-modal-input', {
placeholder: identity.name,
onChange: (event) => {
this.setState({ inputText: event.target.value })
},
value: this.state.inputText,
}, []),
h('button.btn-clear.edit-account-name-modal-save-button.allcaps', {
onClick: () => {
if (this.state.inputText.length !== 0) {
setAccountLabel(identity.address, this.state.inputText)
hideModal()
}
},
disabled: this.state.inputText.length === 0,
}, [
this.context.t('save'),
]),
]),
])
}