Skip to content

Commit

Permalink
move getInternalAccounts from selectors.js to accounts.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch committed Nov 1, 2024
1 parent a94de6a commit c983298
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
);

Expand All @@ -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,
}),
);
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/notifications-settings/notifications-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
9 changes: 9 additions & 0 deletions ui/selectors/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
hasCreatedBtcMainnetAccount,
hasCreatedBtcTestnetAccount,
getSelectedInternalAccount,
getInternalAccounts,
} from './accounts';

const MOCK_STATE: AccountsState = {
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion ui/selectors/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
isBtcMainnetAddress,
isBtcTestnetAddress,
} from '../../shared/lib/multichain';
import { getInternalAccounts } from './selectors';

export type AccountsState = {
metamask: AccountsControllerState;
Expand All @@ -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];
Expand Down
6 changes: 1 addition & 5 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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];
}
Expand Down
8 changes: 0 additions & 8 deletions ui/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion ui/selectors/snaps/accounts.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down

0 comments on commit c983298

Please sign in to comment.