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

Get from and update addressBook in send-v2

This commit is contained in:
Dan 2017-10-17 13:16:36 -02:30 committed by Chi Kei Chan
parent 4915aff750
commit 4f9ac1c4fe
4 changed files with 29 additions and 9 deletions

View File

@ -934,7 +934,7 @@ function setRpcTarget (newRpc) {
} }
// Calls the addressBookController to add a new address. // Calls the addressBookController to add a new address.
function addToAddressBook (recipient, nickname) { function addToAddressBook (recipient, nickname = '') {
log.debug(`background.addToAddressBook`) log.debug(`background.addToAddressBook`)
return (dispatch) => { return (dispatch) => {
background.setAddressBook(recipient, nickname, (err, result) => { background.setAddressBook(recipient, nickname, (err, result) => {

View File

@ -14,13 +14,15 @@ const {
getSelectedAddress, getSelectedAddress,
getGasPrice, getGasPrice,
getGasLimit, getGasLimit,
getAddressBook,
} = require('../../selectors') } = require('../../selectors')
module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther) module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther)
function mapStateToProps (state) { function mapStateToProps (state) {
const selectedAddress = getSelectedAddress(state); const fromAccounts = accountsWithSendEtherInfoSelector(state)
const selectedToken = getSelectedToken(state); const selectedAddress = getSelectedAddress(state)
const selectedToken = getSelectedToken(state)
const tokenExchangeRates = state.metamask.tokenExchangeRates const tokenExchangeRates = state.metamask.tokenExchangeRates
const selectedTokenExchangeRate = getSelectedTokenExchangeRate(state) const selectedTokenExchangeRate = getSelectedTokenExchangeRate(state)
const conversionRate = conversionRateSelector(state) const conversionRate = conversionRateSelector(state)
@ -45,7 +47,8 @@ function mapStateToProps (state) {
return { return {
selectedAccount: getCurrentAccountWithSendEtherInfo(state), selectedAccount: getCurrentAccountWithSendEtherInfo(state),
accounts: accountsWithSendEtherInfoSelector(state), fromAccounts,
toAccounts: [...fromAccounts, ...getAddressBook(state)],
conversionRate, conversionRate,
selectedToken, selectedToken,
primaryCurrency, primaryCurrency,
@ -66,6 +69,7 @@ function mapDispatchToProps (dispatch) {
dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData)) dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData))
), ),
signTx: txParams => dispatch(actions.signTx(txParams)), signTx: txParams => dispatch(actions.signTx(txParams)),
setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)) setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)),
addToAddressBook: address => dispatch(actions.addToAddressBook(address)),
} }
} }

View File

@ -12,6 +12,7 @@ const selectors = {
getCurrentAccountWithSendEtherInfo, getCurrentAccountWithSendEtherInfo,
getGasPrice, getGasPrice,
getGasLimit, getGasLimit,
getAddressBook,
} }
module.exports = selectors module.exports = selectors
@ -59,6 +60,10 @@ function conversionRateSelector (state) {
return state.metamask.conversionRate return state.metamask.conversionRate
} }
function getAddressBook (state) {
return state.metamask.addressBook
}
function accountsWithSendEtherInfoSelector (state) { function accountsWithSendEtherInfoSelector (state) {
const { const {
accounts, accounts,

View File

@ -122,7 +122,7 @@ SendTransactionScreen.prototype.renderHeader = function () {
SendTransactionScreen.prototype.renderFromRow = function () { SendTransactionScreen.prototype.renderFromRow = function () {
const { const {
accounts, fromAccounts,
conversionRate, conversionRate,
selectedAccount, selectedAccount,
setSelectedAddress, setSelectedAddress,
@ -136,7 +136,7 @@ SendTransactionScreen.prototype.renderFromRow = function () {
h(FromDropdown, { h(FromDropdown, {
dropdownOpen, dropdownOpen,
accounts, accounts: fromAccounts,
selectedAccount, selectedAccount,
onSelect: address => setSelectedAddress(address), onSelect: address => setSelectedAddress(address),
openDropdown: () => this.setState({ dropdownOpen: true }), openDropdown: () => this.setState({ dropdownOpen: true }),
@ -157,7 +157,7 @@ SendTransactionScreen.prototype.handleToChange = function (event) {
} }
SendTransactionScreen.prototype.renderToRow = function () { SendTransactionScreen.prototype.renderToRow = function () {
const { accounts } = this.props const { toAccounts } = this.props
const { to } = this.state const { to } = this.state
return h('div.send-v2__form-row', [ return h('div.send-v2__form-row', [
@ -166,7 +166,7 @@ SendTransactionScreen.prototype.renderToRow = function () {
h(ToAutoComplete, { h(ToAutoComplete, {
to, to,
accounts, accounts: toAccounts,
onChange: this.handleToChange, onChange: this.handleToChange,
}), }),
@ -302,6 +302,14 @@ SendTransactionScreen.prototype.render = function () {
) )
} }
SendTransactionScreen.prototype.addToAddressBookIfNew = function (newAddress) {
const { toAccounts, addToAddressBook } = this.props
if (!toAccounts.find(({ address }) => newAddress === address)) {
// TODO: nickname, i.e. addToAddressBook(recipient, nickname)
addToAddressBook(newAddress)
}
}
SendTransactionScreen.prototype.onSubmit = function (event) { SendTransactionScreen.prototype.onSubmit = function (event) {
event.preventDefault() event.preventDefault()
const { const {
@ -315,8 +323,11 @@ SendTransactionScreen.prototype.onSubmit = function (event) {
signTx, signTx,
selectedToken, selectedToken,
selectedAccount: { address: from }, selectedAccount: { address: from },
toAccounts,
} = this.props } = this.props
this.addToAddressBookIfNew(to)
const txParams = { const txParams = {
from, from,
value: '0', value: '0',