mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Address book fixes (#6978)
* Ensure address book send flow correctly matches address book addresses to ens addresses * Use nodify on background.setAddressBook to receive correct result in actions.js * Better error handling for actions.js addToAddressBook * Eliminate unnecessary data normalization and move more data manipluation to ens-input and send-content containers
This commit is contained in:
parent
6bc1077880
commit
043920c9ff
@ -464,7 +464,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),
|
||||
|
||||
// AddressController
|
||||
setAddressBook: this.addressBookController.set.bind(this.addressBookController),
|
||||
setAddressBook: nodeify(this.addressBookController.set, this.addressBookController),
|
||||
removeFromAddressBook: this.addressBookController.delete.bind(this.addressBookController),
|
||||
|
||||
// AppStateController
|
||||
|
@ -30,10 +30,10 @@ export default class EnsInput extends Component {
|
||||
updateEnsResolution: PropTypes.func,
|
||||
scanQrCode: PropTypes.func,
|
||||
updateEnsResolutionError: PropTypes.func,
|
||||
addressBook: PropTypes.array,
|
||||
onPaste: PropTypes.func,
|
||||
onReset: PropTypes.func,
|
||||
onValidAddressTyped: PropTypes.func,
|
||||
contact: PropTypes.object,
|
||||
}
|
||||
|
||||
state = {
|
||||
@ -181,8 +181,7 @@ export default class EnsInput extends Component {
|
||||
|
||||
renderSelected () {
|
||||
const { t } = this.context
|
||||
const { className, selectedAddress, selectedName, addressBook } = this.props
|
||||
const contact = addressBook.filter(item => item.address === selectedAddress)[0] || {}
|
||||
const { className, selectedAddress, selectedName, contact = {} } = this.props
|
||||
const name = contact.name || selectedName
|
||||
|
||||
|
||||
|
@ -5,16 +5,19 @@ import {
|
||||
getSendToNickname,
|
||||
} from '../../send.selectors'
|
||||
import {
|
||||
getAddressBook,
|
||||
getAddressBookEntry,
|
||||
} from '../../../../selectors/selectors'
|
||||
const connect = require('react-redux').connect
|
||||
|
||||
|
||||
export default connect(
|
||||
state => ({
|
||||
network: getCurrentNetwork(state),
|
||||
selectedAddress: getSendTo(state),
|
||||
selectedName: getSendToNickname(state),
|
||||
addressBook: getAddressBook(state),
|
||||
})
|
||||
state => {
|
||||
const selectedAddress = getSendTo(state)
|
||||
return {
|
||||
network: getCurrentNetwork(state),
|
||||
selectedAddress,
|
||||
selectedName: getSendToNickname(state),
|
||||
contact: getAddressBookEntry(state, selectedAddress),
|
||||
}
|
||||
}
|
||||
)(EnsInput)
|
||||
|
@ -18,9 +18,10 @@ export default class SendContent extends Component {
|
||||
scanQrCode: PropTypes.func,
|
||||
showAddToAddressBookModal: PropTypes.func,
|
||||
showHexData: PropTypes.bool,
|
||||
to: PropTypes.string,
|
||||
ownedAccounts: PropTypes.array,
|
||||
addressBook: PropTypes.array,
|
||||
contact: PropTypes.object,
|
||||
isOwnedAccount: PropTypes.bool,
|
||||
}
|
||||
|
||||
updateGas = (updateData) => this.props.updateGas(updateData)
|
||||
@ -47,9 +48,7 @@ export default class SendContent extends Component {
|
||||
|
||||
maybeRenderAddContact () {
|
||||
const { t } = this.context
|
||||
const { to, addressBook = [], ownedAccounts = [], showAddToAddressBookModal } = this.props
|
||||
const isOwnedAccount = !!ownedAccounts.find(({ address }) => address.toLowerCase() === to.toLowerCase())
|
||||
const contact = addressBook.find(({ address }) => address === to) || {}
|
||||
const { isOwnedAccount, showAddToAddressBookModal, contact = {} } = this.props
|
||||
|
||||
if (isOwnedAccount || contact.name) {
|
||||
return
|
||||
|
@ -5,15 +5,17 @@ import {
|
||||
getSendTo,
|
||||
} from '../send.selectors'
|
||||
import {
|
||||
getAddressBook,
|
||||
getAddressBookEntry,
|
||||
} from '../../../selectors/selectors'
|
||||
import actions from '../../../store/actions'
|
||||
|
||||
function mapStateToProps (state) {
|
||||
const ownedAccounts = accountsWithSendEtherInfoSelector(state)
|
||||
const to = getSendTo(state)
|
||||
return {
|
||||
to: getSendTo(state),
|
||||
addressBook: getAddressBook(state),
|
||||
ownedAccounts: accountsWithSendEtherInfoSelector(state),
|
||||
isOwnedAccount: !!ownedAccounts.find(({ address }) => address.toLowerCase() === to.toLowerCase()),
|
||||
contact: getAddressBookEntry(state, to),
|
||||
to,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,10 @@ describe('SendContent Component', function () {
|
||||
assert.equal(PageContainerContentChild.childAt(4).exists(), false)
|
||||
})
|
||||
|
||||
it('should not render the Dialog if addressBook contains "to" address', () => {
|
||||
it('should not render the Dialog if contact has a name', () => {
|
||||
wrapper.setProps({
|
||||
showHexData: false,
|
||||
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
||||
addressBook: [{ address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510', name: 'dinodan' }],
|
||||
contact: { name: 'testName' },
|
||||
})
|
||||
const PageContainerContentChild = wrapper.find(PageContainerContent).children()
|
||||
assert(PageContainerContentChild.childAt(0).is(SendAssetRow), 'row[1] should be SendAssetRow')
|
||||
@ -65,12 +64,10 @@ describe('SendContent Component', function () {
|
||||
assert.equal(PageContainerContentChild.childAt(3).exists(), false)
|
||||
})
|
||||
|
||||
it('should not render the Dialog if ownedAccounts contains "to" address', () => {
|
||||
it('should not render the Dialog if it is an ownedAccount', () => {
|
||||
wrapper.setProps({
|
||||
showHexData: false,
|
||||
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
||||
addressBook: [],
|
||||
ownedAccounts: [{ address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510', name: 'dinodan' }],
|
||||
isOwnedAccount: true,
|
||||
})
|
||||
const PageContainerContentChild = wrapper.find(PageContainerContent).children()
|
||||
assert(PageContainerContentChild.childAt(0).is(SendAssetRow), 'row[1] should be SendAssetRow')
|
||||
|
@ -11,6 +11,7 @@ const {
|
||||
} = require('../helpers/utils/conversion-util')
|
||||
import {
|
||||
addressSlicer,
|
||||
checksumAddress,
|
||||
} from '../helpers/utils/util'
|
||||
|
||||
const selectors = {
|
||||
@ -217,7 +218,7 @@ function getAddressBook (state) {
|
||||
|
||||
function getAddressBookEntry (state, address) {
|
||||
const addressBook = getAddressBook(state)
|
||||
const entry = addressBook.find(contact => contact.address.toLowerCase() === address.toLowerCase())
|
||||
const entry = addressBook.find(contact => contact.address === checksumAddress(address))
|
||||
return entry
|
||||
}
|
||||
|
||||
|
@ -1956,10 +1956,17 @@ function addToAddressBook (recipient, nickname = '', memo = '') {
|
||||
|
||||
return (dispatch, getState) => {
|
||||
const chainId = getState().metamask.network
|
||||
const set = background.setAddressBook(checksumAddress(recipient), nickname, chainId, memo)
|
||||
if (!set) {
|
||||
return dispatch(displayWarning('Address book failed to update'))
|
||||
}
|
||||
background.setAddressBook(checksumAddress(recipient), nickname, chainId, memo, (err, set) => {
|
||||
if (err) {
|
||||
log.error(err)
|
||||
dispatch(displayWarning('Address book failed to update'))
|
||||
throw err
|
||||
}
|
||||
if (!set) {
|
||||
return dispatch(displayWarning('Address book failed to update'))
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user