diff --git a/ui/components/ui/account-list/account-list.js b/ui/components/ui/account-list/account-list.js index 30fb5c7fc87d..45c789f7a6a9 100644 --- a/ui/components/ui/account-list/account-list.js +++ b/ui/components/ui/account-list/account-list.js @@ -136,6 +136,7 @@ const AccountList = ({ display={Display.Flex} width={BlockSize.Full} key={`choose-account-list-${index}`} + data-testid={`choose-account-list-${index}`} onClick={() => handleEVMAccountClick(account)} className="choose-account-list__account" ref={ diff --git a/ui/components/ui/account-list/account-list.test.js b/ui/components/ui/account-list/account-list.test.js index bf88efc7358b..5ee5feb5c303 100644 --- a/ui/components/ui/account-list/account-list.test.js +++ b/ui/components/ui/account-list/account-list.test.js @@ -1,41 +1,59 @@ import React from 'react'; -import { screen } from '@testing-library/react'; +import { screen, fireEvent } from '@testing-library/react'; +import { + BtcAccountType, + BtcMethod, + EthAccountType, +} from '@metamask/keyring-api'; import { renderWithProvider } from '../../../../test/jest'; import configureStore from '../../../store/store'; import mockState from '../../../../test/data/mock-state.json'; +import { ETH_EOA_METHODS } from '../../../../shared/constants/eth-methods'; import AccountList from './account-list'; -const render = () => { +const mockHandleAccountClick = jest.fn(); + +const defaultArgs = { + accounts: [ + { + address: '0x64a845a5b02460acf8a3d84503b0d68d028b4bb4', + addressLabel: 'Account 1', + label: 'Account 1', + balance: '87a73149c048545a3fe58', + id: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', + metadata: { + name: 'Account 1', + keyring: { + type: 'HD Key Tree', + }, + }, + options: {}, + methods: ETH_EOA_METHODS, + type: EthAccountType.Eoa, + has: () => { + /** nothing to do */ + }, + }, + ], + selectedAccounts: new Set(['0x64a845a5b02460acf8a3d84503b0d68d028b4bb4']), + addressLastConnectedMap: { + '0x64a845a5b02460acf8a3d84503b0d68d028b4bb4': 'Feb-22-2022', + }, + allAreSelected: () => true, + nativeCurrency: 'USD', + selectNewAccountViaModal: jest.fn(), + deselectAll: jest.fn(), + selectAll: jest.fn(), + handleAccountClick: mockHandleAccountClick, +}; + +const render = (args = defaultArgs) => { const store = configureStore({ metamask: { ...mockState.metamask, }, }); - const args = { - accounts: [ - { - address: '0x64a845a5b02460acf8a3d84503b0d68d028b4bb4', - addressLabel: 'Account 1', - label: 'Account 1', - lastConnectedDate: 'Feb-22-2022', - balance: '87a73149c048545a3fe58', - has: () => { - /** nothing to do */ - }, - }, - ], - selectedAccounts: new Set(['0x64a845a5b02460acf8a3d84503b0d68d028b4bb4']), - addressLastConnectedMap: { - '0x64a845a5b02460acf8a3d84503b0d68d028b4bb4': 'Feb-22-2022', - }, - allAreSelected: () => true, - nativeCurrency: 'USD', - selectNewAccountViaModal: jest.fn(), - deselectAll: jest.fn(), - selectAll: jest.fn(), - handleAccountClick: jest.fn(), - }; return renderWithProvider(, store); }; @@ -54,4 +72,41 @@ describe('AccountList', () => { render(); expect(screen.getByText('ETH')).toBeInTheDocument(); }); + + it('handleAccountClick is disabled for non-EVM accounts', () => { + const { container } = render({ + ...defaultArgs, + accounts: [ + { + id: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', + metadata: { + name: 'Btc account', + keyring: { + type: 'HD Key Tree', + }, + }, + options: {}, + methods: [BtcMethod.SendMany], + type: BtcAccountType.P2wpkh, + address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', + }, + ], + }); + const accountButton = container.querySelector( + '[data-testid="choose-account-list-0"]', + ); + + fireEvent.click(accountButton); + expect(mockHandleAccountClick).not.toHaveBeenCalled(); + }); + + it('handleAccountClick is enabled for EVM accounts', () => { + const { container } = render(); + const accountButton = container.querySelector( + '[data-testid="choose-account-list-0"]', + ); + + fireEvent.click(accountButton); + expect(mockHandleAccountClick).toHaveBeenCalled(); + }); }); diff --git a/ui/selectors/institutional/selectors.js b/ui/selectors/institutional/selectors.js index 7d0567d0b67b..5b913d5e9da6 100644 --- a/ui/selectors/institutional/selectors.js +++ b/ui/selectors/institutional/selectors.js @@ -2,6 +2,7 @@ import { toChecksumAddress } from 'ethereumjs-util'; import { getAccountType, getSelectedInternalAccount } from '../selectors'; import { getProviderConfig } from '../../ducks/metamask/metamask'; import { hexToDecimal } from '../../../shared/modules/conversion.utils'; +import { normalizeSafeAddress } from '../../../app/scripts/lib/multichain/address'; export function getWaitForConfirmDeepLinkDialog(state) { return state.metamask.waitForConfirmDeepLinkDialog; @@ -36,7 +37,7 @@ export function getConfiguredCustodians(state) { export function getCustodianIconForAddress(state, address) { let custodianIcon; - const checksummedAddress = address && toChecksumAddress(address); + const checksummedAddress = address && normalizeSafeAddress(address); if ( checksummedAddress && state.metamask.custodyAccountDetails?.[checksummedAddress]