Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Unflatten MetamaskController stores #28723

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
52e818a
Remove `getFlatState` method from `ComposableObservableStore`
MajorLift Nov 6, 2024
2a1fee2
Define types for metamask controller store fields
MajorLift Nov 6, 2024
3beda4d
Refactor `MetamaskController` `store`, `memStore` fields so that they…
MajorLift Dec 6, 2024
7143084
Update `PatchStore` class to conform with new state types
MajorLift Nov 11, 2024
28ca845
Fix errors in `MetamaskController` store objects and types
MajorLift Nov 27, 2024
1f65a9f
Fix import paths
MajorLift Nov 27, 2024
899d855
Simply `PatchStore._generatePatches`
MajorLift Nov 27, 2024
0eb33d7
Update `App{State,Metadata}Controller` entries in store objects/types…
MajorLift Dec 4, 2024
cb7eecd
Move `metamask-controllers` types to `shared` directory
MajorLift Dec 4, 2024
55fe737
Remove `NotificationController` from `MetamaskController` and store
MajorLift Dec 2, 2024
eea4c34
Define `BackgroundStateProxy` type and replace `MemStoreControllersCo…
MajorLift Dec 4, 2024
e3be201
Add `eslint-disable` for `no-restricted-paths` in types file
MajorLift Dec 4, 2024
601ce9e
Optimize `PatchStore` to utilize `controllerKey` payload from `stateC…
MajorLift Dec 4, 2024
6e54d6a
Fix `sanitizeUIState` with `in` property checks
MajorLift Dec 4, 2024
5f88de6
Update and fix `store`, `memStore`
MajorLift Dec 5, 2024
2fc248a
Fix broken import for `BalancesControllerState`
MajorLift Dec 9, 2024
622a096
Convert `ComposableObservableStore` to TypeScript
MajorLift Dec 9, 2024
81e7756
Fix all type errors in `ComposableObservableStore`
MajorLift Dec 9, 2024
f94f6a2
Allow `PatchStore` to handle top-level keys that aren't controllerKey…
MajorLift Dec 9, 2024
474efaa
Fix implicit `any` in institutional store types
MajorLift Dec 10, 2024
1ccda39
refactor: `ComposableObservableStore` takes a controller map as input…
MajorLift Dec 10, 2024
11831bc
Fix `BridgeControllerState` import path
MajorLift Dec 11, 2024
df7fa87
Remove `ui/selectors/institutional/selectors.ts` from diff
MajorLift Dec 11, 2024
b74b346
Refactor `sanitizeUIState` so it can handle both the entire backgroun…
MajorLift Dec 12, 2024
d954084
Fix `PatchStore` to handle individual controller state only and not u…
MajorLift Dec 12, 2024
578a736
Fix Redux store actions `updateMetamaskState`, `applyPatches` to ensu…
MajorLift Dec 12, 2024
1b62855
Handle more edge cases in null check for `controller.store.subscribe`
MajorLift Dec 12, 2024
50ba81a
Add variable assignment
MajorLift Dec 12, 2024
398bc7c
Convert `ComposableObservableStore.test.{j,t}s`
MajorLift Dec 13, 2024
25cc18f
Remove incorrect return type on `sanitizeUIState`
MajorLift Dec 13, 2024
1eb1d70
Fix tests for `PatchStore`, `sanitizeUiState`
MajorLift Dec 13, 2024
d93a318
Fix tests for `ComposableObservableStore`
MajorLift Dec 13, 2024
bd57b45
Linter fixes
MajorLift Jan 6, 2025
83316a5
Temporary adjustment for `Bridge{,Status}ControllerState` types
MajorLift Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import { ENVIRONMENT } from '../../../development/build/constants';
///: END:ONLY_INCLUDE_IF

import { BackgroundStateProxy } from '../../../shared/types/metamask';
import type {
PreferencesControllerState,
PreferencesControllerGetStateAction,
Expand Down Expand Up @@ -1004,7 +1005,7 @@
}
}

