From 08ddd4fb0c470d3af415de63240288dd96ab998c Mon Sep 17 00:00:00 2001 From: amerkadicE <97883527+amerkadicE@users.noreply.github.com> Date: Wed, 30 Nov 2022 16:24:28 +0100 Subject: [PATCH] Show account name when qr scan in send screen (#16204) Co-authored-by: Brad Decker --- ui/ducks/send/send.test.js | 27 ++++++++++++++++++++++++--- ui/selectors/selectors.js | 12 +++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ui/ducks/send/send.test.js b/ui/ducks/send/send.test.js index 658070c08..50613b89b 100644 --- a/ui/ducks/send/send.test.js +++ b/ui/ducks/send/send.test.js @@ -3114,7 +3114,14 @@ describe('Send Slice', () => { expect( getSendTo({ send: INITIAL_SEND_STATE_FOR_EXISTING_DRAFT, - metamask: { ensResolutionsByAddress: {} }, + metamask: { + ensResolutionsByAddress: {}, + identities: {}, + addressBook: {}, + provider: { + chainId: '0x5', + }, + }, }), ).toBe(''); expect( @@ -3122,7 +3129,14 @@ describe('Send Slice', () => { send: getInitialSendStateWithExistingTxState({ recipient: { address: '0xb' }, }), - metamask: { ensResolutionsByAddress: {} }, + metamask: { + ensResolutionsByAddress: {}, + addressBook: {}, + identities: {}, + provider: { + chainId: '0x5', + }, + }, }), ).toBe('0xb'); }); @@ -3163,7 +3177,14 @@ describe('Send Slice', () => { expect( getRecipient({ send: INITIAL_SEND_STATE_FOR_EXISTING_DRAFT, - metamask: { ensResolutionsByAddress: {} }, + metamask: { + ensResolutionsByAddress: {}, + identities: {}, + addressBook: {}, + provider: { + chainId: '0x5', + }, + }, }), ).toMatchObject( getTestUUIDTx(INITIAL_SEND_STATE_FOR_EXISTING_DRAFT).recipient, diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 07290eab2..81ec3cf05 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -392,7 +392,17 @@ export function getAddressBook(state) { } export function getEnsResolutionByAddress(state, address) { - return state.metamask.ensResolutionsByAddress[address] || ''; + if (state.metamask.ensResolutionsByAddress[address]) { + return state.metamask.ensResolutionsByAddress[address]; + } + + const entry = + getAddressBookEntry(state, address) || + Object.values(state.metamask.identities).find((identity) => + isEqualCaseInsensitive(identity.address, toChecksumHexAddress(address)), + ); + + return entry?.name || ''; } export function getAddressBookEntry(state, address) {