1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

New account modal now allows for addition of account name.

This commit is contained in:
Dan 2017-09-22 04:29:27 -02:30 committed by Chi Kei Chan
parent e325e5e2f5
commit a1d72a59fe
3 changed files with 35 additions and 7 deletions

View File

@ -349,9 +349,25 @@ function navigateToNewAccountScreen () {
} }
} }
function addNewAccount () { function addNewAccount (oldIdentities) {
log.debug(`background.addNewAccount`) log.debug(`background.addNewAccount`)
return callBackgroundThenUpdate(background.addNewAccount) return (dispatch) => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
background.addNewAccount((err, { identities: newIdentities}) => {
if (err) {
dispatch(actions.displayWarning(err.message))
return reject(err)
}
const newAccountAddress = Object.keys(newIdentities).find(address => !oldIdentities[address])
dispatch(actions.hideLoadingIndication())
forceUpdateMetamaskState(dispatch)
return resolve(newAccountAddress)
})
});
}
} }
function showInfoPage () { function showInfoPage () {

View File

@ -8,6 +8,7 @@ function mapStateToProps (state) {
return { return {
network: state.metamask.network, network: state.metamask.network,
address: state.metamask.selectedAddress, address: state.metamask.selectedAddress,
identities: state.metamask.identities,
} }
} }
@ -19,9 +20,12 @@ function mapDispatchToProps (dispatch) {
hideModal: () => { hideModal: () => {
dispatch(actions.hideModal()) dispatch(actions.hideModal())
}, },
createAccount: () => { createAccount: (identities, newAccountName) => {
dispatch(actions.addNewAccount()) dispatch(actions.addNewAccount(identities))
.then((newAccountAddress) => {
dispatch(actions.saveAccountLabel(newAccountAddress, newAccountName))
dispatch(actions.hideModal()) dispatch(actions.hideModal())
})
}, },
} }
} }
@ -29,11 +33,18 @@ function mapDispatchToProps (dispatch) {
inherits(NewAccountModal, Component) inherits(NewAccountModal, Component)
function NewAccountModal () { function NewAccountModal () {
Component.call(this) Component.call(this)
this.state = {
newAccountName: ''
}
} }
module.exports = connect(mapStateToProps, mapDispatchToProps)(NewAccountModal) module.exports = connect(mapStateToProps, mapDispatchToProps)(NewAccountModal)
NewAccountModal.prototype.render = function () { NewAccountModal.prototype.render = function () {
const { identities } = this.props
const { newAccountName } = this.state
return h('div', {}, [ return h('div', {}, [
h('div.new-account-modal-wrapper', { h('div.new-account-modal-wrapper', {
}, [ }, [
@ -52,6 +63,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', {
placeholder: 'E.g. My new account', placeholder: 'E.g. My new account',
onChange: (event) => this.setState({ newAccountName: event.target.value })
}, []), }, []),
]), ]),
@ -65,7 +77,7 @@ NewAccountModal.prototype.render = function () {
h('div.new-account-modal-content.button', {}, [ h('div.new-account-modal-content.button', {}, [
h('button.btn-clear', { h('button.btn-clear', {
onClick: this.props.createAccount onClick: () => this.props.createAccount(identities, newAccountName)
}, [ }, [
'SAVE', 'SAVE',
]), ]),

View File

@ -325,7 +325,7 @@
border: 1px solid $alto; border: 1px solid $alto;
width: 100%; width: 100%;
font-size: 1em; font-size: 1em;
color: $alto; color: $dusty-gray;
font-family: Montserrat Light; font-family: Montserrat Light;
font-size: 17px; font-size: 17px;
margin: 0 60px; margin: 0 60px;