2019-10-29 17:12:41 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-01-09 04:34:58 +01:00
|
|
|
import * as actions from '../../store/actions'
|
2019-10-29 17:12:41 +01:00
|
|
|
import NewAccountCreateForm from './new-account.component'
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapStateToProps = (state) => {
|
2019-10-29 17:12:41 +01:00
|
|
|
const { metamask: { network, selectedAddress, identities = {} } } = state
|
|
|
|
const numberOfExistingAccounts = Object.keys(identities).length
|
|
|
|
const newAccountNumber = numberOfExistingAccounts + 1
|
|
|
|
|
|
|
|
return {
|
|
|
|
network,
|
|
|
|
address: selectedAddress,
|
|
|
|
newAccountNumber,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2019-10-29 17:12:41 +01:00
|
|
|
return {
|
2020-02-15 21:34:12 +01:00
|
|
|
createAccount: (newAccountName) => {
|
2019-10-29 17:12:41 +01:00
|
|
|
return dispatch(actions.addNewAccount())
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((newAccountAddress) => {
|
2019-10-29 17:12:41 +01:00
|
|
|
if (newAccountName) {
|
|
|
|
dispatch(actions.setAccountLabel(newAccountAddress, newAccountName))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(NewAccountCreateForm)
|