Skip to content

Commit

Permalink
define more actions/event types
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Jan 29, 2025
1 parent 5578510 commit cfa9778
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/core/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ import {
SnapControllerGetSnapAction,
SnapControllerGetSnapStateAction,
SnapControllerHandleRequestAction,
SnapControllerStateChangeAction,
SnapControllerStateChangeEvent,
SnapControllerUpdateSnapStateAction,
} from './controllers/SnapController/constants';

Expand Down Expand Up @@ -378,7 +378,7 @@ export class Engine {
this.controllerMessenger.getRestricted({
name: 'AccountsController',
allowedEvents: [
SnapControllerStateChangeAction,
SnapControllerStateChangeEvent,
'KeyringController:accountRemoved',
'KeyringController:stateChange',
],
Expand Down
16 changes: 11 additions & 5 deletions app/core/Engine/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { AccountsControllerStateChangeEvent } from './controllers/AccountsController/constants';
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
import { SnapControllerStateChangeAction } from './controllers/SnapController/constants';
import { SnapControllerStateChangeEvent } from './controllers/SnapController/constants';
///: END:ONLY_INCLUDE_IF

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { MultichainBalancesControllerStateChangeEvent } from './controllers/MultichainBalancesController/constants';
import { RatesControllerStateChangeEvent } from './controllers/RatesController/constants';
///: END:ONLY_INCLUDE_IF
/**
* Messageable modules that are part of the Engine's context, but are not defined with state.
Expand All @@ -12,7 +18,7 @@ export const STATELESS_NON_CONTROLLER_NAMES = [
] as const;

export const BACKGROUND_STATE_CHANGE_EVENT_NAMES = [
'AccountsController:stateChange',
AccountsControllerStateChangeEvent,
'AccountTrackerController:stateChange',
'AddressBookController:stateChange',
'ApprovalController:stateChange',
Expand All @@ -37,7 +43,7 @@ export const BACKGROUND_STATE_CHANGE_EVENT_NAMES = [
'TokensController:stateChange',
'TransactionController:stateChange',
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
SnapControllerStateChangeAction,
SnapControllerStateChangeEvent,
'SnapsRegistry:stateChange',
'SubjectMetadataController:stateChange',
'AuthenticationController:stateChange',
Expand All @@ -46,7 +52,7 @@ export const BACKGROUND_STATE_CHANGE_EVENT_NAMES = [
'NotificationServicesPushController:stateChange',
///: END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
'MultichainBalancesController:stateChange',
'RatesController:stateChange',
MultichainBalancesControllerStateChangeEvent,
RatesControllerStateChangeEvent,
///: END:ONLY_INCLUDE_IF
] as const;
3 changes: 3 additions & 0 deletions app/core/Engine/controllers/AccountsController/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AccountsControllerChangeEvent as AccountsControllerStateChangeEventType,
AccountsControllerGetAccountByAddressAction as AccountsControllerGetAccountByAddressActionType,
AccountsControllerSetAccountNameAction as AccountsControllerSetAccountNameActionType,
AccountsControllerSetSelectedAccountAction as AccountsControllerSetSelectedAccountActionType,
Expand Down Expand Up @@ -37,6 +38,8 @@ export const AccountsControllerListMultichainAccountsAction: AccountsControllerL
///: END:ONLY_INCLUDE_IF

// Events of AccountsController
export const AccountsControllerStateChangeEvent: AccountsControllerStateChangeEventType['type'] =
'AccountsController:stateChange';
export const AccountsControllerSelectedEvmAccountChangeEvent: AccountsControllerSelectedEvmAccountChangeEventType['type'] =
'AccountsController:selectedEvmAccountChange';
export const AccountsControllerSelectedAccountChangeEvent: AccountsControllerSelectedAccountChangeEventType['type'] =
Expand Down
4 changes: 2 additions & 2 deletions app/core/Engine/controllers/AccountsController/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { withScope } from '@sentry/react-native';
import { AGREED, METRICS_OPT_IN } from '../../../../constants/storage';
import StorageWrapper from '../../../../store/storage-wrapper';
import { logAccountsControllerCreation } from './logger';
import { SnapControllerStateChangeAction } from '../SnapController/constants';
import { SnapControllerStateChangeEvent } from '../SnapController/constants';

jest.mock('@sentry/react-native', () => ({
withScope: jest.fn(),
Expand All @@ -34,7 +34,7 @@ describe('accountControllersUtils', () => {
accountsControllerMessenger = globalMessenger.getRestricted({
name: 'AccountsController',
allowedEvents: [
SnapControllerStateChangeAction,
SnapControllerStateChangeEvent,
'KeyringController:accountRemoved',
'KeyringController:stateChange',
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MultichainBalancesControllerStateChange as MultichainBalancesControllerStateChangeEventType } from '@metamask/assets-controllers';

// Events
export const MultichainBalancesControllerStateChangeEvent: MultichainBalancesControllerStateChangeEventType['type'] =
'MultichainBalancesController:stateChange';
5 changes: 5 additions & 0 deletions app/core/Engine/controllers/RatesController/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { RatesControllerStateChangeEvent as RatesControllerStateChangeEventType } from '@metamask/assets-controllers';

// Events
export const RatesControllerStateChangeEvent: RatesControllerStateChangeEventType['type'] =
'RatesController:stateChange';
10 changes: 6 additions & 4 deletions app/core/Engine/controllers/SnapController/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
SnapStateChange as SnapControllerStateChangeEventType,
HandleSnapRequest as SnapControllerHandleRequestActionType,
SnapStateChange as SnapControllerStateChangeActionType,
ClearSnapState as SnapControllerClearSnapStateActionType,
GetSnap as SnapControllerGetSnapActionType,
GetSnapState as SnapControllerGetSnapStateActionType,
Expand All @@ -10,12 +10,14 @@ import {
GetSnapFile as SnapControllerGetSnapFileActionType,
} from '@metamask/snaps-controllers';

// Events
export const SnapControllerStateChangeEvent: SnapControllerStateChangeEventType['type'] =
'SnapController:stateChange';

// Actions
export const SnapControllerHandleRequestAction: SnapControllerHandleRequestActionType['type'] =
'SnapController:handleRequest';

export const SnapControllerStateChangeAction: SnapControllerStateChangeActionType['type'] =
'SnapController:stateChange';

export const SnapControllerClearSnapStateAction: SnapControllerClearSnapStateActionType['type'] =
'SnapController:clearSnapState';

Expand Down

0 comments on commit cfa9778

Please sign in to comment.