1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-18 15:33:21 +01:00
metamask-extension/ui/app/components/modals/new-account-modal.js

113 lines
3.0 KiB
JavaScript
Raw Normal View History

2017-10-26 20:36:13 +02:00
const { Component } = require('react')
const PropTypes = require('prop-types')
2017-08-21 04:28:20 +02:00
const h = require('react-hyperscript')
const connect = require('react-redux').connect
2017-08-21 04:28:20 +02:00
const actions = require('../../actions')
2017-10-26 20:36:13 +02:00
class NewAccountModal extends Component {
constructor (props) {
super(props)
const { numberOfExistingAccounts = 0 } = props
const newAccountNumber = numberOfExistingAccounts + 1
this.state = {
newAccountName: `${this.context.t('account')} ${newAccountNumber}`,
2017-10-26 20:36:13 +02:00
}
}
render () {
const { newAccountName } = this.state
return h('div', [
h('div.new-account-modal-wrapper', {
}, [
h('div.new-account-modal-header', {}, [
this.context.t('newAccount'),
2017-10-26 20:36:13 +02:00
]),
h('div.modal-close-x', {
onClick: this.props.hideModal,
}),
h('div.new-account-modal-content', {}, [
this.context.t('accountName'),
2017-10-26 20:36:13 +02:00
]),
h('div.new-account-input-wrapper', {}, [
h('input.new-account-input', {
value: this.state.newAccountName,
placeholder: this.context.t('sampleAccountName'),
2017-10-26 20:36:13 +02:00
onChange: event => this.setState({ newAccountName: event.target.value }),
}, []),
]),
h('div.new-account-modal-content.after-input', {}, [
this.context.t('or'),
2017-10-26 20:36:13 +02:00
]),
h('div.new-account-modal-content.after-input.pointer', {
onClick: () => {
this.props.hideModal()
this.props.showImportPage()
},
}, this.context.t('importAnAccount')),
2017-10-26 20:36:13 +02:00
2018-01-29 21:29:01 +01:00
h('div.new-account-modal-content.button.allcaps', {}, [
2017-10-26 20:36:13 +02:00
h('button.btn-clear', {
onClick: () => this.props.createAccount(newAccountName),
}, [
this.context.t('save'),
2017-10-26 20:36:13 +02:00
]),
]),
]),
])
}
}
NewAccountModal.propTypes = {
hideModal: PropTypes.func,
showImportPage: PropTypes.func,
createAccount: PropTypes.func,
numberOfExistingAccounts: PropTypes.number,
2018-03-22 03:18:10 +01:00
t: PropTypes.func,
2017-10-26 20:36:13 +02:00
}
const mapStateToProps = state => {
const { metamask: { network, selectedAddress, identities = {} } } = state
const numberOfExistingAccounts = Object.keys(identities).length
2017-08-21 04:28:20 +02:00
return {
2017-10-26 20:36:13 +02:00
network,
address: selectedAddress,
numberOfExistingAccounts,
2017-08-21 04:28:20 +02:00
}
}
2017-10-26 20:36:13 +02:00
const mapDispatchToProps = dispatch => {
2017-08-21 04:28:20 +02:00
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()),
2017-08-21 04:28:20 +02:00
}
}
NewAccountModal.contextTypes = {
t: PropTypes.func,
}
2017-08-21 15:14:28 +02:00
module.exports = connect(mapStateToProps, mapDispatchToProps)(NewAccountModal)