-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[DNM] Preview branch of complete ComposableController
fix with no type error suppression
#10374
[DNM] Preview branch of complete ComposableController
fix with no type error suppression
#10374
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
8630e58
to
b1f33b3
Compare
1c88fa8
to
f59048b
Compare
202e843
to
e2625a2
Compare
9ca17c7
to
1de86a9
Compare
dd53c9a
to
76ef6e3
Compare
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring: Next stepsTake a deeper look at the dependencyTake a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev. Remove the packageIf you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency. Mark a package as acceptable riskTo ignore an alert, reply with a comment starting with |
76ef6e3
to
bbd680f
Compare
ComposableController
, ComposableControllerMessenger
ComposableController
fix with no type error suppression
f621262
to
2a02d12
Compare
b141caf
to
40d2d42
Compare
2a02d12
to
3848cbe
Compare
40d2d42
to
dfe27b9
Compare
3848cbe
to
1da89cb
Compare
dfe27b9
to
ca177f4
Compare
1da89cb
to
8f61eac
Compare
ca177f4
to
0250b07
Compare
@@ -120,7 +121,16 @@ | |||
"redux-persist-filesystem-storage/react-native-blob-util": "^0.19.9", | |||
"xmldom": "npm:@xmldom/xmldom@0.7.13", | |||
"@metamask/metamask-eth-abis": "3.1.1", | |||
"react-native/ws": "^6.2.3" | |||
"react-native/ws": "^6.2.3", | |||
"@metamask/snaps-controllers@^9.3.1": "patch:@metamask/snaps-controllers@npm%3A9.3.1#./.yarn/patches/@metamask-snaps-controllers-npm-9.3.1-6a141c6563.patch", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This repo already supports patches without yarnv3 via patch-package
, FYI.
package.json
Outdated
@@ -110,6 +110,7 @@ | |||
] | |||
}, | |||
"resolutions": { | |||
"@metamask/base-controller": "6.0.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This resolution should work under yarnv1 too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work fully, unfortunately.
Many of the nested resolutions fail with the following error message (the v1 docs warn about this, and also say that resolutions is a "fairly new feature"):
warning Resolution field "@metamask/base-controller@6.0.2" is incompatible with requested version "@metamask/base-controller@^5.0.2"
As a result, the base-controller version mismatch errors we see in almost every controller instantiation in the Engine
class are not fixed when using yarn v1 resolutions (repro branch vs. current branch).
Type 'RestrictedControllerMessenger<"ExampleController", ..., ..., ..., ...>' is not assignable to type 'ExampleControllerMessenger'.
Property '#private' in type 'RestrictedControllerMessenger' refers to a different member that cannot be accessed from within type 'RestrictedControllerMessenger'.ts(2322)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the newer git protocol syntax doesn't seem to be supported in v1, which was inconvenient.
I think I might have given the impression that I would be upgrading the yarn version in mobile with this PR, which isn't the case since this branch isn't intended to be merged into main. I should probably put that at the top of the PR.😅
… to `Global{Actions,Events}`
…age version that inherits from `BaseControllerV2` and registering to `Global{Actions,Events}`
…age version that inherits from `BaseControllerV2` and registering to `Global{Actions,Events}`
…orts missing `stateChange` type
…t exports missing `stateChange` type
…rn patch that exports missing `stateChange` type
…ating yarn patch that exports missing `stateChange` type
… exports missing `stateChange` type
4e2ec3b
to
36b966e
Compare
… into `ComposableController`
fe6b8f8
to
9e2449e
Compare
Controllers[Exclude<keyof Controllers, keyof NonControllers>] | ||
>({ | ||
controllers, | ||
// @ts-expect-error Resolve/patch mismatch between base-controller versions | ||
// ts(2322) - Property '#private' in type 'RestrictedControllerMessenger' refers to a different member that cannot be accessed from within type 'RestrictedControllerMessenger' | ||
controllers: controllers.filter( | ||
( | ||
controller, | ||
): controller is Controllers[Exclude< | ||
keyof Controllers, | ||
keyof NonControllers | ||
>] => | ||
'state' in controller && | ||
controller.state !== undefined && | ||
Object.keys(controller.state).length > 0, | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComposableController
now raises a type error if a non-controller lacking a state property is passed into the ChildControllers
generic parameter or the controllers constructor option.
Here, I've assigned the responsibility of ensuring correct input to the call site. This is out of a preference for explicit code and less "magical" behavior on part of the ComposableController
.
However, if this implementation seems too cumbersome, I could definitely look into implicitly handling this in the ComposableController
constructor.
TypeScript v5.5 introduces inferred type predicates, which should make this much less verbose, so waiting for that is also an option.
9e2449e
to
6ba9da2
Compare
app/core/Engine.ts
Outdated
export type EngineState = { | ||
AccountTrackerController: AccountTrackerState; | ||
AddressBookController: AddressBookState; | ||
AssetsContractController: BaseState; | ||
NftController: NftState; | ||
AccountTrackerController: AccountTrackerControllerState; | ||
AddressBookController: AddressBookControllerState; | ||
NftController: NftControllerState; | ||
TokenListController: TokenListState; | ||
CurrencyRateController: CurrencyRateState; | ||
KeyringController: KeyringControllerState; | ||
NetworkController: NetworkState; | ||
PreferencesController: PreferencesState; | ||
PhishingController: PhishingControllerState; | ||
TokenBalancesController: TokenBalancesControllerState; | ||
TokenRatesController: TokenRatesState; | ||
TokenRatesController: TokenRatesControllerState; | ||
TransactionController: TransactionControllerState; | ||
SmartTransactionsController: SmartTransactionsControllerState; | ||
SwapsController: SwapsState; | ||
GasFeeController: GasFeeState; | ||
TokensController: TokensState; | ||
TokenDetectionController: BaseState; | ||
NftDetectionController: BaseState; | ||
TokensController: TokensControllerState; | ||
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stateless non-controllers probably should be removed from EngineState
:
- These non-controllers do not have empty state objects or
BaseState
-- they lack astate
property entirely. - Non-controllers can still be included in
Controllers
type, and any information needed by the Engine class can be derived from the full controller class stored inControllers
.
Edit:
In the interest of minimizing invasive changes and unnecessary diffs, I've reverted this commit for now and opted to exclude the non-controllers when EngineState
is passed into ComposableController
as a generic argument instead.
ComposableController
fix with type error suppression removedComposableController
fix with no type error suppression
ComposableController
fix with no type error suppressionComposableController
fix with no type error suppression
This reverts commit 6ba9da2.
…trollerState` generic parameter
#4633) ## Explanation Fixes controllers and messengers in the core repo that do not fulfill their intended specifications correctly: - [Define the `*:getState` action using the `ControllerGetStateAction` utility type](https://github.com/MetaMask/core/blob/add-controller-guidelines/docs/writing-controllers.md#define-the-getstate-action-using-the-controllergetstateaction-utility-type) - [Define the `*:stateChange` event using the `ControllerStateChangeEvent` utility type](https://github.com/MetaMask/core/blob/add-controller-guidelines/docs/writing-controllers.md#define-the-statechange-event-using-the-controllerstatechangeevent-utility-type) - [Define and export a type union for internal action types](https://github.com/MetaMask/core/blob/add-controller-guidelines/docs/writing-controllers.md#define-and-export-a-type-union-for-internal-action-types) - [Define and export a type union for internal event types](https://github.com/MetaMask/core/blob/add-controller-guidelines/docs/writing-controllers.md#define-and-export-a-type-union-for-internal-event-types) - [Define and export a type for the controller's messenger](https://github.com/MetaMask/core/blob/add-controller-guidelines/docs/writing-controllers.md#define-and-export-a-type-for-the-controllers-messenger) This also resolves downstream errors in mobile caused by `composable-controller` expecting all of its child controllers to have a `stateChange` event. - See MetaMask/metamask-mobile#10374 ## References - Fixes #4579 - Blocks MetaMask/metamask-mobile#10441 ## Changelog ### `@metamask/logging-controller` (major) ```md ### Added - Define and export new types: `LoggingControllerGetStateAction`, `LoggingControllerStateChangeEvent`, `LoggingControllerEvents` ([#4633](#4633)) ### Changed - **BREAKING:** `LoggingControllerMessenger` must allow internal events defined in the `LoggingControllerEvents` type ([#4633](#4633)) - `LoggingControllerActions` is widened to include the `LoggingController:getState` action ([#4633](#4633)) ``` ### `@metamask/phishing-controller` (major) ```md ### Added - Define and export new types: `PhishingControllerGetStateAction`, `PhishingControllerStateChangeEvent`, `PhishingControllerEvents` ([#4633](#4633)) ### Changed - **BREAKING:** `PhishingControllerMessenger` must allow internal events defined in the `PhishingControllerEvents` type ([#4633](#4633)) - `PhishingControllerActions` is widened to include the `PhishingController:getState` action ([#4633](#4633)) ``` ### `@metamask/notification-services-controller` (minor) ```md ### Added - Define and export new type `NotificationServicesControllerGetStateAction` ([#4633](#4633)) ### Fixed - Replace `getState` action in `NotificationServicesControllerActions` with correctly-defined `NotificationServicesControllerGetStateAction` type ([#4633](#4633)) ``` ### `@metamask/authentication-controller` (major) ```md ### Added - Define and export new types: `AuthenticationControllerGetStateAction`, `AuthenticationControllerStateChangeEvent`, `Events` ([#4633](#4633)) ### Changed - **BREAKING:** `AuthenticationControllerMessenger` must allow internal events defined in the `Events` type ([#4633](#4633)) - `AuthenticationControllerActions` is widened to include the `AuthenticationController:getState` action ([#4633](#4633)) ``` ### `@metamask/user-storage-controller` (major) ```md ### Added - Define and export new types: `UserStorageControllerGetStateAction`, `UserStorageControllerStateChangeEvent`, `Events` ([#4633](#4633)) ### Changed - **BREAKING:** `UserStorageControllerMessenger` must allow internal events defined in the `Events` type ([#4633](#4633)) - `UserStorageControllerActions` is widened to include the `UserStorageController:getState` action ([#4633](#4633)) ``` ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate
This PR has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 7 days. Thank you for your contributions. |
This PR was closed because there has been no follow up activity in 7 days. Thank you for your contributions. |
Description
This PR is not intended to be merged into main, but to serve as a preview for a complete implementation of
@metamask/composable-controller@8.0.0
that doesn't rely on type error suppression.Some commits may be cherry-picked into a new PR -- especially the controller patches (the wallet framework team will be applying the same changes to the core controllers).
To access newer
yarn resolutions
features andyarn patch
,git
protocol syntax), the package.jsonpackageManager
field is set to yarn v3.This change is the cause of the CI failure during the "setup" step, and will be reverted in any PR that follows.
Fixes
All
ts-expect-error
,ts-ignore
directives are removed by fixing the following errors:@metamask/base-controller
version mismatch errors in controller instantiations@metamask/base-controller
version to6.0.2
(latest) with yarn resolutions.@metamask/base-controller
version, (e.g.@metamask/approval-controller
is bumped to its latest version).@metamask/ppom-validator
is updated to use@metamask/base-controller@6.0.2
)."
stateChange
event is not assignable..."This error is caused by one of the following:
messagingSystem
is defined as a private field.messagingSystem
class field ofBaseControllerV2
was defined as a private field in@metamask/controllers@6.1.1
(#377) and has been set toprotected
since@metamask/controllers@8.0.0
(#378) (these versions are from 3 years ago before the core monorepo existed).@metamask/base-controller
.stateChange
event type for the controller is not defined and/or the controller's messenger is defined without itsstateChange
event type (and there are no newer releases where these issues have been fixed)stateChange
event type using theControllerStateChangeEvent
generic type from@metamask/base-controller
.ExampleControllerEvents
type union.Events
field of the controller's messenger type.Global{Actions,Events}
type unions in theEngine
class.Related issues
ComposableController
instantiation and functionality is broken #10073@metamask/composable-controller
from^3.0.0
to^6.0.2
#10011Manual testing steps
Screenshots/Recordings
Pre-merge author checklist
Pre-merge reviewer checklist