Skip to content

Commit

Permalink
Merge branch 'main' into brian/network-controller-race-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
bergeron authored Jan 16, 2025
2 parents 8a52867 + 21c4ec6 commit 66ba52c
Show file tree
Hide file tree
Showing 88 changed files with 2,853 additions and 1,638 deletions.
3 changes: 0 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
## Accounts Team
/packages/accounts-controller @MetaMask/accounts-engineers
/packages/keyring-controller @MetaMask/accounts-engineers
/packages/chain-controller @MetaMask/accounts-engineers

## Assets Team
/packages/assets-controllers @MetaMask/metamask-assets
Expand Down Expand Up @@ -71,8 +70,6 @@
/packages/approval-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/assets-controllers/package.json @MetaMask/metamask-assets @MetaMask/wallet-framework-engineers
/packages/assets-controllers/CHANGELOG.md @MetaMask/metamask-assets @MetaMask/wallet-framework-engineers
/packages/chain-controller/package.json @MetaMask/accounts-engineers @MetaMask/wallet-framework-engineers
/packages/chain-controller/CHANGELOG.md @MetaMask/accounts-engineers @MetaMask/wallet-framework-engineers
/packages/ens-controller/package.json @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/ens-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/gas-fee-controller/package.json @MetaMask/confirmations @MetaMask/wallet-framework-engineers
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Each package in this repository has its own README where you can find installati
- [`@metamask/assets-controllers`](packages/assets-controllers)
- [`@metamask/base-controller`](packages/base-controller)
- [`@metamask/build-utils`](packages/build-utils)
- [`@metamask/chain-controller`](packages/chain-controller)
- [`@metamask/composable-controller`](packages/composable-controller)
- [`@metamask/controller-utils`](packages/controller-utils)
- [`@metamask/ens-controller`](packages/ens-controller)
Expand Down Expand Up @@ -70,7 +69,6 @@ linkStyle default opacity:0.5
assets_controllers(["@metamask/assets-controllers"]);
base_controller(["@metamask/base-controller"]);
build_utils(["@metamask/build-utils"]);
chain_controller(["@metamask/chain-controller"]);
composable_controller(["@metamask/composable-controller"]);
controller_utils(["@metamask/controller-utils"]);
ens_controller(["@metamask/ens-controller"]);
Expand Down Expand Up @@ -112,7 +110,6 @@ linkStyle default opacity:0.5
assets_controllers --> network_controller;
assets_controllers --> preferences_controller;
base_controller --> json_rpc_engine;
chain_controller --> base_controller;
composable_controller --> base_controller;
composable_controller --> json_rpc_engine;
ens_controller --> base_controller;
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ If you need to customize the behavior of Jest for a package, see `jest.config.js
## Linting

[ESLint](https://eslint.org/docs/v8.x/) v8 (via [MetaMask's shared ESLint configurations](https://github.com/MetaMask/eslint-config)) is used to check for code quality issues, and [Prettier](https://prettier.io/docs/en/) is used to format files.
[ESLint](https://eslint.org) v9 (via [MetaMask's shared ESLint configurations](https://github.com/MetaMask/eslint-config)) is used to check for code quality issues, and [Prettier](https://prettier.io/docs/en/) is used to format files.

If you need to customize the behavior of ESLint, see `.eslintrc.js` in the root.
If you need to customize the behavior of ESLint, see `eslint.config.mjs` in the root.

- Run `yarn lint` to lint all files and show possible violations across the monorepo.
- Run `yarn lint:fix` to fix any automatically fixable violations.
Expand Down
64 changes: 29 additions & 35 deletions docs/writing-controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ If the recipient controller supports the messaging system, however, the callback

const name = 'FooController';

type FooControllerMessenger = RestrictedControllerMessenger<
type FooControllerMessenger = RestrictedMessenger<
typeof name,
never,
never,
Expand All @@ -247,10 +247,7 @@ class FooController extends BaseController<

// === Client repo ===

const rootMessenger = new ControllerMessenger<
'BarController:stateChange',
never
>();
const rootMessenger = new Messenger<'BarController:stateChange', never>();
const barControllerMessenger = rootMessenger.getRestricted({
name: 'BarController',
});
Expand Down Expand Up @@ -307,7 +304,7 @@ However, this pattern can be replaced with the use of the messenger:

const name = 'FooController';

type FooControllerMessenger = RestrictedControllerMessenger<
type FooControllerMessenger = RestrictedMessenger<
typeof name,
never,
never,
Expand All @@ -331,10 +328,7 @@ class FooController extends BaseController<

// === Client repo ===

const rootMessenger = new ControllerMessenger<
'FooController:someEvent',
never
>();
const rootMessenger = new Messenger<'FooController:someEvent', never>();
const fooControllerMessenger = rootMessenger.getRestricted({
name: 'FooController',
});
Expand Down Expand Up @@ -505,7 +499,7 @@ A controller should define and export a type union that holds all of its actions

The name of this type should be `${ControllerName}Actions`.

This type should be only passed to `RestrictedControllerMessenger` as the 2nd type parameter. It should _not_ be included in its 4th type parameter, as that is is used for external actions.
This type should be only passed to `RestrictedMessenger` as the 2nd type parameter. It should _not_ be included in its 4th type parameter, as that is is used for external actions.

🚫 **`FooController['type']` is passed as the 4th type parameter**

Expand All @@ -514,7 +508,7 @@ export type FooControllerActions =
| FooControllerUpdateCurrencyAction
| FooControllerUpdateRatesAction;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
FooControllerActions,
never,
Expand All @@ -530,7 +524,7 @@ export type FooControllerActions =
| FooControllerUpdateCurrencyAction
| FooControllerUpdateRatesAction;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
FooControllerActions,
never,
Expand All @@ -545,7 +539,7 @@ A controller should define and export a type union that holds all of its events.

The name of this type should be `${ControllerName}Events`.

This type should be only passed to `RestrictedControllerMessenger` as the 3rd type parameter. It should _not_ be included in its 5th type parameter, as that is is used for external events.
This type should be only passed to `RestrictedMessenger` as the 3rd type parameter. It should _not_ be included in its 5th type parameter, as that is is used for external events.

🚫 **`FooControllerEvents['type']` is passed as the 5th type parameter**

Expand All @@ -554,7 +548,7 @@ export type FooControllerEvents =
| FooControllerMessageReceivedEvent
| FooControllerNotificationAddedEvent;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
never,
FooControllerEvents,
Expand All @@ -570,7 +564,7 @@ export type FooControllerEvents =
| FooControllerMessageReceivedEvent
| FooControllerNotificationAddedEvent;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
never,
FooControllerEvents,
Expand All @@ -583,11 +577,11 @@ export type FooControllerMessenger = RestrictedControllerMessenger<

A controller may wish to call actions defined by other controllers, and therefore will need to define them in the messenger's allowlist.

In this case, the controller should group these types into a type union so that they can be easily passed to the `RestrictedControllerMessenger` type. However, it should not export this type, as it would then be re-exporting types that another package has already exported.
In this case, the controller should group these types into a type union so that they can be easily passed to the `RestrictedMessenger` type. However, it should not export this type, as it would then be re-exporting types that another package has already exported.

The name of this type should be `AllowedActions`.

This type should not only be passed to `RestrictedControllerMessenger` as the 2nd type parameter, but should also be included in its 4th type parameter.
This type should not only be passed to `RestrictedMessenger` as the 2nd type parameter, but should also be included in its 4th type parameter.

🚫 **`never` is passed as the 4th type parameter**

Expand All @@ -596,7 +590,7 @@ export type AllowedActions =
| BarControllerDoSomethingAction
| BarControllerDoSomethingElseAction;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
AllowedActions,
never,
Expand All @@ -614,7 +608,7 @@ export type AllowedActions =
| BarControllerDoSomethingAction
| BarControllerDoSomethingElseAction;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
AllowedActions,
never,
Expand All @@ -634,7 +628,7 @@ type AllowedActions =
| BarControllerDoSomethingAction
| BarControllerDoSomethingElseAction;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
AllowedActions,
never,
Expand All @@ -649,7 +643,7 @@ If, in a test, you need to access all of the actions included in a controller's
// NOTE: You may need to adjust the path depending on where you are
import { ExtractAvailableAction } from '../../base-controller/tests/helpers';

const messenger = new ControllerMessenger<
const messenger = new Messenger<
ExtractAvailableAction<FooControllerMessenger>,
never
>();
Expand All @@ -659,11 +653,11 @@ const messenger = new ControllerMessenger<

A controller may wish to subscribe to events defined by other controllers, and therefore will need to define them in the messenger's allowlist.

In this case, the controller should group these types into a type union so that they can be easily passed to the `RestrictedControllerMessenger` type. However, it should not export this type, as it would then be re-exporting types that another package has already exported.
In this case, the controller should group these types into a type union so that they can be easily passed to the `RestrictedMessenger` type. However, it should not export this type, as it would then be re-exporting types that another package has already exported.

The name of this type should be `AllowedEvents`.

This type should not only be passed to `RestrictedControllerMessenger` as the 3rd type parameter, but should also be included in its 5th type parameter.
This type should not only be passed to `RestrictedMessenger` as the 3rd type parameter, but should also be included in its 5th type parameter.

🚫 **`never` is passed as the 5th type parameter**

Expand All @@ -672,7 +666,7 @@ export type AllowedEvents =
| BarControllerSomethingHappenedEvent
| BarControllerSomethingElseHappenedEvent;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
never,
AllowedEvents,
Expand All @@ -690,7 +684,7 @@ export type AllowedEvents =
| BarControllerSomethingHappenedEvent
| BarControllerSomethingElseHappenedEvent;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
never,
AllowedEvents,
Expand All @@ -710,7 +704,7 @@ type AllowedEvents =
| BarControllerSomethingHappenedEvent
| BarControllerSomethingElseHappenedEvent;

export type FooControllerMessenger = RestrictedControllerMessenger<
export type FooControllerMessenger = RestrictedMessenger<
'FooController',
never,
AllowedEvents,
Expand All @@ -725,7 +719,7 @@ If, in a test, you need to access all of the events included in a controller's m
// NOTE: You may need to adjust the path depending on where you are
import { ExtractAvailableEvent } from '../../base-controller/tests/helpers';

const messenger = new ControllerMessenger<
const messenger = new Messenger<
never,
ExtractAvailableEvent<FooControllerMessenger>
>();
Expand Down Expand Up @@ -790,7 +784,7 @@ export type AllowedEvents =
| ApprovalControllerApprovalRequestApprovedEvent
| ApprovalControllerApprovalRequestRejectedEvent;

export type SwapsControllerMessenger = RestrictedControllerMessenger<
export type SwapsControllerMessenger = RestrictedMessenger<
'SwapsController',
SwapsControllerActions | AllowedActions,
SwapsControllerEvents | AllowedEvents,
Expand All @@ -802,7 +796,7 @@ export type SwapsControllerMessenger = RestrictedControllerMessenger<
A messenger that allows no actions or events (whether internal or external) looks like this:

```typescript
export type SwapsControllerMessenger = RestrictedControllerMessenger<
export type SwapsControllerMessenger = RestrictedMessenger<
'SwapsController',
never,
never,
Expand Down Expand Up @@ -1175,7 +1169,7 @@ import { AccountsControllerGetStateAction } from '@metamask/accounts-controller'

