From c983298d29f5945592f40ff4d981ea50b7ad2ebc Mon Sep 17 00:00:00 2001 From: David Murdoch <187813+davidmurdoch@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:59:04 -0400 Subject: [PATCH] move `getInternalAccounts` from `selectors.js` to `accounts.ts` --- .../interactive-replacement-token-page.tsx | 2 ++ .../notifications-settings/notifications-settings.tsx | 2 +- ui/selectors/accounts.test.ts | 9 +++++++++ ui/selectors/accounts.ts | 5 ++++- ui/selectors/selectors.js | 6 +----- ui/selectors/selectors.test.js | 8 -------- ui/selectors/snaps/accounts.ts | 3 ++- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx b/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx index 5c00eb4ffa10..d0aa772e3a31 100644 --- a/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx +++ b/ui/pages/institutional/interactive-replacement-token-page/interactive-replacement-token-page.tsx @@ -154,6 +154,7 @@ const InteractiveReplacementTokenPage: React.FC = () => { const filteredAccounts = custodianAccounts.filter( (account: TokenAccount) => + // @ts-expect-error metaMaskAccounts isn't a real type metaMaskAccounts[account.address.toLowerCase()], ); @@ -163,6 +164,7 @@ const InteractiveReplacementTokenPage: React.FC = () => { name: account.name, labels: account.labels, balance: + // @ts-expect-error metaMaskAccounts isn't a real type metaMaskAccounts[account.address.toLowerCase()]?.balance || 0, }), ); diff --git a/ui/pages/notifications-settings/notifications-settings.tsx b/ui/pages/notifications-settings/notifications-settings.tsx index d929f048a793..0fafb468b733 100644 --- a/ui/pages/notifications-settings/notifications-settings.tsx +++ b/ui/pages/notifications-settings/notifications-settings.tsx @@ -57,7 +57,7 @@ export default function NotificationsSettings() { const isUpdatingMetamaskNotifications = useSelector( getIsUpdatingMetamaskNotifications, ); - const accounts: AccountType[] = useSelector(getInternalAccounts); + const accounts = useSelector(getInternalAccounts) as AccountType[]; // States const [loadingAllowNotifications, setLoadingAllowNotifications] = diff --git a/ui/selectors/accounts.test.ts b/ui/selectors/accounts.test.ts index 639da0185b72..033d88c30faa 100644 --- a/ui/selectors/accounts.test.ts +++ b/ui/selectors/accounts.test.ts @@ -15,6 +15,7 @@ import { hasCreatedBtcMainnetAccount, hasCreatedBtcTestnetAccount, getSelectedInternalAccount, + getInternalAccounts, } from './accounts'; const MOCK_STATE: AccountsState = { @@ -27,6 +28,14 @@ const MOCK_STATE: AccountsState = { }; describe('Accounts Selectors', () => { + describe('#getInternalAccounts', () => { + it('returns a list of internal accounts', () => { + expect(getInternalAccounts(mockState as AccountsState)).toStrictEqual( + Object.values(mockState.metamask.internalAccounts.accounts), + ); + }); + }); + describe('#getSelectedInternalAccount', () => { it('returns selected internalAccount', () => { expect( diff --git a/ui/selectors/accounts.ts b/ui/selectors/accounts.ts index d69cd130f9aa..af977b7511da 100644 --- a/ui/selectors/accounts.ts +++ b/ui/selectors/accounts.ts @@ -8,7 +8,6 @@ import { isBtcMainnetAddress, isBtcTestnetAddress, } from '../../shared/lib/multichain'; -import { getInternalAccounts } from './selectors'; export type AccountsState = { metamask: AccountsControllerState; @@ -20,6 +19,10 @@ function isBtcAccount(account: InternalAccount) { return Boolean(account && account.type === P2wpkh); } +export function getInternalAccounts(state: AccountsState) { + return Object.values(state.metamask.internalAccounts.accounts); +} + export function getSelectedInternalAccount(state: AccountsState) { const accountId = state.metamask.internalAccounts.selectedAccount; return state.metamask.internalAccounts.accounts[accountId]; diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index bb7ef5f796d7..3267805bba61 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -117,7 +117,7 @@ import { getOrderedConnectedAccountsForConnectedDapp, getSubjectMetadata, } from './permissions'; -import { getSelectedInternalAccount } from './accounts'; +import { getSelectedInternalAccount, getInternalAccounts } from './accounts'; import { createDeepEqualSelector } from './util'; import { getMultichainBalances, getMultichainNetwork } from './multichain'; @@ -371,10 +371,6 @@ export function getSelectedInternalAccountWithBalance(state) { return selectedAccountWithBalance; } -export function getInternalAccounts(state) { - return Object.values(state.metamask.internalAccounts.accounts); -} - export function getInternalAccount(state, accountId) { return state.metamask.internalAccounts.accounts[accountId]; } diff --git a/ui/selectors/selectors.test.js b/ui/selectors/selectors.test.js index 459864c1e1f3..d6656e481709 100644 --- a/ui/selectors/selectors.test.js +++ b/ui/selectors/selectors.test.js @@ -113,14 +113,6 @@ describe('Selectors', () => { }); }); - describe('#getInternalAccounts', () => { - it('returns a list of internal accounts', () => { - expect(selectors.getInternalAccounts(mockState)).toStrictEqual( - Object.values(mockState.metamask.internalAccounts.accounts), - ); - }); - }); - describe('#getInternalAccount', () => { it("returns undefined if the account doesn't exist", () => { expect( diff --git a/ui/selectors/snaps/accounts.ts b/ui/selectors/snaps/accounts.ts index b47f33726429..55a30f0c72eb 100644 --- a/ui/selectors/snaps/accounts.ts +++ b/ui/selectors/snaps/accounts.ts @@ -1,6 +1,7 @@ import { createSelector } from 'reselect'; import { AccountsControllerState } from '@metamask/accounts-controller'; -import { getAccountName, getInternalAccounts } from '../selectors'; +import { getAccountName } from '../selectors'; +import { getInternalAccounts } from '../accounts'; import { createDeepEqualSelector } from '../util'; /**