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'
|
2020-06-01 19:54:32 +02:00
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history'
|
2020-08-18 21:18:25 +02:00
|
|
|
import NewAccountCreateForm from './new-account.component'
|
2019-10-29 17:12:41 +01:00
|
|
|
|
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-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2019-10-29 17:12:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|