Skip to content

Commit

Permalink
Move metamask-controllers types to shared directory
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Dec 2, 2024
1 parent 57115d1 commit 3e6e2e5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 33 deletions.
1 change: 0 additions & 1 deletion app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
ControllerStateChangeEvent,
RestrictedControllerMessenger,
} from '@metamask/base-controller';
import type { MemStoreControllersComposedState } from '../metamask-controller-stores';
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
import {
METAMETRICS_ANONYMOUS_ID,
Expand Down
20 changes: 10 additions & 10 deletions app/scripts/lib/PatchStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createProjectLogger, getKnownPropertyNames } from '@metamask/utils';
import { Patch } from 'immer';
import { v4 as uuid } from 'uuid';
import { MemStoreControllersComposedState } from '../metamask-controller-stores';
import { MemStoreControllersComposedState as BackgroundState } from '../../../shared/types/metamask';
import ComposableObservableStore from './ComposableObservableStore';
import { sanitizeUIState } from './state-utils';

Expand All @@ -16,8 +16,8 @@ export class PatchStore {

private listener: (request: {
controllerKey: string;
oldState: MemStoreControllersComposedState;
newState: MemStoreControllersComposedState;
oldState: BackgroundState;
newState: BackgroundState;
}) => void;

constructor(observableStore: ComposableObservableStore) {
Expand Down Expand Up @@ -52,8 +52,8 @@ export class PatchStore {
newState,
}: {
controllerKey: string;
oldState: MemStoreControllersComposedState;
newState: MemStoreControllersComposedState;
oldState: BackgroundState;
newState: BackgroundState;
}) {
const sanitizedNewState = sanitizeUIState(newState);
const patches = this._generatePatches(oldState, sanitizedNewState);
Expand Down Expand Up @@ -81,12 +81,12 @@ export class PatchStore {
}

private _generatePatches(
oldState: MemStoreControllersComposedState,
newState: MemStoreControllersComposedState,
oldState: BackgroundState,
newState: BackgroundState,
): Patch[] {
return getKnownPropertyNames<keyof MemStoreControllersComposedState>(
newState,
).reduce<Patch[]>((patches, controllerName) => {
return getKnownPropertyNames<keyof BackgroundState>(newState).reduce<
Patch[]
>((patches, controllerName) => {
Object.keys(oldState[controllerName]).forEach((key) => {
const oldData = oldState[controllerName][key];
const newData = newState[controllerName][key];
Expand Down
8 changes: 3 additions & 5 deletions app/scripts/lib/state-utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { SnapControllerState } from '@metamask/snaps-controllers';
import { isSnapId, Snap } from '@metamask/snaps-utils';
import { MemStoreControllersComposedState } from '../metamask-controller-stores';
import { MemStoreControllersComposedState as BackgroundState } from '../../../shared/types/metamask';

const REMOVE_KEYS = ['snapStates', 'unencryptedSnapStates', 'vault'] as const;

export function sanitizeUIState(
state: MemStoreControllersComposedState,
): MemStoreControllersComposedState {
export function sanitizeUIState(state: BackgroundState): BackgroundState {
const newState = { ...state };

for (const key of REMOVE_KEYS) {
Expand All @@ -22,7 +20,7 @@ export function sanitizeUIState(
return newState;
}

function sanitizeSnapData(state: MemStoreControllersComposedState) {
function sanitizeSnapData(state: BackgroundState) {
const snapsData: SnapControllerState['snaps'] | undefined =
state.SnapController.snaps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ import type {
NotificationServicesPushController,
} from '@metamask/notification-services-controller';

import { BridgeStatusControllerState } from '../../shared/types/bridge-status';
import { BridgeStatusControllerState } from './bridge-status';

import type { BalancesController as MultichainBalancesControllerState } from './lib/accounts/BalancesController';
import type { NetworkOrderControllerState } from './controllers/network-order';
import type { AccountOrderControllerState } from './controllers/account-order';
import type { PreferencesControllerState } from './controllers/preferences-controller';
import type { AppStateControllerState } from './controllers/app-state-controller';
import type { AlertControllerState } from './controllers/alert-controller';
import type { OnboardingControllerState } from './controllers/onboarding';
import type { EncryptionPublicKeyControllerState } from './controllers/encryption-public-key';
import type { AppMetadataControllerState } from './controllers/app-metadata';
import type { DecryptMessageControllerState } from './controllers/decrypt-message';
import type { SwapsControllerState } from './controllers/swaps/swaps.types';
import type { BridgeControllerState } from './controllers/bridge/types';
import { MetaMetricsDataDeletionState } from './controllers/metametrics-data-deletion/metametrics-data-deletion';
import { MetaMetricsControllerState } from './controllers/metametrics-controller';
import { AccountTrackerControllerState } from './controllers/account-tracker-controller';
import type { BalancesController as MultichainBalancesControllerState } from '../../app/scripts/lib/accounts/BalancesController';
import type { NetworkOrderControllerState } from '../../app/scripts/controllers/network-order';
import type { AccountOrderControllerState } from '../../app/scripts/controllers/account-order';
import type { PreferencesControllerState } from '../../app/scripts/controllers/preferences-controller';
import type { AppStateControllerState } from '../../app/scripts/controllers/app-state-controller';
import type { AlertControllerState } from '../../app/scripts/controllers/alert-controller';
import type { OnboardingControllerState } from '../../app/scripts/controllers/onboarding';
import type { EncryptionPublicKeyControllerState } from '../../app/scripts/controllers/encryption-public-key';
import type { AppMetadataControllerState } from '../../app/scripts/controllers/app-metadata';
import type { DecryptMessageControllerState } from '../../app/scripts/controllers/decrypt-message';
import type { SwapsControllerState } from '../../app/scripts/controllers/swaps/swaps.types';
import type { BridgeControllerState } from '../../app/scripts/controllers/bridge/types';
import { MetaMetricsDataDeletionState } from '../../app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion';
import { MetaMetricsControllerState } from '../../app/scripts/controllers/metametrics-controller';
import { AccountTrackerControllerState } from '../../app/scripts/controllers/account-tracker-controller';

export type ResetOnRestartStoresComposedState = {
AccountTracker: AccountTrackerControllerState;
Expand Down
2 changes: 1 addition & 1 deletion ui/ducks/metamask/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NameType } from '@metamask/name-controller';
import { getDefaultPreferencesControllerState } from '../../../app/scripts/controllers/preferences-controller';
import type { BackgroundStateProxy, MemStoreControllersComposedState } from '../../../app/scripts/metamask-controller-stores';
import type { BackgroundStateProxy, MemStoreControllersComposedState } from '../../../shared/types/metamask';
import {
DEFAULT_AUTO_LOCK_TIME_LIMIT,
ThemeType,
Expand Down

0 comments on commit 3e6e2e5

Please sign in to comment.