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

feat(29629): Construct exhaustive state object for metamask slice with default values #30378

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const SENTRY_BACKGROUND_STATE = {
isCheckingAccountsPresence: false,
isFetchingMetamaskNotifications: false,
isUpdatingMetamaskNotifications: false,
isUpdatingMetamaskNotificationsAccount: false,
isUpdatingMetamaskNotificationsAccount: [],
},
MetaMetricsController: {
eventsBeforeMetricsOptIn: false,
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/controllers/permissions/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ export enum NOTIFICATION_NAMES {
unlockStateChanged = 'metamask_unlockStateChanged',
chainChanged = 'metamask_chainChanged',
}

export enum LOG_METHOD_TYPES {
restricted = 'restricted',
internal = 'internal',
}
8 changes: 8 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ export type MetaMetricsUserTraits = {
* @deprecated
*/
three_box_enabled?: boolean;
/**
* Does the user have privacy mode enabled?
*/
privacy_mode_toggle?: boolean;
/**
* Does the user prefer seeing all tokens or current network tokens in wallet list
*/
selected_network_filter?: string[];
/**
* Which theme the user has selected.
*/
Expand Down
317 changes: 317 additions & 0 deletions shared/types/metamask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
/* eslint-disable import/no-restricted-paths */
/** Circular dependencies in this file should have no impact at build time and runtime, ås all imports/exports are types that will be stripped by tsc */
import {
TokenRatesController,
CurrencyRateController,
TokenListController,
TokensController,
TokenBalancesController,
NftController,
RatesController,
CurrencyRateState,
TokenListState,
TokensControllerState,
TokenBalancesControllerState,
NftControllerState,
RatesControllerState,
TokenRatesControllerState,
} from '@metamask/assets-controllers';
import {
KeyringController,
KeyringControllerState,
} from '@metamask/keyring-controller';
import {
AddressBookController,
AddressBookControllerState,
} from '@metamask/address-book-controller';
import {
ApprovalController,
ApprovalControllerState,
} from '@metamask/approval-controller';
import { EnsController, EnsControllerState } from '@metamask/ens-controller';
import {
PhishingController,
PhishingControllerState,
} from '@metamask/phishing-controller';
import {
AnnouncementController,
AnnouncementControllerState,
} from '@metamask/announcement-controller';
import { NetworkController, NetworkState } from '@metamask/network-controller';
import { GasFeeController, GasFeeState } from '@metamask/gas-fee-controller';
import {
CaveatConstraint,
PermissionConstraint,
PermissionController,
PermissionControllerState,
PermissionSpecificationConstraint,
SubjectMetadataController,
SubjectMetadataControllerState,
} from '@metamask/permission-controller';
import {
RemoteFeatureFlagController,
RemoteFeatureFlagControllerState,
} from '@metamask/remote-feature-flag-controller';
import {
SelectedNetworkController,
SelectedNetworkControllerState,
} from '@metamask/selected-network-controller';
import {
LoggingController,
LoggingControllerState,
} from '@metamask/logging-controller';
import {
PermissionLogController,
PermissionLogControllerState,
} from '@metamask/permission-log-controller';
import {
SnapController,
CronjobController,
SnapInterfaceController,
SnapInsightsController,
SnapControllerState,
CronjobControllerState,
SnapsRegistryState,
SnapInterfaceControllerState,
SnapInsightsControllerState,
JsonSnapsRegistry,
} from '@metamask/snaps-controllers';
import {
AccountsController,
AccountsControllerState,
} from '@metamask/accounts-controller';
import {
SignatureController,
SignatureControllerState,
} from '@metamask/signature-controller';
import { PPOMController, PPOMState } from '@metamask/ppom-validator';
import { NameController, NameControllerState } from '@metamask/name-controller';
import {
QueuedRequestController,
QueuedRequestControllerState,
} from '@metamask/queued-request-controller';
import {
UserOperationController,
UserOperationControllerState,
} from '@metamask/user-operation-controller';
import {
TransactionController,
TransactionControllerState,
} from '@metamask/transaction-controller';
import {
AuthenticationController,
UserStorageController,
} from '@metamask/profile-sync-controller';
import {
NotificationServicesController,
NotificationServicesPushController,
} from '@metamask/notification-services-controller';
import SmartTransactionsController, {
SmartTransactionsControllerState,
} from '@metamask/smart-transactions-controller';
import { CustodyController } from '@metamask-institutional/custody-controller';
import { InstitutionalFeaturesController } from '@metamask-institutional/institutional-features';
import { MmiConfigurationController } from '@metamask-institutional/custody-keyring';

import AccountTrackerController, {
AccountTrackerControllerState,
} from '../../app/scripts/controllers/account-tracker-controller';
import {
BalancesController,
BalancesControllerState,
} from '../../app/scripts/lib/accounts/BalancesController';
import {
NetworkOrderController,
NetworkOrderControllerState,
} from '../../app/scripts/controllers/network-order';
import {
AccountOrderController,
AccountOrderControllerState,
} from '../../app/scripts/controllers/account-order';
import {
PreferencesController,
PreferencesControllerState,
} from '../../app/scripts/controllers/preferences-controller';
import {
AppStateController,
AppStateControllerState,
} from '../../app/scripts/controllers/app-state-controller';
import {
AlertController,
AlertControllerState,
} from '../../app/scripts/controllers/alert-controller';
import {
MetaMetricsDataDeletionController,
MetaMetricsDataDeletionState,
} from '../../app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion';
import BridgeController from '../../app/scripts/controllers/bridge/bridge-controller';
import BridgeStatusController from '../../app/scripts/controllers/bridge-status/bridge-status-controller';
import SwapsController from '../../app/scripts/controllers/swaps';
import EncryptionPublicKeyController, {
EncryptionPublicKeyControllerState,
} from '../../app/scripts/controllers/encryption-public-key';
import DecryptMessageController, {
DecryptMessageControllerState,
} from '../../app/scripts/controllers/decrypt-message';
import OnboardingController, {
OnboardingControllerState,
} from '../../app/scripts/controllers/onboarding';
import MetaMetricsController, {
MetaMetricsControllerState,
} from '../../app/scripts/controllers/metametrics-controller';
import AppMetadataController, {
AppMetadataControllerState,
} from '../../app/scripts/controllers/app-metadata';
import { SwapsControllerState } from '../../app/scripts/controllers/swaps/swaps.types';

import { BridgeControllerState as BridgeState } from './bridge';
import { BridgeStatusControllerState as BridgeStatusState } from './bridge-status';

export type ResetOnRestartStores = {
AccountTracker: AccountTrackerController;
TokenRatesController: TokenRatesController;
DecryptMessageController: DecryptMessageController;
EncryptionPublicKeyController: EncryptionPublicKeyController;
SignatureController: SignatureController;
SwapsController: SwapsController;
BridgeController: BridgeController;
BridgeStatusController: BridgeStatusController;
EnsController: EnsController;
ApprovalController: ApprovalController;
PPOMController: PPOMController;
};

export type ResetOnRestartStoresComposedState = {
AccountTracker: AccountTrackerControllerState;
TokenRatesController: TokenRatesControllerState;
DecryptMessageController: DecryptMessageControllerState;
EncryptionPublicKeyController: EncryptionPublicKeyControllerState;
SignatureController: SignatureControllerState;
SwapsController: SwapsControllerState;
BridgeController: BridgeState;
BridgeStatusController: BridgeStatusState;
EnsController: EnsControllerState;
ApprovalController: ApprovalControllerState;
PPOMController: PPOMState;
};

export type StoreControllers = ResetOnRestartStores & {
AccountsController: AccountsController;
AppStateController: AppStateController;
AppMetadataController: AppMetadataController;
MultichainBalancesController: BalancesController;
TransactionController: TransactionController;
KeyringController: KeyringController;
PreferencesController: PreferencesController;
MetaMetricsController: MetaMetricsController;
MetaMetricsDataDeletionController: MetaMetricsDataDeletionController;
AddressBookController: AddressBookController;
CurrencyController: CurrencyRateController;
NetworkController: NetworkController;
AlertController: AlertController;
OnboardingController: OnboardingController;
PermissionController: PermissionController<
PermissionSpecificationConstraint,
CaveatConstraint
>;
PermissionLogController: PermissionLogController;
SubjectMetadataController: SubjectMetadataController;
AnnouncementController: AnnouncementController;
NetworkOrderController: NetworkOrderController;
AccountOrderController: AccountOrderController;
GasFeeController: GasFeeController;
TokenListController: TokenListController;
TokensController: TokensController;
TokenBalancesController: TokenBalancesController;
SmartTransactionsController: SmartTransactionsController;
NftController: NftController;
PhishingController: PhishingController;
SelectedNetworkController: SelectedNetworkController;
LoggingController: LoggingController;
MultichainRatesController: RatesController;
SnapController: SnapController;
CronjobController: CronjobController;
SnapsRegistry: JsonSnapsRegistry;
SnapInterfaceController: SnapInterfaceController;
SnapInsightsController: SnapInsightsController;
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
CustodyController: CustodyController;
InstitutionalFeaturesController: InstitutionalFeaturesController;
MmiConfigurationController: MmiConfigurationController;
///: END:ONLY_INCLUDE_IF
NameController: NameController;
UserOperationController: UserOperationController;
// Notification Controllers
AuthenticationController: AuthenticationController.Controller;
UserStorageController: UserStorageController.Controller;
NotificationServicesController: NotificationServicesController.Controller;
NotificationServicesPushController: NotificationServicesPushController.Controller;
RemoteFeatureFlagController: RemoteFeatureFlagController;
};

export type StoreControllersComposedState =
ResetOnRestartStoresComposedState & {
AccountsController: AccountsControllerState;
AppStateController: AppStateControllerState;
AppMetadataController: AppMetadataControllerState;
MultichainBalancesController: BalancesControllerState;
TransactionController: TransactionControllerState;
KeyringController: KeyringControllerState;
PreferencesController: PreferencesControllerState;
MetaMetricsController: MetaMetricsControllerState;
MetaMetricsDataDeletionController: MetaMetricsDataDeletionState;
AddressBookController: AddressBookControllerState;
CurrencyController: CurrencyRateState;
NetworkController: NetworkState;
AlertController: AlertControllerState;
OnboardingController: OnboardingControllerState;
PermissionController: PermissionControllerState<PermissionConstraint>;
PermissionLogController: PermissionLogControllerState;
SubjectMetadataController: SubjectMetadataControllerState;
AnnouncementController: AnnouncementControllerState;
NetworkOrderController: NetworkOrderControllerState;
AccountOrderController: AccountOrderControllerState;
GasFeeController: GasFeeState;
TokenListController: TokenListState;
TokensController: TokensControllerState;
TokenBalancesController: TokenBalancesControllerState;
SmartTransactionsController: SmartTransactionsControllerState;
NftController: NftControllerState;
PhishingController: PhishingControllerState;
SelectedNetworkController: SelectedNetworkControllerState;
LoggingController: LoggingControllerState;
MultichainRatesController: RatesControllerState;
SnapController: SnapControllerState;
CronjobController: CronjobControllerState;
SnapsRegistry: SnapsRegistryState;
SnapInterfaceController: SnapInterfaceControllerState;
SnapInsightsController: SnapInsightsControllerState;
NameController: NameControllerState;
UserOperationController: UserOperationControllerState;
// Notification Controllers
AuthenticationController: AuthenticationController.AuthenticationControllerState;
UserStorageController: UserStorageController.UserStorageControllerState;
NotificationServicesController: NotificationServicesController.NotificationServicesControllerState;
NotificationServicesPushController: NotificationServicesPushController.NotificationServicesPushControllerState;
RemoteFeatureFlagController: RemoteFeatureFlagControllerState;
};

export type MemStoreControllers = Omit<
StoreControllers,
'PhishingController' | 'TransactionController'
> & {
TxController: TransactionController;
QueuedRequestController: QueuedRequestController;
};

export type MemStoreControllersComposedState = Omit<
StoreControllersComposedState,
'PhishingController' | 'TransactionController'
> & {
TxController: TransactionControllerState;
QueuedRequestController: QueuedRequestControllerState;
};

export type BackgroundStateProxy = {
isInitialized: boolean;
} & MemStoreControllersComposedState;
Loading
Loading