handleMetaMaskStateUpdate(newState: MetaMaskState): void {
handleMetaMaskStateUpdate(newState: BackgroundStateProxy): void {
const userTraits = this._buildUserTraitsObject(newState);
if (userTraits) {
this.identify(userTraits);
Expand Down Expand Up @@ -1169,20 +1170,20 @@
* @returns traits that have changed since last update
*/
_buildUserTraitsObject(
metamaskState: MetaMaskState,
metamaskState: BackgroundStateProxy,
): Partial<MetaMetricsUserTraits> | null {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
const mmiAccountAddress =
metamaskState.custodyAccountDetails &&

Check failure on line 1177 in app/scripts/controllers/metametrics-controller.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Property 'custodyAccountDetails' does not exist on type 'BackgroundStateProxy'.
Object.keys(metamaskState.custodyAccountDetails).length

Check failure on line 1178 in app/scripts/controllers/metametrics-controller.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Property 'custodyAccountDetails' does not exist on type 'BackgroundStateProxy'.
? Object.keys(metamaskState.custodyAccountDetails)[0]

Check failure on line 1179 in app/scripts/controllers/metametrics-controller.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Property 'custodyAccountDetails' does not exist on type 'BackgroundStateProxy'.
: null;
///: END:ONLY_INCLUDE_IF
const { traits, previousUserTraits } = this.state;

const currentTraits = {
[MetaMetricsUserTrait.AddressBookEntries]: sum(
Object.values(metamaskState.addressBook).map(size),

Check failure on line 1186 in app/scripts/controllers/metametrics-controller.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Property 'addressBook' does not exist on type 'BackgroundStateProxy'.

Check failure on line 1186 in app/scripts/controllers/metametrics-controller.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Argument of type '(collection: string | object | null | undefined) => number' is not assignable to parameter of type '(value: unknown, index: number, array: unknown[]) => number'.
),
[MetaMetricsUserTrait.InstallDateExt]:
traits[MetaMetricsUserTrait.InstallDateExt] || '',
Expand Down Expand Up @@ -1299,11 +1300,13 @@
*
* @param allNfts
*/
#getAllNFTsFlattened = memoize((allNfts: MetaMaskState['allNfts'] = {}) => {
return Object.values(allNfts).reduce((result: Nft[], chainNFTs) => {
return result.concat(...Object.values(chainNFTs));
}, []);
});
#getAllNFTsFlattened = memoize(
(allNfts: BackgroundStateProxy['NftController']['allNfts'] = {}) => {
return Object.values(allNfts).reduce((result: Nft[], chainNFTs) => {
return result.concat(...Object.values(chainNFTs));
}, []);
},
);

/**
* Returns the number of unique NFT addresses the user
Expand All @@ -1312,7 +1315,7 @@
* @param allNfts
*/
#getAllUniqueNFTAddressesLength(
allNfts: MetaMaskState['allNfts'] = {},
allNfts: BackgroundStateProxy['NftController']['allNfts'] = {},
): number {
const allNFTAddresses = this.#getAllNFTsFlattened(allNfts).map(
(nft) => nft.address,
Expand All @@ -1325,7 +1328,9 @@
* @param allTokens
* @returns number of unique token addresses
*/
#getNumberOfTokens(allTokens: MetaMaskState['allTokens']): number {
#getNumberOfTokens(
allTokens: BackgroundStateProxy['TokensController']['allTokens'],
): number {
return Object.values(allTokens).reduce((result, accountsByChain) => {
return result + sum(Object.values(accountsByChain).map(size));
}, 0);
Expand Down Expand Up @@ -1549,8 +1554,9 @@
*
* @param metamaskState
*/
#getPetnameAddressCount(metamaskState: MetaMaskState): number {
const addressNames = metamaskState.names?.[NameType.ETHEREUM_ADDRESS] ?? {};
#getPetnameAddressCount(metamaskState: BackgroundStateProxy): number {
const addressNames =
metamaskState.NameController.names?.[NameType.ETHEREUM_ADDRESS] ?? {};

return Object.keys(addressNames).reduce((totalCount, address) => {
const addressEntry = addressNames[address];
Expand Down
115 changes: 0 additions & 115 deletions app/scripts/lib/ComposableObservableStore.js

This file was deleted.

Loading
Loading