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 selectors and convert to TypeScript #29014

Draft
wants to merge 61 commits into
base: jongsun/perf/redux/241204-unflatten-metamask-slice
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
3064fe3
Squashed commit of the following:
MajorLift Dec 18, 2024
3062309
Remove `getFlatState` method from `ComposableObservableStore`
MajorLift Nov 6, 2024
0d17209
Define types for metamask controller store fields
MajorLift Nov 6, 2024
912c398
Refactor `MetamaskController` `store`, `memStore` fields so that they…
MajorLift Dec 6, 2024
eaee948
Update `PatchStore` class to conform with new state types
MajorLift Nov 11, 2024
7980ef2
Fix errors in `MetamaskController` store objects and types
MajorLift Nov 27, 2024
dfc343d
Fix import paths
MajorLift Nov 27, 2024
fcf7a84
Simply `PatchStore._generatePatches`
MajorLift Nov 27, 2024
93989f4
Update `App{State,Metadata}Controller` entries in store objects/types…
MajorLift Dec 4, 2024
d074740
Move `metamask-controllers` types to `shared` directory
MajorLift Dec 4, 2024
1c011fd
Remove `NotificationController` from `MetamaskController` and store
MajorLift Dec 2, 2024
1ce4e5f
Define `BackgroundStateProxy` type and replace `MemStoreControllersCo…
MajorLift Dec 4, 2024
c618832
Add `eslint-disable` for `no-restricted-paths` in types file
MajorLift Dec 4, 2024
048ac30
Optimize `PatchStore` to utilize `controllerKey` payload from `stateC…
MajorLift Dec 4, 2024
bee2056
Fix `sanitizeUIState` with `in` property checks
MajorLift Dec 4, 2024
9ddb504
Update and fix `store`, `memStore`
MajorLift Dec 5, 2024
09aad96
Fix broken import for `BalancesControllerState`
MajorLift Dec 9, 2024
6c55409
Convert `ComposableObservableStore` to TypeScript
MajorLift Dec 9, 2024
03071f4
Fix all type errors in `ComposableObservableStore`
MajorLift Dec 9, 2024
abb8797
Allow `PatchStore` to handle top-level keys that aren't controllerKey…
MajorLift Dec 9, 2024
13efab9
Fix implicit `any` in institutional store types
MajorLift Dec 10, 2024
6931a31
refactor: `ComposableObservableStore` takes a controller map as input…
MajorLift Dec 10, 2024
1214a7e
Fix `BridgeControllerState` import path
MajorLift Dec 11, 2024
57d1666
Remove `ui/selectors/institutional/selectors.ts` from diff
MajorLift Dec 11, 2024
308d6df
Refactor `sanitizeUIState` so it can handle both the entire backgroun…
MajorLift Dec 12, 2024
90ca993
Fix `PatchStore` to handle individual controller state only and not u…
MajorLift Dec 12, 2024
2d30f08
Fix Redux store actions `updateMetamaskState`, `applyPatches` to ensu…
MajorLift Dec 12, 2024
ca342b2
Handle more edge cases in null check for `controller.store.subscribe`
MajorLift Dec 12, 2024
a9e9ad3
Add variable assignment
MajorLift Dec 12, 2024
803cff6
Convert `ComposableObservableStore.test.{j,t}s`
MajorLift Dec 13, 2024
a9f14c4
Remove incorrect return type on `sanitizeUIState`
MajorLift Dec 13, 2024
9557404
Fix tests for `PatchStore`, `sanitizeUiState`
MajorLift Dec 13, 2024
f4ef2f1
Fix tests for `ComposableObservableStore`
MajorLift Dec 13, 2024
9743495
Linter fixes
MajorLift Jan 6, 2025
cd636c5
Temporary adjustment for `Bridge{,Status}ControllerState` types
MajorLift Jan 6, 2025
f6859e2
Move `initialMetamaskState` into `ui/ducks/metamask/constants.ts`
MajorLift Dec 11, 2024
9208fe4
Remove `TemporaryBackgroundState` type and merge into `initialMetamas…
MajorLift Jan 6, 2025
cd27838
Merge `MetamaskState` defined in `metametrics-controller` into `initi…
MajorLift Dec 2, 2024
e060254
Convert to TypeScript: `combineReducer`, `metamask` slice
MajorLift Dec 2, 2024
402da11
Unflatten `metamask` slice and convert to TypeScript
MajorLift Dec 11, 2024
2db4888
Replace `CombinedBackgroundAndReduxState` type with fixed `MetaMaskRe…
MajorLift Dec 4, 2024
3ef2792
Remove unused import
MajorLift Dec 4, 2024
5232d71
Unflatten `SENTRY_UI_STATE` object
MajorLift Dec 5, 2024
e5aa2c2
Add missing `PreferencesController.preferences` properties to `SENTRY…
MajorLift Dec 7, 2024
8fe8b22
Reduce diffs
MajorLift Dec 11, 2024
1745af1
Rename `MetamaskSliceState` to `MetaMaskSliceState`
MajorLift Dec 11, 2024
ada4198
Unflatten `metametrics-controller`
MajorLift Dec 11, 2024
c47ed91
Update type in `updateMetamaskState`
MajorLift Dec 12, 2024
21eb963
Unflatten institutional selectors
MajorLift Jan 6, 2025
08d1ec3
Convert all selectors in `ui/selectors` to TypeScript
MajorLift Dec 10, 2024
5c1dc41
Unflatten selectors and fix type errors
MajorLift Dec 18, 2024
cc92f39
Define utility type `MetaMaskSliceControllerState`
MajorLift Dec 31, 2024
c348183
Narrow network shared constants with `as const`
MajorLift Jan 1, 2025
d1ca681
Fix selectors to use composable input types
MajorLift Jan 6, 2025
6ffd569
Upstream type fixes
MajorLift Jan 6, 2025
e0380f0
Type fixes for `confirm-transaction` slice selectors
MajorLift Jan 7, 2025
958dbe9
Type fixes, unflattening for selectors
MajorLift Jan 7, 2025
c44c94b
Selector composition type fixes for `ui/selectors/custom-gas.ts`
MajorLift Jan 7, 2025
55fc96e
Linter fixes
MajorLift Jan 7, 2025
978fa9c
Prep for extracting diffs of unrecognized renames
MajorLift Jan 7, 2025
9c931d8
Extract diffs for unrecognized renames
MajorLift Jan 7, 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
11 changes: 5 additions & 6 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ const state = {
connectedAccounts: ['0x64a845a5b02460acf8a3d84503b0d68d028b4bb4'],
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
rpcUrl: 'https://rawtestrpc.metamask.io/',
internalAccounts: {
accounts: {
Expand Down Expand Up @@ -677,8 +676,6 @@ const state = {
],
},
],
pendingTokens: {},
customNonceValue: '',
send: {
gasLimit: '0xcb28',
gasPrice: null,
Expand All @@ -702,7 +699,6 @@ const state = {
},
useBlockie: false,
featureFlags: {},
welcomeScreenSeen: false,
slides: [],
currentLocale: 'en',
preferences: {
Expand Down Expand Up @@ -731,7 +727,6 @@ const state = {
},
},
participateInMetaMetrics: true,
nextNonce: 71,
connectedStatusPopoverHasBeenShown: true,
swapsWelcomeMessageHasBeenShown: true,
defaultHomeActiveTabName: 'Tokens',
Expand Down Expand Up @@ -1630,6 +1625,11 @@ const state = {
openSeaEnabled: true,
},
appState: {
isAccountMenuOpen: false,
welcomeScreenSeen: false,
pendingTokens: {},
customNonceValue: '',
nextNonce: 71,
shouldClose: false,
menuOpen: false,
modal: {
Expand Down Expand Up @@ -1665,7 +1665,6 @@ const state = {
isLoading: false,
warning: null,
buyView: {},
gasIsLoading: false,
defaultHdPaths: {
trezor: "m/44'/60'/0'/0",
ledger: "m/44'/60'/0'/0/0",
Expand Down
55 changes: 29 additions & 26 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ export const SENTRY_BACKGROUND_STATE = {
petnamesEnabled: true,
showConfirmationAdvancedDetails: true,
privacyMode: false,
useNativeCurrencyAsPrimaryCurrency: true,
featureNotificationsEnabled: true,
showMultiRpcModal: true,
tokenSortConfig: {},
shouldShowAggregatedBalancePopover: true,
},
useExternalServices: false,
selectedAddress: false,
Expand Down Expand Up @@ -412,26 +417,13 @@ export const SENTRY_BACKGROUND_STATE = {
///: END:ONLY_INCLUDE_IF
};

const flattenedBackgroundStateMask = Object.values(
SENTRY_BACKGROUND_STATE,
).reduce((partialBackgroundState, controllerState: object) => {
return {
...partialBackgroundState,
...controllerState,
};
}, {});

// This describes the subset of Redux state attached to errors sent to Sentry
// These properties have some potential to be useful for debugging, and they do
// not contain any identifiable information.
export const SENTRY_UI_STATE = {
gas: true,
history: true,
metamask: {
...flattenedBackgroundStateMask,
// This property comes from the background but isn't in controller state
isInitialized: true,
// These properties are in the `metamask` slice but not in the background state
appState: {
customNonceValue: true,
isAccountMenuOpen: true,
isNetworkMenuOpen: true,
Expand All @@ -440,18 +432,29 @@ export const SENTRY_UI_STATE = {
welcomeScreenSeen: true,
slides: false,
confirmationExchangeRates: true,
useSafeChainsListValidation: true,
watchEthereumAccountEnabled: false,
bitcoinSupportEnabled: false,
bitcoinTestnetSupportEnabled: false,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
addSnapAccountEnabled: false,
snapsAddSnapAccountModalDismissed: false,
///: END:ONLY_INCLUDE_IF
switchedNetworkDetails: false,
switchedNetworkNeverShowMessage: false,
newPrivacyPolicyToastClickedOrClosed: false,
newPrivacyPolicyToastShownDate: false,
},
metamask: {
// This property comes from the background but isn't in controller state
isInitialized: true,
...SENTRY_BACKGROUND_STATE,
PreferencesController: {
...SENTRY_BACKGROUND_STATE.PreferencesController,
useSafeChainsListValidation: true,
watchEthereumAccountEnabled: false,
bitcoinSupportEnabled: false,
bitcoinTestnetSupportEnabled: false,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
addSnapAccountEnabled: false,
snapsAddSnapAccountModalDismissed: false,
///: END:ONLY_INCLUDE_IF
},
AppStateController: {
...SENTRY_BACKGROUND_STATE.AppStateController,
switchedNetworkDetails: false,
switchedNetworkNeverShowMessage: false,
newPrivacyPolicyToastClickedOrClosed: false,
newPrivacyPolicyToastShownDate: false,
},
},
unconnectedAccount: true,
};
8 changes: 4 additions & 4 deletions app/scripts/controllers/account-tracker-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
NetworkControllerGetStateAction,
Provider,
} from '@metamask/network-controller';
import { hasProperty, Hex } from '@metamask/utils';
import { getKnownPropertyNames, hasProperty, Hex } from '@metamask/utils';
import {
BaseController,
ControllerGetStateAction,
Expand Down Expand Up @@ -66,7 +66,7 @@ type Account = {
export type AccountTrackerControllerState = {
accounts: Record<string, Account | Record<string, never>>;
currentBlockGasLimit: string;
accountsByChainId: Record<string, AccountTrackerControllerState['accounts']>;
accountsByChainId: Record<Hex, AccountTrackerControllerState['accounts']>;
currentBlockGasLimitByChainId: Record<Hex, string>;
};

Expand Down Expand Up @@ -524,7 +524,7 @@ export default class AccountTrackerController extends BaseController<
addresses.forEach((address) => {
accounts[address] = {};
});
Object.keys(accountsByChainId).forEach((chainId) => {
getKnownPropertyNames(accountsByChainId).forEach((chainId) => {
addresses.forEach((address) => {
accountsByChainId[chainId][address] = {};
});
Expand Down Expand Up @@ -562,7 +562,7 @@ export default class AccountTrackerController extends BaseController<
addresses.forEach((address) => {
delete accounts[address];
});
Object.keys(accountsByChainId).forEach((chainId) => {
getKnownPropertyNames(accountsByChainId).forEach((chainId) => {
addresses.forEach((address) => {
delete accountsByChainId[chainId][address];
});
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/app-state-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type AppStateControllerState = {
// prior to Migration 92.3 where we split out the setting to support
// multiple networks.
hadAdvancedGasFeesSetPriorToMigration92_3: boolean;
qrHardware: Json;
qrHardware: { sign?: { request?: Json } } | Json;
nftsDropdownState: Json;
surveyLinkLastClickedOrClosed: number | null;
signatureSecurityAlertResponses: Record<string, SecurityAlertResponse>;
Expand Down
Loading
Loading