diff options
-rw-r--r-- | ui/app/actions.js | 2 | ||||
-rw-r--r-- | ui/app/components/send/send-v2-container.js | 12 | ||||
-rw-r--r-- | ui/app/selectors.js | 5 | ||||
-rw-r--r-- | ui/app/send-v2.js | 19 |
4 files changed, 29 insertions, 9 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 7ac0acf05..2fbd578c5 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -934,7 +934,7 @@ function setRpcTarget (newRpc) { } // Calls the addressBookController to add a new address. -function addToAddressBook (recipient, nickname) { +function addToAddressBook (recipient, nickname = '') { log.debug(`background.addToAddressBook`) return (dispatch) => { background.setAddressBook(recipient, nickname, (err, result) => { diff --git a/ui/app/components/send/send-v2-container.js b/ui/app/components/send/send-v2-container.js index 5935a8fee..8ac5cc961 100644 --- a/ui/app/components/send/send-v2-container.js +++ b/ui/app/components/send/send-v2-container.js @@ -14,13 +14,15 @@ const { getSelectedAddress, getGasPrice, getGasLimit, + getAddressBook, } = require('../../selectors') module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther) function mapStateToProps (state) { - const selectedAddress = getSelectedAddress(state); - const selectedToken = getSelectedToken(state); + const fromAccounts = accountsWithSendEtherInfoSelector(state) + const selectedAddress = getSelectedAddress(state) + const selectedToken = getSelectedToken(state) const tokenExchangeRates = state.metamask.tokenExchangeRates const selectedTokenExchangeRate = getSelectedTokenExchangeRate(state) const conversionRate = conversionRateSelector(state) @@ -45,7 +47,8 @@ function mapStateToProps (state) { return { selectedAccount: getCurrentAccountWithSendEtherInfo(state), - accounts: accountsWithSendEtherInfoSelector(state), + fromAccounts, + toAccounts: [...fromAccounts, ...getAddressBook(state)], conversionRate, selectedToken, primaryCurrency, @@ -66,6 +69,7 @@ function mapDispatchToProps (dispatch) { dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData)) ), signTx: txParams => dispatch(actions.signTx(txParams)), - setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)) + setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)), + addToAddressBook: address => dispatch(actions.addToAddressBook(address)), } } diff --git a/ui/app/selectors.js b/ui/app/selectors.js index bf3d3399e..fffe7dd61 100644 --- a/ui/app/selectors.js +++ b/ui/app/selectors.js @@ -12,6 +12,7 @@ const selectors = { getCurrentAccountWithSendEtherInfo, getGasPrice, getGasLimit, + getAddressBook, } module.exports = selectors @@ -59,6 +60,10 @@ function conversionRateSelector (state) { return state.metamask.conversionRate } +function getAddressBook (state) { + return state.metamask.addressBook +} + function accountsWithSendEtherInfoSelector (state) { const { accounts, diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 9f91af0e1..c41ba9758 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -122,7 +122,7 @@ SendTransactionScreen.prototype.renderHeader = function () { SendTransactionScreen.prototype.renderFromRow = function () { const { - accounts, + fromAccounts, conversionRate, selectedAccount, setSelectedAddress, @@ -136,7 +136,7 @@ SendTransactionScreen.prototype.renderFromRow = function () { h(FromDropdown, { dropdownOpen, - accounts, + accounts: fromAccounts, selectedAccount, onSelect: address => setSelectedAddress(address), openDropdown: () => this.setState({ dropdownOpen: true }), @@ -157,7 +157,7 @@ SendTransactionScreen.prototype.handleToChange = function (event) { } SendTransactionScreen.prototype.renderToRow = function () { - const { accounts } = this.props + const { toAccounts } = this.props const { to } = this.state return h('div.send-v2__form-row', [ @@ -166,7 +166,7 @@ SendTransactionScreen.prototype.renderToRow = function () { h(ToAutoComplete, { to, - accounts, + accounts: toAccounts, 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) { event.preventDefault() const { @@ -315,8 +323,11 @@ SendTransactionScreen.prototype.onSubmit = function (event) { signTx, selectedToken, selectedAccount: { address: from }, + toAccounts, } = this.props + this.addToAddressBookIfNew(to) + const txParams = { from, value: '0', |