@metamask/controllers@15.0.0 (#11975)

Adds the latest version of `@metamask/controllers`, and updates our usage of the `ApprovalController`, which has been migrated to `BaseControllerV2`. Of [the new `controllers` release](https://github.com/MetaMask/controllers/releases/tag/v15.0.0), only the `ApprovalController` migration should be breaking.

This is the first time we use events on the `ControllerMessenger` to update the badge, so I turned the messenger into a property on the main `MetaMaskController` in order to subscribe to events on it in `background.js`. I confirmed that the badge does indeed update during local QA.

As it turns out, [MetaMask/controllers#571](https://github.com/MetaMask/controllers/pull/571) was breaking for a single unit test case, which is now handled during setup and teardown for the related test suite (`metamask-controller.test.js`).
feature/default_network_editable
Erik Marks 3 years ago committed by Alex
parent c5c5d266db
commit 049c863f83
  1. 6
      app/scripts/background.js
  2. 2
      app/scripts/controllers/permissions/index.js
  3. 19
      app/scripts/metamask-controller.js
  4. 2
      app/scripts/metamask-controller.test.js
  5. 3
      test/mocks/permission-controller.js
  6. 12
      yarn.lock

@ -435,12 +435,16 @@ function setupController(initState, initLangCode) {
METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,
updateBadge,
);
controller.approvalController.subscribe(updateBadge);
controller.appStateController.on(
METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,
updateBadge,
);
controller.controllerMessenger.subscribe(
METAMASK_CONTROLLER_EVENTS.APPROVAL_STATE_CHANGE,
updateBadge,
);
/**
* Updates the Web Extension's "badge" number, on the little fox in the toolbar.
* The number reflects the current number of pending transactions or message signatures needing user approval.

@ -249,7 +249,7 @@ export class PermissionsController {
approved.permissions,
accounts,
);
this.approvals.resolve(id, approved.permissions);
this.approvals.accept(id, approved.permissions);
}
} catch (err) {
// if finalization fails, reject the request

@ -76,6 +76,8 @@ export const METAMASK_CONTROLLER_EVENTS = {
// Fired after state changes that impact the extension badge (unapproved msg count)
// The process of updating the badge happens in app/scripts/background.js.
UPDATE_BADGE: 'updateBadge',
// TODO: Add this and similar enums to @metamask/controllers and export them
APPROVAL_STATE_CHANGE: 'ApprovalController:stateChange',
};
export default class MetamaskController extends EventEmitter {
@ -106,12 +108,12 @@ export default class MetamaskController extends EventEmitter {
this.getRequestAccountTabIds = opts.getRequestAccountTabIds;
this.getOpenMetamaskTabsIds = opts.getOpenMetamaskTabsIds;
const controllerMessenger = new ControllerMessenger();
this.controllerMessenger = new ControllerMessenger();
// observable state store
this.store = new ComposableObservableStore({
state: initState,
controllerMessenger,
controllerMessenger: this.controllerMessenger,
});
// external connections by origin
@ -131,6 +133,9 @@ export default class MetamaskController extends EventEmitter {
// controller initialization order matters
this.approvalController = new ApprovalController({
messenger: this.controllerMessenger.getRestricted({
name: 'ApprovalController',
}),
showApprovalRequest: opts.showUserConfirmation,
});
@ -169,7 +174,7 @@ export default class MetamaskController extends EventEmitter {
initState: initState.MetaMetricsController,
});
const gasFeeMessenger = controllerMessenger.getRestricted({
const gasFeeMessenger = this.controllerMessenger.getRestricted({
name: 'GasFeeController',
});
@ -210,7 +215,7 @@ export default class MetamaskController extends EventEmitter {
preferencesStore: this.preferencesController.store,
});
const currencyRateMessenger = controllerMessenger.getRestricted({
const currencyRateMessenger = this.controllerMessenger.getRestricted({
name: 'CurrencyRateController',
});
this.currencyRateController = new CurrencyRateController({
@ -219,7 +224,7 @@ export default class MetamaskController extends EventEmitter {
state: initState.CurrencyController,
});
const tokenListMessenger = controllerMessenger.getRestricted({
const tokenListMessenger = this.controllerMessenger.getRestricted({
name: 'TokenListController',
});
this.tokenListController = new TokenListController({
@ -569,7 +574,7 @@ export default class MetamaskController extends EventEmitter {
GasFeeController: this.gasFeeController,
TokenListController: this.tokenListController,
},
controllerMessenger,
controllerMessenger: this.controllerMessenger,
});
this.memStore.subscribe(this.sendUpdate.bind(this));
@ -1097,7 +1102,7 @@ export default class MetamaskController extends EventEmitter {
// approval controller
resolvePendingApproval: nodeify(
approvalController.resolve,
approvalController.accept,
approvalController,
),
rejectPendingApproval: nodeify(

@ -109,6 +109,7 @@ describe('MetaMaskController', function () {
const noop = () => undefined;
before(async function () {
globalThis.AbortController = window.AbortController;
await ganacheServer.start();
});
@ -157,6 +158,7 @@ describe('MetaMaskController', function () {
after(async function () {
await ganacheServer.quit();
delete globalThis.AbortController;
});
describe('#getAccounts', function () {

@ -1,7 +1,7 @@
import { ethErrors, errorCodes } from 'eth-rpc-errors';
import deepFreeze from 'deep-freeze-strict';
import { ApprovalController } from '@metamask/controllers';
import { ApprovalController, ControllerMessenger } from '@metamask/controllers';
import _getRestrictedMethods from '../../app/scripts/controllers/permissions/restrictedMethods';
@ -70,6 +70,7 @@ const getRestrictedMethods = (permController) => {
export function getPermControllerOpts() {
return {
approvals: new ApprovalController({
messenger: new ControllerMessenger(),
showApprovalRequest: noop,
}),
getKeyringAccounts: async () => [...keyringAccounts],

@ -3040,17 +3040,7 @@
semver "^7.3.5"
yargs "^17.0.1"
"@metamask/contract-metadata@^1.19.0":
version "1.25.0"
resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-1.25.0.tgz#442ace91fb40165310764b68d8096d0017bb0492"
integrity sha512-yhmYB9CQPv0dckNcPoWDcgtrdUp0OgK0uvkRE5QIBv4b3qENI1/03BztvK2ijbTuMlORUpjPq7/1MQDUPoRPVw==
"@metamask/contract-metadata@^1.28.0":
version "1.28.0"
resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-1.28.0.tgz#76796f5010aa4aa6d28bf6fe36392017cea687cb"
integrity sha512-QZj6Y1nmSs9BHufBS1GSuPX5TVFa5gbtMhEo/KRuSdKyY43OdlbBKuyT36/l5p30krlzfMX8bN0MAWqw3g0Bog==
"@metamask/contract-metadata@^1.29.0":
"@metamask/contract-metadata@^1.19.0", "@metamask/contract-metadata@^1.28.0", "@metamask/contract-metadata@^1.29.0":
version "1.29.0"
resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-1.29.0.tgz#4ca86a2f03d4dad4350d09216a7fe92f9dd21c8e"
integrity sha512-wxsC0ZCyhPKqThvmsL8+2zVWGWPqofSo8HNtOuOnQM9oGbXX9294imJ3T+A/Lov8fkX4jAWZOeNV0uR80zkNtA==

Loading…
Cancel
Save