type AllowedActions = AccountsControllerGetStateAction;

type PreferencesControllerMessenger = RestrictedControllerMessenger<
type PreferencesControllerMessenger = RestrictedMessenger<
'PreferencesController',
AllowedActions,
never,
Expand Down Expand Up @@ -1273,7 +1267,7 @@ type AccountsControllerActions =
| AccountsControllerGetActiveAccountAction
| AccountsControllerGetInactiveAccountsAction;

export type AccountsControllerMessenger = RestrictedControllerMessenger<
export type AccountsControllerMessenger = RestrictedMessenger<
'AccountsController',
AccountsControllerActions,
never,
Expand Down Expand Up @@ -1302,7 +1296,7 @@ type AllowedActions =
| AccountsControllerGetActiveAccountsAction
| AccountsControllerGetInactiveAccountsAction;

export type TokensControllerMessenger = RestrictedControllerMessenger<
export type TokensControllerMessenger = RestrictedMessenger<
'TokensController',
AllowedActions,
never,
Expand Down Expand Up @@ -1383,7 +1377,7 @@ export type AccountsControllerGetStateAction = ControllerGetStateAction<

type AccountsControllerActions = AccountsControllerGetStateAccountAction;

export type AccountsControllerMessenger = RestrictedControllerMessenger<
export type AccountsControllerMessenger = RestrictedMessenger<
'AccountsController',
AccountsControllerActions,
never,
Expand All @@ -1400,7 +1394,7 @@ import { accountsControllerSelectors } from '@metamask/accounts-controller';

