Skip to content

Commit

Permalink
Accounts controller actions/events
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Feb 28, 2024
1 parent 28a6805 commit f88a93f
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ import { isHardwareAccount } from '../util/address';
import { ledgerSignTypedMessage } from './Ledger/Ledger';
import ExtendedKeyringTypes from '../constants/keyringTypes';
import { UpdatePPOMInitializationStatus } from '../actions/experimental';
import {
AccountsController,
AccountsControllerActions,
AccountsControllerEvents,
AccountsControllerState,
} from '@metamask/accounts-controller';

const NON_EMPTY = 'NON_EMPTY';

Expand Down Expand Up @@ -225,21 +231,22 @@ type GlobalActions =
///: BEGIN:ONLY_INCLUDE_IF(snaps)
| SnapsGlobalActions
///: END:ONLY_INCLUDE_IF
| KeyringControllerActions;
| KeyringControllerActions
| AccountsControllerActions;
type GlobalEvents =
| ApprovalControllerEvents
| CurrencyRateStateChange
| GasFeeStateChange
| TokenListStateChange
| NetworkControllerEvents
| PermissionControllerEvents
| KeyringControllerEvents
///: BEGIN:ONLY_INCLUDE_IF(snaps)
| SnapsGlobalEvents
///: END:ONLY_INCLUDE_IF
| SignatureControllerEvents
| KeyringControllerEvents
| PPOMControllerEvents;
| PPOMControllerEvents
| AccountsControllerEvents;

type PermissionsByRpcMethod = ReturnType<typeof getPermissionSpecifications>;
type Permissions = PermissionsByRpcMethod[keyof PermissionsByRpcMethod];
Expand Down Expand Up @@ -272,6 +279,7 @@ export interface EngineState {
ApprovalController: ApprovalControllerState;
LoggingController: LoggingControllerState;
PPOMController: PPOMState;
AccountsController: AccountsControllerState;
}

/**
Expand Down Expand Up @@ -312,6 +320,7 @@ class Engine {
TransactionController: TransactionController;
SignatureController: SignatureController;
SwapsController: SwapsController;
AccountsController: AccountsController;
}
| any;
/**
Expand Down Expand Up @@ -897,6 +906,31 @@ class Engine {
///: END:ONLY_INCLUDE_IF

const codefiTokenApiV2 = new CodefiTokenPricesServiceV2();
const accountsControllerMessenger = this.controllerMessenger.getRestricted({
name: 'AccountsController',
allowedEvents: [
'SnapController:stateChange',
'KeyringController:accountRemoved',
'KeyringController:stateChange',
'AccountsController:selectedAccountChange',

Check failure on line 915 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type '"AccountsController:selectedAccountChange"' is not assignable to type '"NetworkController:stateChange" | "KeyringController:stateChange" | "PPOMController:initialisationStateChangeEvent" | "SnapController:snapBlocked" | "SnapController:snapInstalled" | ... 27 more ... | "KeyringController:qrKeyringStateChange"'.
],
allowedActions: [
'AccountsController:setCurrentAccount',

Check failure on line 918 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type '"AccountsController:setCurrentAccount"' is not assignable to type '"SnapController:getPermitted" | "SnapController:install" | `${string}:maybeUpdateState` | `${string}:testOrigin` | "SnapController:clearSnapState" | "SnapController:get" | "SnapController:getSnapState" | ... 68 more ... | "KeyringController:getKeyringForAccount"'.
'AccountsController:setAccountName',

Check failure on line 919 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type '"AccountsController:setAccountName"' is not assignable to type '"SnapController:getPermitted" | "SnapController:install" | `${string}:maybeUpdateState` | `${string}:testOrigin` | "SnapController:clearSnapState" | "SnapController:get" | "SnapController:getSnapState" | ... 68 more ... | "KeyringController:getKeyringForAccount"'.
'AccountsController:listAccounts',

Check failure on line 920 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type '"AccountsController:listAccounts"' is not assignable to type '"SnapController:getPermitted" | "SnapController:install" | `${string}:maybeUpdateState` | `${string}:testOrigin` | "SnapController:clearSnapState" | "SnapController:get" | "SnapController:getSnapState" | ... 68 more ... | "KeyringController:getKeyringForAccount"'.
'AccountsController:getSelectedAccount',

Check failure on line 921 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type '"AccountsController:getSelectedAccount"' is not assignable to type '"SnapController:getPermitted" | "SnapController:install" | `${string}:maybeUpdateState` | `${string}:testOrigin` | "SnapController:clearSnapState" | "SnapController:get" | "SnapController:getSnapState" | ... 68 more ... | "KeyringController:getKeyringForAccount"'.
'AccountsController:getAccountByAddress',

Check failure on line 922 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type '"AccountsController:getAccountByAddress"' is not assignable to type '"SnapController:getPermitted" | "SnapController:install" | `${string}:maybeUpdateState` | `${string}:testOrigin` | "SnapController:clearSnapState" | "SnapController:get" | "SnapController:getSnapState" | ... 68 more ... | "KeyringController:getKeyringForAccount"'.
'AccountsController:updateAccounts',

Check failure on line 923 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type '"AccountsController:updateAccounts"' is not assignable to type '"SnapController:getPermitted" | "SnapController:install" | `${string}:maybeUpdateState` | `${string}:testOrigin` | "SnapController:clearSnapState" | "SnapController:get" | "SnapController:getSnapState" | ... 68 more ... | "KeyringController:getKeyringForAccount"'.
'KeyringController:getAccounts',
'KeyringController:getKeyringsByType',
'KeyringController:getKeyringForAccount',
],
});

const accountsController = new AccountsController({
messenger: accountsControllerMessenger,
state: initialState.AccountsController,

Check failure on line 932 in app/core/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Type 'AccountsControllerState | undefined' is not assignable to type 'AccountsControllerState'.
});

const controllers = [
keyringController,
Expand Down Expand Up @@ -1116,6 +1150,7 @@ class Engine {
snapController,
subjectMetadataController,
///: END:ONLY_INCLUDE_IF
accountsController,
];

if (isBlockaidFeatureEnabled()) {
Expand Down

0 comments on commit f88a93f

Please sign in to comment.