-
-
Notifications
You must be signed in to change notification settings - Fork 275
feat!: Expose Accounts-owned controller/service methods through messenger #7976
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
base: main
Are you sure you want to change the base?
Changes from all commits
271e0cd
2635b01
0cc9967
e7322e2
c78f96b
000c741
926052c
2c604d4
a79fc19
5418e3b
d6e1fe9
efec6bf
47cdaed
58fc302
7e9d46b
47419ab
0ff1bd8
e91e209
a84ed9e
9653421
80fba50
6867941
7ec9ffb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||||||||||||
|
|
||||||||||||||
| ### 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. | ||||||||||||||
| - Update `UserStorageController` and `AuthenticationController` actions to their new names ([#7976](https://github.com/MetaMask/core/pull/7976)) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||||||||||
| - Bump `@metamask/accounts-controller` from `^36.0.0` to `^36.0.1` ([#7996](https://github.com/MetaMask/core/pull/7996)) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we mention that we effectively removed
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| ## [4.1.1] | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| /** | ||
| * This file is auto generated by `scripts/generate-method-action-types.ts`. | ||
| * Do not edit manually. | ||
| */ | ||
|
|
||
| import type { AccountTreeController } from './AccountTreeController'; | ||
|
|
||
| /** | ||
| * Gets the account wallet object from its ID. | ||
| * | ||
| * @param walletId - Account wallet ID. | ||
| * @returns The account wallet object if found, undefined otherwise. | ||
| */ | ||
| export type AccountTreeControllerGetAccountWalletObjectAction = { | ||
| type: `AccountTreeController:getAccountWalletObject`; | ||
| handler: AccountTreeController['getAccountWalletObject']; | ||
| }; | ||
|
|
||
| /** | ||
| * Gets all account wallet objects. | ||
| * | ||
| * @returns All account wallet objects. | ||
| */ | ||
| export type AccountTreeControllerGetAccountWalletObjectsAction = { | ||
| type: `AccountTreeController:getAccountWalletObjects`; | ||
| handler: AccountTreeController['getAccountWalletObjects']; | ||
| }; | ||
|
|
||
| /** | ||
| * Gets all underlying accounts from the currently selected account | ||
| * group. | ||
| * | ||
| * It also support account selector, which allows to filter specific | ||
| * accounts given some criterias (account type, address, scopes, etc...). | ||
| * | ||
| * @param selector - Optional account selector. | ||
| * @returns Underlying accounts for the currently selected account (filtered | ||
| * by the selector if provided). | ||
| */ | ||
| export type AccountTreeControllerGetAccountsFromSelectedAccountGroupAction = { | ||
| type: `AccountTreeController:getAccountsFromSelectedAccountGroup`; | ||
| handler: AccountTreeController['getAccountsFromSelectedAccountGroup']; | ||
| }; | ||
|
|
||
| /** | ||
| * Gets the account group object from its ID. | ||
| * | ||
| * @param groupId - Account group ID. | ||
| * @returns The account group object if found, undefined otherwise. | ||
| */ | ||
| export type AccountTreeControllerGetAccountGroupObjectAction = { | ||
| type: `AccountTreeController:getAccountGroupObject`; | ||
| handler: AccountTreeController['getAccountGroupObject']; | ||
| }; | ||
|
|
||
| /** | ||
| * Gets the account's context which contains its wallet ID, group ID, and sort order. | ||
| * | ||
| * @param accountId - Account ID. | ||
| * @returns The account context if found, undefined otherwise. | ||
| */ | ||
| export type AccountTreeControllerGetAccountContextAction = { | ||
| type: `AccountTreeController:getAccountContext`; | ||
| handler: AccountTreeController['getAccountContext']; | ||
| }; | ||
|
|
||
| /** | ||
| * Gets the currently selected account group ID. | ||
| * | ||
| * @returns The selected account group ID or empty string if none selected. | ||
| */ | ||
| export type AccountTreeControllerGetSelectedAccountGroupAction = { | ||
| type: `AccountTreeController:getSelectedAccountGroup`; | ||
| handler: AccountTreeController['getSelectedAccountGroup']; | ||
| }; | ||
|
|
||
| /** | ||
| * Sets the selected account group and updates the AccountsController selectedAccount accordingly. | ||
| * | ||
| * @param groupId - The account group ID to select. | ||
| */ | ||
| export type AccountTreeControllerSetSelectedAccountGroupAction = { | ||
| type: `AccountTreeController:setSelectedAccountGroup`; | ||
| handler: AccountTreeController['setSelectedAccountGroup']; | ||
| }; | ||
|
|
||
| /** | ||
| * Sets a custom name for an account group. | ||
| * | ||
| * @param groupId - The account group ID. | ||
| * @param name - The custom name to set. | ||
| * @param autoHandleConflict - If true, automatically resolves name conflicts by adding a suffix. If false, throws on conflicts. | ||
| * @throws If the account group ID is not found in the current tree. | ||
| * @throws If the account group name already exists and autoHandleConflict is false. | ||
| */ | ||
| export type AccountTreeControllerSetAccountGroupNameAction = { | ||
| type: `AccountTreeController:setAccountGroupName`; | ||
| handler: AccountTreeController['setAccountGroupName']; | ||
| }; | ||
|
|
||
| /** | ||
| * Sets a custom name for an account wallet. | ||
| * | ||
| * @param walletId - The account wallet ID. | ||
| * @param name - The custom name to set. | ||
| * @throws If the account wallet ID is not found in the current tree. | ||
| */ | ||
| export type AccountTreeControllerSetAccountWalletNameAction = { | ||
| type: `AccountTreeController:setAccountWalletName`; | ||
| handler: AccountTreeController['setAccountWalletName']; | ||
| }; | ||
|
|
||
| /** | ||
| * Toggles the pinned state of an account group. | ||
| * | ||
| * @param groupId - The account group ID. | ||
| * @param pinned - Whether the group should be pinned. | ||
| * @throws If the account group ID is not found in the current tree. | ||
| */ | ||
| export type AccountTreeControllerSetAccountGroupPinnedAction = { | ||
| type: `AccountTreeController:setAccountGroupPinned`; | ||
| handler: AccountTreeController['setAccountGroupPinned']; | ||
| }; | ||
|
|
||
| /** | ||
| * Toggles the hidden state of an account group. | ||
| * | ||
| * @param groupId - The account group ID. | ||
| * @param hidden - Whether the group should be hidden. | ||
| * @throws If the account group ID is not found in the current tree. | ||
| */ | ||
| export type AccountTreeControllerSetAccountGroupHiddenAction = { | ||
| type: `AccountTreeController:setAccountGroupHidden`; | ||
| handler: AccountTreeController['setAccountGroupHidden']; | ||
| }; | ||
|
|
||
| /** | ||
| * Clears the controller state and resets to default values. | ||
| * Also clears the backup and sync service state. | ||
| */ | ||
| export type AccountTreeControllerClearStateAction = { | ||
| type: `AccountTreeController:clearState`; | ||
| handler: AccountTreeController['clearState']; | ||
| }; | ||
|
|
||
| /** | ||
| * Bi-directionally syncs the account tree with user storage. | ||
| * This will perform a full sync, including both pulling updates | ||
| * from user storage and pushing local changes to user storage. | ||
| * This also performs legacy account syncing if needed. | ||
| * | ||
| * IMPORTANT: | ||
| * If a full sync is already in progress, it will return the ongoing promise. | ||
| * | ||
| * @returns A promise that resolves when the sync is complete. | ||
| */ | ||
| export type AccountTreeControllerSyncWithUserStorageAction = { | ||
| type: `AccountTreeController:syncWithUserStorage`; | ||
| handler: AccountTreeController['syncWithUserStorage']; | ||
| }; | ||
|
|
||
| /** | ||
| * Bi-directionally syncs the account tree with user storage. | ||
| * This will ensure at least one full sync is ran, including both pulling updates | ||
| * from user storage and pushing local changes to user storage. | ||
| * This also performs legacy account syncing if needed. | ||
| * | ||
| * IMPORTANT: | ||
| * If the first ever full sync is already in progress, it will return the ongoing promise. | ||
| * If the first ever full sync was previously completed, it will NOT start a new sync, and will resolve immediately. | ||
| * | ||
| * @returns A promise that resolves when the first ever full sync is complete. | ||
| */ | ||
| export type AccountTreeControllerSyncWithUserStorageAtLeastOnceAction = { | ||
| type: `AccountTreeController:syncWithUserStorageAtLeastOnce`; | ||
| handler: AccountTreeController['syncWithUserStorageAtLeastOnce']; | ||
| }; | ||
|
|
||
| /** | ||
| * Union of all AccountTreeController action types. | ||
| */ | ||
| export type AccountTreeControllerMethodActions = | ||
| | AccountTreeControllerGetAccountWalletObjectAction | ||
| | AccountTreeControllerGetAccountWalletObjectsAction | ||
| | AccountTreeControllerGetAccountsFromSelectedAccountGroupAction | ||
| | AccountTreeControllerGetAccountGroupObjectAction | ||
| | AccountTreeControllerGetAccountContextAction | ||
| | AccountTreeControllerGetSelectedAccountGroupAction | ||
| | AccountTreeControllerSetSelectedAccountGroupAction | ||
| | AccountTreeControllerSetAccountGroupNameAction | ||
| | AccountTreeControllerSetAccountWalletNameAction | ||
| | AccountTreeControllerSetAccountGroupPinnedAction | ||
| | AccountTreeControllerSetAccountGroupHiddenAction | ||
| | AccountTreeControllerClearStateAction | ||
| | AccountTreeControllerSyncWithUserStorageAction | ||
| | AccountTreeControllerSyncWithUserStorageAtLeastOnceAction; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4575,21 +4575,18 @@ describe('AccountTreeController', () => { | |
| }); | ||
|
|
||
| // Test suffix resolution directly using the public method | ||
| const wallet = controller.state.accountTree.wallets[walletId]; | ||
| const resolvedName = controller.resolveNameConflict( | ||
| wallet, | ||
| groupId, | ||
| 'Suffix Test', | ||
| ); | ||
| expect(resolvedName).toBe('Suffix Test (3)'); | ||
| 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'); | ||
|
Comment on lines
+4578
to
+4589
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can confirm this is not used in either extension and mobile.
Comment on lines
+4578
to
+4589
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| }); | ||
|
|
||
| it('throws error when group ID not found in tree', () => { | ||
|
|
||
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.
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?