mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Provide default new account name
This commit is contained in:
parent
4e8d8639cb
commit
5d8b53bcf4
@ -1,52 +1,24 @@
|
||||
const Component = require('react').Component
|
||||
const { Component } = require('react')
|
||||
const PropTypes = require('prop-types')
|
||||
const h = require('react-hyperscript')
|
||||
const inherits = require('util').inherits
|
||||
const connect = require('react-redux').connect
|
||||
const { connect } = require('react-redux')
|
||||
const actions = require('../../actions')
|
||||
|
||||
function mapStateToProps (state) {
|
||||
return {
|
||||
network: state.metamask.network,
|
||||
address: state.metamask.selectedAddress,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
class NewAccountModal extends Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
const { numberOfExistingAccounts = 0 } = props
|
||||
const newAccountNumber = numberOfExistingAccounts + 1
|
||||
|
||||
this.state = {
|
||||
newAccountName: '',
|
||||
newAccountName: `Account ${newAccountNumber}`,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = connect(mapStateToProps, mapDispatchToProps)(NewAccountModal)
|
||||
|
||||
NewAccountModal.prototype.render = function () {
|
||||
render () {
|
||||
const { newAccountName } = this.state
|
||||
|
||||
return h('div', {}, [
|
||||
return h('div', [
|
||||
h('div.new-account-modal-wrapper', {
|
||||
}, [
|
||||
h('div.new-account-modal-header', {}, [
|
||||
@ -63,6 +35,7 @@ NewAccountModal.prototype.render = function () {
|
||||
|
||||
h('div.new-account-input-wrapper', {}, [
|
||||
h('input.new-account-input', {
|
||||
value: this.state.newAccountName,
|
||||
placeholder: 'E.g. My new account',
|
||||
onChange: event => this.setState({ newAccountName: event.target.value }),
|
||||
}, []),
|
||||
@ -89,3 +62,45 @@ 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…
Reference in New Issue
Block a user