mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Get from and update addressBook in send-v2
This commit is contained in:
parent
4915aff750
commit
4f9ac1c4fe
@ -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) => {
|
||||
|
@ -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)),
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user