type AllowedActions = AccountsControllerGetStateAction;

export type TokensControllerMessenger = RestrictedControllerMessenger<
export type TokensControllerMessenger = RestrictedMessenger<
'TokensController',
AllowedActions,
never,
Expand Down
29 changes: 29 additions & 0 deletions eslint-warning-thresholds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"@typescript-eslint/consistent-type-exports": 19,
"@typescript-eslint/no-base-to-string": 3,
"@typescript-eslint/no-duplicate-enum-values": 2,
"@typescript-eslint/no-unsafe-enum-comparison": 34,
"@typescript-eslint/no-unused-vars": 36,
"@typescript-eslint/prefer-promise-reject-errors": 13,
"@typescript-eslint/prefer-readonly": 145,
"import-x/namespace": 189,
"import-x/no-named-as-default": 1,
"import-x/no-named-as-default-member": 8,
"import-x/order": 205,
"jest/no-conditional-in-test": 129,
"jest/prefer-lowercase-title": 2,
"jest/prefer-strict-equal": 2,
"jsdoc/check-tag-names": 375,
"jsdoc/require-returns": 22,
"jsdoc/tag-lines": 328,
"n/no-unsupported-features/node-builtins": 18,
"n/prefer-global/text-encoder": 4,
"n/prefer-global/text-decoder": 4,
"prettier/prettier": 115,
"promise/always-return": 3,
"promise/catch-or-return": 2,
"promise/param-names": 8,
"no-empty-function": 2,
"no-shadow": 8,
"no-unused-private-class-members": 5
}
Loading

0 comments on commit 66ba52c

Please sign in to comment.