Provide default new account name

feature/default_network_editable
Alexander Tseung 7 years ago committed by Chi Kei Chan
parent 4e8d8639cb
commit 5d8b53bcf4
  1. 95
      ui/app/components/modals/new-account-modal.js

@ -1,52 +1,24 @@
const Component = require('react').Component const { Component } = require('react')
const PropTypes = require('prop-types')
const h = require('react-hyperscript') const h = require('react-hyperscript')
const inherits = require('util').inherits const { connect } = require('react-redux')
const connect = require('react-redux').connect
const actions = require('../../actions') const actions = require('../../actions')
function mapStateToProps (state) { class NewAccountModal extends Component {
return { constructor (props) {
network: state.metamask.network, super(props)
address: state.metamask.selectedAddress, const { numberOfExistingAccounts = 0 } = props
} const newAccountNumber = numberOfExistingAccounts + 1
}
function mapDispatchToProps (dispatch) {
return {
toCoinbase: (address) => {
dispatch(actions.buyEth({ network: '1', address, amount: 0 }))
},
hideModal: () => {
dispatch(actions.hideModal())
},
createAccount: (newAccountName) => {
dispatch(actions.addNewAccount())
.then((newAccountAddress) => {
if (newAccountName) {
dispatch(actions.saveAccountLabel(newAccountAddress, newAccountName))
}
dispatch(actions.hideModal())
})
},
showImportPage: () => dispatch(actions.showImportPage()),
}
}
inherits(NewAccountModal, Component)
function NewAccountModal () {
Component.call(this)
this.state = { this.state = {
newAccountName: '', newAccountName: `Account ${newAccountNumber}`,
}
} }
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(NewAccountModal)
NewAccountModal.prototype.render = function () { render () {
const { newAccountName } = this.state const { newAccountName } = this.state
return h('div', {}, [ return h('div', [
h('div.new-account-modal-wrapper', { h('div.new-account-modal-wrapper', {
}, [ }, [
h('div.new-account-modal-header', {}, [ h('div.new-account-modal-header', {}, [
@ -63,6 +35,7 @@ NewAccountModal.prototype.render = function () {
h('div.new-account-input-wrapper', {}, [ h('div.new-account-input-wrapper', {}, [
h('input.new-account-input', { h('input.new-account-input', {
value: this.state.newAccountName,
placeholder: 'E.g. My new account', placeholder: 'E.g. My new account',
onChange: event => this.setState({ newAccountName: event.target.value }), onChange: event => this.setState({ newAccountName: event.target.value }),
}, []), }, []),
@ -88,4 +61,46 @@ NewAccountModal.prototype.render = function () {
]), ]),
]), ]),
]) ])
}
} }
NewAccountModal.propTypes = {
hideModal: PropTypes.func,
showImportPage: PropTypes.func,
createAccount: PropTypes.func,
numberOfExistingAccounts: PropTypes.number,
}
const mapStateToProps = state => {
const { metamask: { network, selectedAddress, identities = {} } } = state
const numberOfExistingAccounts = Object.keys(identities).length
return {
network,
address: selectedAddress,
numberOfExistingAccounts,
}
}
const mapDispatchToProps = dispatch => {
return {
toCoinbase: (address) => {
dispatch(actions.buyEth({ network: '1', address, amount: 0 }))
},
hideModal: () => {
dispatch(actions.hideModal())
},
createAccount: (newAccountName) => {
dispatch(actions.addNewAccount())
.then((newAccountAddress) => {
if (newAccountName) {
dispatch(actions.saveAccountLabel(newAccountAddress, newAccountName))
}
dispatch(actions.hideModal())
})
},
showImportPage: () => dispatch(actions.showImportPage()),
}
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(NewAccountModal)

Loading…
Cancel
Save