mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +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),
|
whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),
|
||||||
|
|
||||||
// AddressController
|
// AddressController
|
||||||
setAddressBook: this.addressBookController.set.bind(this.addressBookController),
|
setAddressBook: nodeify(this.addressBookController.set, this.addressBookController),
|
||||||
removeFromAddressBook: this.addressBookController.delete.bind(this.addressBookController),
|
removeFromAddressBook: this.addressBookController.delete.bind(this.addressBookController),
|
||||||
|
|
||||||
// AppStateController
|
// AppStateController
|
||||||
|
@ -30,10 +30,10 @@ export default class EnsInput extends Component {
|
|||||||
updateEnsResolution: PropTypes.func,
|
updateEnsResolution: PropTypes.func,
|
||||||
scanQrCode: PropTypes.func,
|
scanQrCode: PropTypes.func,
|
||||||
updateEnsResolutionError: PropTypes.func,
|
updateEnsResolutionError: PropTypes.func,
|
||||||
addressBook: PropTypes.array,
|
|
||||||
onPaste: PropTypes.func,
|
onPaste: PropTypes.func,
|
||||||
onReset: PropTypes.func,
|
onReset: PropTypes.func,
|
||||||
onValidAddressTyped: PropTypes.func,
|
onValidAddressTyped: PropTypes.func,
|
||||||
|
contact: PropTypes.object,
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -181,8 +181,7 @@ export default class EnsInput extends Component {
|
|||||||
|
|
||||||
renderSelected () {
|
renderSelected () {
|
||||||
const { t } = this.context
|
const { t } = this.context
|
||||||
const { className, selectedAddress, selectedName, addressBook } = this.props
|
const { className, selectedAddress, selectedName, contact = {} } = this.props
|
||||||
const contact = addressBook.filter(item => item.address === selectedAddress)[0] || {}
|
|
||||||
const name = contact.name || selectedName
|
const name = contact.name || selectedName
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,16 +5,19 @@ import {
|
|||||||
getSendToNickname,
|
getSendToNickname,
|
||||||
} from '../../send.selectors'
|
} from '../../send.selectors'
|
||||||
import {
|
import {
|
||||||
getAddressBook,
|
getAddressBookEntry,
|
||||||
} from '../../../../selectors/selectors'
|
} from '../../../../selectors/selectors'
|
||||||
const connect = require('react-redux').connect
|
const connect = require('react-redux').connect
|
||||||
|
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
state => ({
|
state => {
|
||||||
network: getCurrentNetwork(state),
|
const selectedAddress = getSendTo(state)
|
||||||
selectedAddress: getSendTo(state),
|
return {
|
||||||
selectedName: getSendToNickname(state),
|
network: getCurrentNetwork(state),
|
||||||
addressBook: getAddressBook(state),
|
selectedAddress,
|
||||||
})
|
selectedName: getSendToNickname(state),
|
||||||
|
contact: getAddressBookEntry(state, selectedAddress),
|
||||||
|
}
|
||||||
|
}
|
||||||
)(EnsInput)
|
)(EnsInput)
|
||||||
|
@ -18,9 +18,10 @@ export default class SendContent extends Component {
|
|||||||
scanQrCode: PropTypes.func,
|
scanQrCode: PropTypes.func,
|
||||||
showAddToAddressBookModal: PropTypes.func,
|
showAddToAddressBookModal: PropTypes.func,
|
||||||
showHexData: PropTypes.bool,
|
showHexData: PropTypes.bool,
|
||||||
to: PropTypes.string,
|
|
||||||
ownedAccounts: PropTypes.array,
|
ownedAccounts: PropTypes.array,
|
||||||
addressBook: PropTypes.array,
|
addressBook: PropTypes.array,
|
||||||
|
contact: PropTypes.object,
|
||||||
|
isOwnedAccount: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGas = (updateData) => this.props.updateGas(updateData)
|
updateGas = (updateData) => this.props.updateGas(updateData)
|
||||||
@ -47,9 +48,7 @@ export default class SendContent extends Component {
|
|||||||
|
|
||||||
maybeRenderAddContact () {
|
maybeRenderAddContact () {
|
||||||
const { t } = this.context
|
const { t } = this.context
|
||||||
const { to, addressBook = [], ownedAccounts = [], showAddToAddressBookModal } = this.props
|
const { isOwnedAccount, showAddToAddressBookModal, contact = {} } = this.props
|
||||||
const isOwnedAccount = !!ownedAccounts.find(({ address }) => address.toLowerCase() === to.toLowerCase())
|
|
||||||
const contact = addressBook.find(({ address }) => address === to) || {}
|
|
||||||
|
|
||||||
if (isOwnedAccount || contact.name) {
|
if (isOwnedAccount || contact.name) {
|
||||||
return
|
return
|
||||||
|
@ -5,15 +5,17 @@ import {
|
|||||||
getSendTo,
|
getSendTo,
|
||||||
} from '../send.selectors'
|
} from '../send.selectors'
|
||||||
import {
|
import {
|
||||||
getAddressBook,
|
getAddressBookEntry,
|
||||||
} from '../../../selectors/selectors'
|
} from '../../../selectors/selectors'
|
||||||
import actions from '../../../store/actions'
|
import actions from '../../../store/actions'
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
|
const ownedAccounts = accountsWithSendEtherInfoSelector(state)
|
||||||
|
const to = getSendTo(state)
|
||||||
return {
|
return {
|
||||||
to: getSendTo(state),
|
isOwnedAccount: !!ownedAccounts.find(({ address }) => address.toLowerCase() === to.toLowerCase()),
|
||||||
addressBook: getAddressBook(state),
|
contact: getAddressBookEntry(state, to),
|
||||||
ownedAccounts: accountsWithSendEtherInfoSelector(state),
|
to,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,11 +52,10 @@ describe('SendContent Component', function () {
|
|||||||
assert.equal(PageContainerContentChild.childAt(4).exists(), false)
|
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({
|
wrapper.setProps({
|
||||||
showHexData: false,
|
showHexData: false,
|
||||||
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
contact: { name: 'testName' },
|
||||||
addressBook: [{ address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510', name: 'dinodan' }],
|
|
||||||
})
|
})
|
||||||
const PageContainerContentChild = wrapper.find(PageContainerContent).children()
|
const PageContainerContentChild = wrapper.find(PageContainerContent).children()
|
||||||
assert(PageContainerContentChild.childAt(0).is(SendAssetRow), 'row[1] should be SendAssetRow')
|
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)
|
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({
|
wrapper.setProps({
|
||||||
showHexData: false,
|
showHexData: false,
|
||||||
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
isOwnedAccount: true,
|
||||||
addressBook: [],
|
|
||||||
ownedAccounts: [{ address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510', name: 'dinodan' }],
|
|
||||||
})
|
})
|
||||||
const PageContainerContentChild = wrapper.find(PageContainerContent).children()
|
const PageContainerContentChild = wrapper.find(PageContainerContent).children()
|
||||||
assert(PageContainerContentChild.childAt(0).is(SendAssetRow), 'row[1] should be SendAssetRow')
|
assert(PageContainerContentChild.childAt(0).is(SendAssetRow), 'row[1] should be SendAssetRow')
|
||||||
|
@ -11,6 +11,7 @@ const {
|
|||||||
} = require('../helpers/utils/conversion-util')
|
} = require('../helpers/utils/conversion-util')
|
||||||
import {
|
import {
|
||||||
addressSlicer,
|
addressSlicer,
|
||||||
|
checksumAddress,
|
||||||
} from '../helpers/utils/util'
|
} from '../helpers/utils/util'
|
||||||
|
|
||||||
const selectors = {
|
const selectors = {
|
||||||
@ -217,7 +218,7 @@ function getAddressBook (state) {
|
|||||||
|
|
||||||
function getAddressBookEntry (state, address) {
|
function getAddressBookEntry (state, address) {
|
||||||
const addressBook = getAddressBook(state)
|
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
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1956,10 +1956,17 @@ function addToAddressBook (recipient, nickname = '', memo = '') {
|
|||||||
|
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const chainId = getState().metamask.network
|
const chainId = getState().metamask.network
|
||||||
const set = background.setAddressBook(checksumAddress(recipient), nickname, chainId, memo)
|
background.setAddressBook(checksumAddress(recipient), nickname, chainId, memo, (err, set) => {
|
||||||
if (!set) {
|
if (err) {
|
||||||
return dispatch(displayWarning('Address book failed to update'))
|
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