feat!: Expose Accounts-owned controller/service methods through messenger#7976
feat!: Expose Accounts-owned controller/service methods through messenger#7976GuillaumeRx wants to merge 23 commits intomainfrom
Conversation
7de355d to
0e42ff2
Compare
| controller.setAccountGroupName(groupId, 'Suffix Test', true); | ||
|
|
||
| // Test with no conflicts: should return "Unique Name (2)" | ||
| const uniqueName = controller.resolveNameConflict( | ||
| wallet, | ||
| groupId, | ||
| 'Unique Name', | ||
| ); | ||
| expect(uniqueName).toBe('Unique Name (2)'); | ||
| const collidingGroupObject = controller.getAccountGroupObject(groupId); | ||
|
|
||
| expect(collidingGroupObject?.metadata.name).toBe('Suffix Test (3)'); | ||
|
|
||
| // Test with no conflicts: should return "Unique Name" | ||
| controller.setAccountGroupName(groupId, 'Unique Name', true); | ||
|
|
||
| const uniqueGroupObject = controller.getAccountGroupObject(groupId); | ||
|
|
||
| expect(uniqueGroupObject?.metadata.name).toBe('Unique Name'); |
There was a problem hiding this comment.
resolveNameConflict is only internally used. It doesn't make sense to have it publicly only to test its behavior in unit tests. We can do that via the public methods that uses it
There was a problem hiding this comment.
I can confirm this is not used in either extension and mobile.
| controller.setAccountGroupName(groupId, 'Suffix Test', true); | ||
|
|
||
| // Test with no conflicts: should return "Unique Name (2)" | ||
| const uniqueName = controller.resolveNameConflict( | ||
| wallet, | ||
| groupId, | ||
| 'Unique Name', | ||
| ); | ||
| expect(uniqueName).toBe('Unique Name (2)'); | ||
| const collidingGroupObject = controller.getAccountGroupObject(groupId); | ||
|
|
||
| expect(collidingGroupObject?.metadata.name).toBe('Suffix Test (3)'); | ||
|
|
||
| // Test with no conflicts: should return "Unique Name" | ||
| controller.setAccountGroupName(groupId, 'Unique Name', true); | ||
|
|
||
| const uniqueGroupObject = controller.getAccountGroupObject(groupId); | ||
|
|
||
| expect(uniqueGroupObject?.metadata.name).toBe('Unique Name'); |
There was a problem hiding this comment.
This assertion was very misleading by the way. If there's no conflict the method shouldn't be called therefore no suffix should be added.
| * @throws An error if the account ID is not found. | ||
| */ | ||
| getAccountExpect(accountId: string): InternalAccount { | ||
| #getAccountExpect(accountId: string): InternalAccount { |
There was a problem hiding this comment.
We don't need this method to be public, it's only used internally.
packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.ts
Outdated
Show resolved
Hide resolved
packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.ts
Outdated
Show resolved
Hide resolved
packages/profile-sync-controller/src/controllers/authentication/AuthenticationController.ts
Outdated
Show resolved
Hide resolved
packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.ts
Outdated
Show resolved
Hide resolved
0e42ff2 to
6ea2c28
Compare
There was a problem hiding this comment.
I don't know what's going on here with the imports, I just made sure that the original export behavior was respected.
There was a problem hiding this comment.
This certainly seems cleaner :)
There was a problem hiding this comment.
I don't know what's going on here with the imports, I just made sure that the original export behavior was respected.
be1d092 to
405c239
Compare
| const { messenger, mocks } = await setup({ | ||
| accounts: [MOCK_HD_ACCOUNT_1], | ||
| }); | ||
|
|
||
| const resyncAccountsSpy = jest.spyOn(service, 'resyncAccounts'); | ||
| await messenger.call('MultichainAccountService:resyncAccounts'); | ||
| expect(resyncAccountsSpy).toHaveBeenCalled(); | ||
|
|
||
| expect(mocks.EvmAccountProvider.resyncAccounts).toHaveBeenCalled(); | ||
| expect(mocks.SolAccountProvider.resyncAccounts).toHaveBeenCalled(); |
There was a problem hiding this comment.
we can't spy resyncAccounts at this step since registeMethodActionHandlers will register the original method not the spied one
| const ensureCanUseSnapPlatformSpy = jest.spyOn( | ||
| service, | ||
| 'ensureCanUseSnapPlatform', | ||
| await rootMessenger.call( | ||
| 'MultichainAccountService:ensureCanUseSnapPlatform', | ||
| ); | ||
| await messenger.call('MultichainAccountService:ensureCanUseSnapPlatform'); | ||
| expect(ensureCanUseSnapPlatformSpy).toHaveBeenCalled(); |
There was a problem hiding this comment.
we can't spy ensureCanUseSnapPlatform at this step since registeMethodActionHandlers will register the original method not the spied one
…StorageController`
31e2baa to
6867941
Compare
packages/multichain-account-service/src/MultichainAccountService.test.ts
Show resolved
Hide resolved
mcmire
left a comment
There was a problem hiding this comment.
Nice! The code changes themselves look good, but I had some suggestions on changelogs. (You may need to add the no-changelog label to this PR to suppress the changelog checker.)
| controller.setAccountGroupName(groupId, 'Suffix Test', true); | ||
|
|
||
| // Test with no conflicts: should return "Unique Name (2)" | ||
| const uniqueName = controller.resolveNameConflict( | ||
| wallet, | ||
| groupId, | ||
| 'Unique Name', | ||
| ); | ||
| expect(uniqueName).toBe('Unique Name (2)'); | ||
| const collidingGroupObject = controller.getAccountGroupObject(groupId); | ||
|
|
||
| expect(collidingGroupObject?.metadata.name).toBe('Suffix Test (3)'); | ||
|
|
||
| // Test with no conflicts: should return "Unique Name" | ||
| controller.setAccountGroupName(groupId, 'Unique Name', true); | ||
|
|
||
| const uniqueGroupObject = controller.getAccountGroupObject(groupId); | ||
|
|
||
| expect(uniqueGroupObject?.metadata.name).toBe('Unique Name'); |
There was a problem hiding this comment.
I can confirm this is not used in either extension and mobile.
| - The controller's methods are now exposed to the messenger through `registerMethodActionHandlers` and `MESSENGER_EXPOSED_METHODS`. | ||
| - The action types are now generated using `generate-method-action-types`. | ||
| - Exposes the missing public methods in the messenger. | ||
| - Update `UserStorageController` and `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) |
There was a problem hiding this comment.
Are these public-facing changes? It looks like we are using new names for the types in the union, but neither the names of the action type strings nor the signatures of the action handlers themselves have changed. So consumers should not need to adjust how they construct the AccountTreeController messenger. Is this true?
| - Update `UserStorageController` and `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) |
| * @throws An error if the account ID is not found. | ||
| */ | ||
| getAccountExpect(accountId: string): InternalAccount { | ||
| #getAccountExpect(accountId: string): InternalAccount { |
| - The action types are now generated using `generate-method-action-types`. | ||
| - Exposes the missing public methods in the messenger. | ||
| - Update `UserStorageController` and `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) | ||
| - Bump `@metamask/accounts-controller` from `^36.0.0` to `^36.0.1` ([#7996](https://github.com/MetaMask/core/pull/7996)) |
There was a problem hiding this comment.
Should we mention that we effectively removed resolveNameConflict?
| - Bump `@metamask/accounts-controller` from `^36.0.0` to `^36.0.1` ([#7996](https://github.com/MetaMask/core/pull/7996)) | |
| ### Removed | |
| - **BREAKING:** Remove `resolveNameConflict` from `AccountTreeController` ([#7976](https://github.com/MetaMask/core/pull/7976)) | |
| - This method was only used internally. |
| ### Changed | ||
|
|
||
| - Refactor the controller's messenger action registration ([#7976](https://github.com/MetaMask/core/pull/7976/)) | ||
| - The controller's methods are now exposed to the messenger through `registerMethodActionHandlers` and `MESSENGER_EXPOSED_METHODS`. | ||
| - The action types are now generated using `generate-method-action-types`. | ||
| - Exposes the missing public methods in the messenger. |
There was a problem hiding this comment.
We've been keeping changelog entries focused on public changes to the API only.
Curious if instead of highlighting that we refactored the messenger action registration, we should instead call out which methods are now available through the messenger? Also should this be in "Added" since we are adding new things that consumers can use?
| ### Changed | |
| - Refactor the controller's messenger action registration ([#7976](https://github.com/MetaMask/core/pull/7976/)) | |
| - The controller's methods are now exposed to the messenger through `registerMethodActionHandlers` and `MESSENGER_EXPOSED_METHODS`. | |
| - The action types are now generated using `generate-method-action-types`. | |
| - Exposes the missing public methods in the messenger. | |
| ### Added | |
| - Expose missing public `AccountTreeController` methods through its messenger ([#7976](https://github.com/MetaMask/core/pull/7976/)) | |
| - The following actions are now available: | |
| - `AccountTreeController:getAccountWalletObject` | |
| - `AccountTreeController:getAccountWalletObjects` | |
| - `AccountTreeController:getAccountGroupObject` | |
| - `AccountTreeController:clearState` | |
| - `AccountTreeController:syncWithUserStorage` | |
| - `AccountTreeController:syncWithUserStorageAtLeastOnce` | |
| - Corresponding action types (e.g. `AccountTreeControllerGetAccountWalletObjectAction`) are available as well. |
|
|
||
| ### Changed | ||
|
|
||
| - Refactor the controller's messenger action registration ([#7976](https://github.com/MetaMask/core/pull/7976/)) |
There was a problem hiding this comment.
(Similar as for the changelogs above)
| - Debounce `KeyringController:stateChange` handler to reduce redundant notification subscription calls during rapid account syncing ([#7980](https://github.com/MetaMask/core/pull/7980)) | ||
| - Filter out Product Account announcements notifications older than 3 months ([#7884](https://github.com/MetaMask/core/pull/7884)) | ||
| - Bump `@metamask/controller-utils` from `^11.18.0` to `^11.19.0` ([#7995](https://github.com/MetaMask/core/pull/7995)) | ||
| - Update `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) |
There was a problem hiding this comment.
| - Update `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) |
|
|
||
| ### Changed | ||
|
|
||
| - Update `AuthenticationController` action to its new name ([#7976](https://github.com/MetaMask/core/pull/7976)) |
There was a problem hiding this comment.
| - Update `AuthenticationController` action to its new name ([#7976](https://github.com/MetaMask/core/pull/7976)) |
| - **BREAKING:** Refactor the controller's messenger action registration ([#7976](https://github.com/MetaMask/core/pull/7976/)) | ||
| - The controller's methods are now exposed to the messenger through `registerMethodActionHandlers` and `MESSENGER_EXPOSED_METHODS`. | ||
| - The action types are now generated using `generate-method-action-types`. | ||
| - Exposes the missing public methods in the messenger. |
There was a problem hiding this comment.
This is a bit different from other changelogs since we have some breaking changes. Currently it's not clear what exactly is breaking. Should we highlight that better specifically? Maybe something like:
| - Exposes the missing public methods in the messenger. | |
| ### Added | |
| - Expose missing public `UserStorageController` methods through its messenger ([#7976](https://github.com/MetaMask/core/pull/7976/)) | |
| - The following actions are now available: | |
| - `UserStorageController:performDeleteStorageAllFeatureEntries` | |
| - `UserStorageController:listEntropySources` | |
| - `UserStorageController:setIsBackupAndSyncFeatureEnabled` | |
| - `UserStorageController:setIsContactSyncingInProgress` | |
| - `UserStorageController:syncContactsWithUserStorage` | |
| - Corresponding action types (e.g. `UserStorageControllerPerformDeleteStorageAllFeatureEntriesAction`) are available as well. | |
| ### Changed | |
| - **BREAKING:** Standardize names of `AuthenticationController` and `UserStorageController` messenger action types ([#7976](https://github.com/MetaMask/core/pull/7976/)) | |
| - All existing types for messenger actions have been renamed so they end in `Action` (e.g. `AuthenticationControllerPerformSignIn` -> `AuthenticationControllerPerformSignInAction`). You will need to update imports appropriately. | |
| - This change only affects the types. The action type strings themselves have not changed, so you do not need to update the list of actions you pass when initializing `AuthenticationController` and `UserStorageController` messengers. |
| - Bump `@metamask/transaction-controller` from `^62.16.0` to `^62.18.0` ([#7897](https://github.com/MetaMask/core/pull/7897), [#7996](https://github.com/MetaMask/core/pull/7996), [#8005](https://github.com/MetaMask/core/pull/8005)) | ||
| - Bump `@metamask/polling-controller` from `^16.0.2` to `^16.0.3` ([#7996](https://github.com/MetaMask/core/pull/7996)) | ||
| - Bump `@metamask/controller-utils` from `^11.18.0` to `^11.19.0` ([#7995](https://github.com/MetaMask/core/pull/7995)) | ||
| - Update `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) |
There was a problem hiding this comment.
| - Update `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) |
Explanation
Exposes all the public methods other than
initor any internally used methods of the accounts-owned controllers/services throught the messenger.This also refactors how actions are defined and bound to the messenger using
registerMethodActionHandlersandMESSENGER_EXPOSED_METHODS.The
generate-method-action-typescript was used to generate the action types.This is a breaking change in the
profile-sync-controllerpackage as some of the action type names changed but none of the underlying signatures changed.References
Checklist
Note
Medium Risk
Wide cross-package refactor of messenger action registration and exported action type names; risk is mainly integration breakage for consumers relying on old action types or missing exposed methods, rather than new business logic.
Overview
Refactors
AccountsController,AccountTreeController,MultichainAccountService, andprofile-sync-controller(AuthenticationController,UserStorageController) to expose public APIs through the messenger viaregisterMethodActionHandlersand per-moduleMESSENGER_EXPOSED_METHODS, replacing manualregisterActionHandlerwiring.Introduces auto-generated
*-method-action-types.tsfiles (and newgenerate-method-action-typesscripts usingtsx) and updates package exports/types and cross-packageAllowedActionsreferences to the new...Actiontype names (notably a breaking rename inprofile-sync-controller). Tests were adjusted for the new action names and a couple of behaviors (e.g., selected-account missing ID now throws; account-group name conflict resolution is exercised via public setters).Written by Cursor Bugbot for commit 7ec9ffb. This will update automatically on new commits. Configure here.