From 8f787d185e9f2197f3755c07f36101bcc07fa8fb Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 11 Mar 2026 16:53:03 +0100 Subject: [PATCH 01/10] chore!: Expose confirmations-owned controller/service methods through messenger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate 10 confirmations-team controllers to the MESSENGER_EXPOSED_METHODS + registerMethodActionHandlers pattern with auto-generated action types. BREAKING CHANGE: ApprovalController methods renamed: clear→clearRequests, has→hasRequest, accept→acceptRequest, reject→rejectRequest, success→showSuccess, error→showError. TransactionController action types standardized with Action suffix. --- eslint-suppressions.json | 5 +- packages/address-book-controller/CHANGELOG.md | 4 + packages/address-book-controller/package.json | 2 + ...dressBookController-method-action-types.ts | 60 +++ .../src/AddressBookController.ts | 55 +-- packages/address-book-controller/src/index.ts | 10 +- packages/approval-controller/CHANGELOG.md | 6 + packages/approval-controller/package.json | 2 + .../ApprovalController-method-action-types.ts | 273 +++++++++++++ .../src/ApprovalController.test.ts | 278 +++++++------ .../src/ApprovalController.ts | 199 +++------ packages/approval-controller/src/index.ts | 18 + .../src/NftController.test.ts | 6 +- .../assets-controllers/src/NftController.ts | 2 +- .../src/NftDetectionController.ts | 2 +- .../src/TokensController.test.ts | 4 +- .../src/TokensController.ts | 2 +- packages/ens-controller/CHANGELOG.md | 4 + packages/ens-controller/package.json | 2 + .../src/EnsController-method-action-types.ts | 83 ++++ packages/ens-controller/src/EnsController.ts | 22 +- packages/ens-controller/src/index.ts | 8 + packages/gas-fee-controller/CHANGELOG.md | 4 + packages/gas-fee-controller/package.json | 2 + .../GasFeeController-method-action-types.ts | 80 ++++ .../src/GasFeeController.ts | 47 ++- packages/gas-fee-controller/src/index.ts | 8 + packages/logging-controller/CHANGELOG.md | 5 + packages/logging-controller/package.json | 2 + .../LoggingController-method-action-types.ts | 31 ++ .../src/LoggingController.ts | 18 +- packages/logging-controller/src/index.ts | 4 + packages/name-controller/CHANGELOG.md | 4 + packages/name-controller/package.json | 2 + .../src/NameController-method-action-types.ts | 43 ++ .../src/NameController.test.ts | 1 + .../name-controller/src/NameController.ts | 10 +- packages/name-controller/src/index.ts | 4 + .../src/PermissionController.ts | 12 +- packages/signature-controller/CHANGELOG.md | 4 + packages/signature-controller/package.json | 2 + ...SignatureController-method-action-types.ts | 132 ++++++ .../src/SignatureController.test.ts | 1 + .../src/SignatureController.ts | 30 +- packages/signature-controller/src/index.ts | 12 + packages/transaction-controller/CHANGELOG.md | 3 + packages/transaction-controller/package.json | 2 + ...ansactionController-method-action-types.ts | 384 ++++++++++++++++++ .../src/TransactionController.test.ts | 2 +- .../src/TransactionController.ts | 245 ++++------- .../TransactionControllerIntegration.test.ts | 24 +- packages/transaction-controller/src/index.ts | 42 +- .../transaction-pay-controller/CHANGELOG.md | 1 + .../transaction-pay-controller/package.json | 2 + ...actionPayController-method-action-types.ts | 92 +++++ .../src/TransactionPayController.ts | 102 +++-- .../transaction-pay-controller/src/index.ts | 12 +- .../src/tests/messenger-mock.ts | 2 +- .../transaction-pay-controller/src/types.ts | 36 +- .../user-operation-controller/CHANGELOG.md | 4 + .../user-operation-controller/package.json | 2 + ...OperationController-method-action-types.ts | 64 +++ .../src/UserOperationController.test.ts | 1 + .../src/UserOperationController.ts | 21 +- .../user-operation-controller/src/index.ts | 5 + yarn.lock | 10 + 66 files changed, 1947 insertions(+), 614 deletions(-) create mode 100644 packages/address-book-controller/src/AddressBookController-method-action-types.ts create mode 100644 packages/approval-controller/src/ApprovalController-method-action-types.ts create mode 100644 packages/ens-controller/src/EnsController-method-action-types.ts create mode 100644 packages/gas-fee-controller/src/GasFeeController-method-action-types.ts create mode 100644 packages/logging-controller/src/LoggingController-method-action-types.ts create mode 100644 packages/name-controller/src/NameController-method-action-types.ts create mode 100644 packages/signature-controller/src/SignatureController-method-action-types.ts create mode 100644 packages/transaction-controller/src/TransactionController-method-action-types.ts create mode 100644 packages/transaction-pay-controller/src/TransactionPayController-method-action-types.ts create mode 100644 packages/user-operation-controller/src/UserOperationController-method-action-types.ts diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 6b6929e2d1d..49dc00630a1 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -115,7 +115,7 @@ }, "packages/address-book-controller/src/AddressBookController.ts": { "@typescript-eslint/explicit-function-return-type": { - "count": 4 + "count": 3 }, "@typescript-eslint/naming-convention": { "count": 3 @@ -138,9 +138,6 @@ }, "@typescript-eslint/prefer-nullish-coalescing": { "count": 6 - }, - "no-restricted-syntax": { - "count": 1 } }, "packages/assets-controllers/jest.environment.js": { diff --git a/packages/address-book-controller/CHANGELOG.md b/packages/address-book-controller/CHANGELOG.md index d63149d6172..272493229cf 100644 --- a/packages/address-book-controller/CHANGELOG.md +++ b/packages/address-book-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New messenger action: `AddressBookControllerClearAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + ### Changed - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) diff --git a/packages/address-book-controller/package.json b/packages/address-book-controller/package.json index 682e01fa56d..2f722cb3c10 100644 --- a/packages/address-book-controller/package.json +++ b/packages/address-book-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/address-book-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/address-book-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", @@ -59,6 +60,7 @@ "deepmerge": "^4.2.2", "jest": "^29.7.0", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/address-book-controller/src/AddressBookController-method-action-types.ts b/packages/address-book-controller/src/AddressBookController-method-action-types.ts new file mode 100644 index 00000000000..6074a35dd07 --- /dev/null +++ b/packages/address-book-controller/src/AddressBookController-method-action-types.ts @@ -0,0 +1,60 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { AddressBookController } from './AddressBookController'; + +/** + * Returns all address book entries as an array. + * + * @returns Array of all address book entries. + */ +export type AddressBookControllerListAction = { + type: `AddressBookController:list`; + handler: AddressBookController['list']; +}; + +/** + * Remove all contract entries. + */ +export type AddressBookControllerClearAction = { + type: `AddressBookController:clear`; + handler: AddressBookController['clear']; +}; + +/** + * Remove a contract entry by address. + * + * @param chainId - Chain id identifies the current chain. + * @param address - Recipient address to delete. + * @returns Whether the entry was deleted. + */ +export type AddressBookControllerDeleteAction = { + type: `AddressBookController:delete`; + handler: AddressBookController['delete']; +}; + +/** + * Add or update a contact entry by address. + * + * @param address - Recipient address to add or update. + * @param name - Nickname to associate with this address. + * @param chainId - Chain id identifies the current chain. + * @param memo - User's note about address. + * @param addressType - Contact's address type. + * @returns Boolean indicating if the address was successfully set. + */ +export type AddressBookControllerSetAction = { + type: `AddressBookController:set`; + handler: AddressBookController['set']; +}; + +/** + * Union of all AddressBookController action types. + */ +export type AddressBookControllerMethodActions = + | AddressBookControllerListAction + | AddressBookControllerClearAction + | AddressBookControllerDeleteAction + | AddressBookControllerSetAction; diff --git a/packages/address-book-controller/src/AddressBookController.ts b/packages/address-book-controller/src/AddressBookController.ts index 38793f866dd..62ad4e66824 100644 --- a/packages/address-book-controller/src/AddressBookController.ts +++ b/packages/address-book-controller/src/AddressBookController.ts @@ -13,6 +13,8 @@ import { import type { Messenger } from '@metamask/messenger'; import type { Hex } from '@metamask/utils'; +import type { AddressBookControllerMethodActions } from './AddressBookController-method-action-types'; + /** * ContactEntry representation */ @@ -73,6 +75,8 @@ export const controllerName = 'AddressBookController'; */ const WALLET_ACCOUNTS_CHAIN_ID = '*'; +const MESSENGER_EXPOSED_METHODS = ['list', 'set', 'delete', 'clear'] as const; + /** * The action that can be performed to get the state of the {@link AddressBookController}. */ @@ -81,30 +85,6 @@ export type AddressBookControllerGetStateAction = ControllerGetStateAction< AddressBookControllerState >; -/** - * The action that can be performed to list contacts from the {@link AddressBookController}. - */ -export type AddressBookControllerListAction = { - type: `${typeof controllerName}:list`; - handler: AddressBookController['list']; -}; - -/** - * The action that can be performed to set a contact in the {@link AddressBookController}. - */ -export type AddressBookControllerSetAction = { - type: `${typeof controllerName}:set`; - handler: AddressBookController['set']; -}; - -/** - * The action that can be performed to delete a contact from the {@link AddressBookController}. - */ -export type AddressBookControllerDeleteAction = { - type: `${typeof controllerName}:delete`; - handler: AddressBookController['delete']; -}; - /** * Event emitted when a contact is added or updated */ @@ -126,9 +106,7 @@ export type AddressBookControllerContactDeletedEvent = { */ export type AddressBookControllerActions = | AddressBookControllerGetStateAction - | AddressBookControllerListAction - | AddressBookControllerSetAction - | AddressBookControllerDeleteAction; + | AddressBookControllerMethodActions; /** * The event that {@link AddressBookController} can emit. @@ -206,7 +184,10 @@ export class AddressBookController extends BaseController< state: mergedState, }); - this.#registerMessageHandlers(); + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, + ); } /** @@ -337,24 +318,6 @@ export class AddressBookController extends BaseController< return true; } - - /** - * Registers message handlers for the AddressBookController. - */ - #registerMessageHandlers() { - this.messenger.registerActionHandler( - `${controllerName}:list`, - this.list.bind(this), - ); - this.messenger.registerActionHandler( - `${controllerName}:set`, - this.set.bind(this), - ); - this.messenger.registerActionHandler( - `${controllerName}:delete`, - this.delete.bind(this), - ); - } } export default AddressBookController; diff --git a/packages/address-book-controller/src/index.ts b/packages/address-book-controller/src/index.ts index 7df7d5fe576..3cf41024037 100644 --- a/packages/address-book-controller/src/index.ts +++ b/packages/address-book-controller/src/index.ts @@ -3,9 +3,6 @@ export type { AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction, - AddressBookControllerListAction, - AddressBookControllerSetAction, - AddressBookControllerDeleteAction, AddressBookControllerActions, AddressBookControllerStateChangeEvent, AddressBookControllerContactUpdatedEvent, @@ -18,3 +15,10 @@ export { getDefaultAddressBookControllerState, AddressBookController, } from './AddressBookController'; + +export type { + AddressBookControllerListAction, + AddressBookControllerSetAction, + AddressBookControllerDeleteAction, + AddressBookControllerClearAction, +} from './AddressBookController-method-action-types'; diff --git a/packages/approval-controller/CHANGELOG.md b/packages/approval-controller/CHANGELOG.md index 44c6a2e5415..df724d39bd7 100644 --- a/packages/approval-controller/CHANGELOG.md +++ b/packages/approval-controller/CHANGELOG.md @@ -9,8 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **BREAKING:** Renamed methods: `clear()` → `clearRequests()`, `has()` → `hasRequest()`, `accept()` → `acceptRequest()`, `reject()` → `rejectRequest()`, `success()` → `showSuccess()`, `error()` → `showError()` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) +### Added + +- New `addRequest()` public method ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger actions: `ApprovalControllerAddAction`, `ApprovalControllerAddAndShowApprovalRequestAction`, `ApprovalControllerGetAction`, `ApprovalControllerGetApprovalCountAction`, `ApprovalControllerGetTotalApprovalCountAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + ## [8.0.0] ### Changed diff --git a/packages/approval-controller/package.json b/packages/approval-controller/package.json index 8acc6b8fae4..e3274935a39 100644 --- a/packages/approval-controller/package.json +++ b/packages/approval-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/approval-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/approval-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", @@ -60,6 +61,7 @@ "deepmerge": "^4.2.2", "jest": "^29.7.0", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/approval-controller/src/ApprovalController-method-action-types.ts b/packages/approval-controller/src/ApprovalController-method-action-types.ts new file mode 100644 index 00000000000..3dc6f6630fc --- /dev/null +++ b/packages/approval-controller/src/ApprovalController-method-action-types.ts @@ -0,0 +1,273 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { ApprovalController } from './ApprovalController'; + +/** + * Adds an approval request per the given arguments, optionally showing + * the approval request to the user. + * + * @param opts - Options bag. + * @param opts.id - The id of the approval request. A random id will be + * generated if none is provided. + * @param opts.origin - The origin of the approval request. + * @param opts.type - The type associated with the approval request. + * @param opts.requestData - Additional data associated with the request, + * if any. + * @param opts.requestState - Additional state associated with the request, + * if any. + * @param shouldShowRequest - Whether to show the approval request to the user. + * @returns The approval promise. + */ +export type ApprovalControllerAddRequestAction = { + type: `ApprovalController:addRequest`; + handler: ApprovalController['addRequest']; +}; + +/** + * Adds an approval request per the given arguments, calls the show approval + * request function, and returns the associated approval promise resolving to + * an AddResult object. + * + * There can only be one approval per origin and type. An error is thrown if + * attempting to add an invalid or duplicate request. + * + * @param opts - Options bag. + * @param opts.id - The id of the approval request. A random id will be + * generated if none is provided. + * @param opts.origin - The origin of the approval request. + * @param opts.type - The type associated with the approval request. + * @param opts.requestData - Additional data associated with the request, + * @param opts.requestState - Additional state associated with the request, + * if any. + * @returns The approval promise resolving to an AddResult object. + */ +export type ApprovalControllerAddAndShowApprovalRequestAction = { + type: `ApprovalController:addAndShowApprovalRequest`; + handler: ApprovalController['addAndShowApprovalRequest']; +}; + +/** + * Adds an approval request per the given arguments and returns the approval + * promise resolving to an AddResult object. + * + * There can only be one approval per origin and type. An error is thrown if + * attempting to add an invalid or duplicate request. + * + * @param opts - Options bag. + * @param opts.id - The id of the approval request. A random id will be + * generated if none is provided. + * @param opts.origin - The origin of the approval request. + * @param opts.type - The type associated with the approval request. + * @param opts.requestData - Additional data associated with the request, + * if any. + * @returns The approval promise resolving to an AddResult object. + */ +export type ApprovalControllerAddAction = { + type: `ApprovalController:add`; + handler: ApprovalController['add']; +}; + +/** + * Gets the info for the approval request with the given id. + * + * @param id - The id of the approval request. + * @returns The approval request data associated with the id. + */ +export type ApprovalControllerGetAction = { + type: `ApprovalController:get`; + handler: ApprovalController['get']; +}; + +/** + * Gets the number of pending approvals, by origin and/or type. + * + * If only `origin` is specified, all approvals for that origin will be + * counted, regardless of type. + * If only `type` is specified, all approvals for that type will be counted, + * regardless of origin. + * If both `origin` and `type` are specified, 0 or 1 will be returned. + * + * @param opts - The approval count options. + * @param opts.origin - An approval origin. + * @param opts.type - The type of the approval request. + * @returns The current approval request count for the given origin and/or + * type. + */ +export type ApprovalControllerGetApprovalCountAction = { + type: `ApprovalController:getApprovalCount`; + handler: ApprovalController['getApprovalCount']; +}; + +/** + * Get the total count of all pending approval requests for all origins. + * + * @returns The total pending approval request count. + */ +export type ApprovalControllerGetTotalApprovalCountAction = { + type: `ApprovalController:getTotalApprovalCount`; + handler: ApprovalController['getTotalApprovalCount']; +}; + +/** + * Checks if there's a pending approval request per the given parameters. + * At least one parameter must be specified. An error will be thrown if the + * parameters are invalid. + * + * If `id` is specified, all other parameters will be ignored. + * If `id` is not specified, the method will check for requests that match + * all of the specified parameters. + * + * @param opts - Options bag. + * @param opts.id - The ID to check for. + * @param opts.origin - The origin to check for. + * @param opts.type - The type to check for. + * @returns `true` if a matching approval is found, and `false` otherwise. + */ +export type ApprovalControllerHasRequestAction = { + type: `ApprovalController:hasRequest`; + handler: ApprovalController['hasRequest']; +}; + +/** + * Resolves the promise of the approval with the given id, and deletes the + * approval. Throws an error if no such approval exists. + * + * @param id - The id of the approval request. + * @param value - The value to resolve the approval promise with. + * @param options - Options bag. + * @returns A promise that either resolves once a result is provided by + * the creator of the approval request, or immediately if `options.waitForResult` + * is `false` or `undefined`. + */ +export type ApprovalControllerAcceptRequestAction = { + type: `ApprovalController:acceptRequest`; + handler: ApprovalController['acceptRequest']; +}; + +/** + * Rejects the promise of the approval with the given id, and deletes the + * approval. Throws an error if no such approval exists. + * + * @param id - The id of the approval request. + * @param error - The error to reject the approval promise with. + */ +export type ApprovalControllerRejectRequestAction = { + type: `ApprovalController:rejectRequest`; + handler: ApprovalController['rejectRequest']; +}; + +/** + * Rejects and deletes all approval requests. + * + * @param rejectionError - The JsonRpcError to reject the approval + * requests with. + */ +export type ApprovalControllerClearRequestsAction = { + type: `ApprovalController:clearRequests`; + handler: ApprovalController['clearRequests']; +}; + +/** + * Updates the request state of the approval with the given id. + * + * @param opts - Options bag. + * @param opts.id - The id of the approval request. + * @param opts.requestState - Additional data associated with the request + */ +export type ApprovalControllerUpdateRequestStateAction = { + type: `ApprovalController:updateRequestState`; + handler: ApprovalController['updateRequestState']; +}; + +/** + * Starts a new approval flow. + * + * @param opts - Options bag. + * @param opts.id - The id of the approval flow. + * @param opts.loadingText - The loading text that will be associated to the approval flow. + * @param opts.show - A flag to determine whether the approval should show to the user. + * @returns The object containing the approval flow id. + */ +export type ApprovalControllerStartFlowAction = { + type: `ApprovalController:startFlow`; + handler: ApprovalController['startFlow']; +}; + +/** + * Ends the current approval flow. + * + * @param opts - Options bag. + * @param opts.id - The id of the approval flow that will be finished. + */ +export type ApprovalControllerEndFlowAction = { + type: `ApprovalController:endFlow`; + handler: ApprovalController['endFlow']; +}; + +/** + * Sets the loading text for the approval flow. + * + * @param opts - Options bag. + * @param opts.id - The approval flow loading text that will be displayed. + * @param opts.loadingText - The loading text that will be associated to the approval flow. + */ +export type ApprovalControllerSetFlowLoadingTextAction = { + type: `ApprovalController:setFlowLoadingText`; + handler: ApprovalController['setFlowLoadingText']; +}; + +/** + * Show a success page. + * + * @param opts - Options bag. + * @param opts.message - The message text or components to display in the page. + * @param opts.header - The text or components to display in the header of the page. + * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved. + * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`. + * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`. + * @returns Empty object to support future additions. + */ +export type ApprovalControllerShowSuccessAction = { + type: `ApprovalController:showSuccess`; + handler: ApprovalController['showSuccess']; +}; + +/** + * Show an error page. + * + * @param opts - Options bag. + * @param opts.message - The message text or components to display in the page. + * @param opts.header - The text or components to display in the header of the page. + * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved. + * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`. + * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`. + * @returns Empty object to support future additions. + */ +export type ApprovalControllerShowErrorAction = { + type: `ApprovalController:showError`; + handler: ApprovalController['showError']; +}; + +/** + * Union of all ApprovalController action types. + */ +export type ApprovalControllerMethodActions = + | ApprovalControllerAddRequestAction + | ApprovalControllerAddAndShowApprovalRequestAction + | ApprovalControllerAddAction + | ApprovalControllerGetAction + | ApprovalControllerGetApprovalCountAction + | ApprovalControllerGetTotalApprovalCountAction + | ApprovalControllerHasRequestAction + | ApprovalControllerAcceptRequestAction + | ApprovalControllerRejectRequestAction + | ApprovalControllerClearRequestsAction + | ApprovalControllerUpdateRequestStateAction + | ApprovalControllerStartFlowAction + | ApprovalControllerEndFlowAction + | ApprovalControllerSetFlowLoadingTextAction + | ApprovalControllerShowSuccessAction + | ApprovalControllerShowErrorAction; diff --git a/packages/approval-controller/src/ApprovalController.test.ts b/packages/approval-controller/src/ApprovalController.test.ts index 687b44328cb..04d1af6832d 100644 --- a/packages/approval-controller/src/ApprovalController.test.ts +++ b/packages/approval-controller/src/ApprovalController.test.ts @@ -339,11 +339,11 @@ describe('approval controller', () => { }), ).not.toThrow(); - expect(approvalController.has({ id: 'foo' })).toBe(true); + expect(approvalController.hasRequest({ id: 'foo' })).toBe(true); - expect(approvalController.has({ origin: 'bar.baz', type: TYPE })).toBe( - true, - ); + expect( + approvalController.hasRequest({ origin: 'bar.baz', type: TYPE }), + ).toBe(true); expect( approvalController.state[PENDING_APPROVALS_STORE_KEY], @@ -385,9 +385,9 @@ describe('approval controller', () => { }), ).not.toThrow(); - expect(approvalController.has({ id: 'foo' })).toBe(true); - expect(approvalController.has({ origin: 'bar.baz' })).toBe(true); - expect(approvalController.has({ type: 'myType' })).toBe(true); + expect(approvalController.hasRequest({ id: 'foo' })).toBe(true); + expect(approvalController.hasRequest({ origin: 'bar.baz' })).toBe(true); + expect(approvalController.hasRequest({ type: 'myType' })).toBe(true); expect( approvalController.state[PENDING_APPROVALS_STORE_KEY].foo.requestData, ).toStrictEqual({ foo: 'bar' }); @@ -403,9 +403,9 @@ describe('approval controller', () => { }), ).not.toThrow(); - expect(approvalController.has({ id: 'foo' })).toBe(true); - expect(approvalController.has({ origin: 'bar.baz' })).toBe(true); - expect(approvalController.has({ type: 'myType' })).toBe(true); + expect(approvalController.hasRequest({ id: 'foo' })).toBe(true); + expect(approvalController.hasRequest({ origin: 'bar.baz' })).toBe(true); + expect(approvalController.hasRequest({ type: 'myType' })).toBe(true); expect( approvalController.state[PENDING_APPROVALS_STORE_KEY].foo.requestState, ).toStrictEqual({ foo: 'bar' }); @@ -423,14 +423,14 @@ describe('approval controller', () => { ).not.toThrow(); expect( - approvalController.has({ id: 'foo1' }) && - approvalController.has({ id: 'foo2' }), + approvalController.hasRequest({ id: 'foo1' }) && + approvalController.hasRequest({ id: 'foo2' }), ).toBe(true); expect( - approvalController.has({ origin: ORIGIN }) && - approvalController.has({ origin: ORIGIN, type: 'myType1' }) && - approvalController.has({ origin: ORIGIN, type: 'myType2' }), + approvalController.hasRequest({ origin: ORIGIN }) && + approvalController.hasRequest({ origin: ORIGIN, type: 'myType1' }) && + approvalController.hasRequest({ origin: ORIGIN, type: 'myType2' }), ).toBe(true); }); @@ -688,10 +688,10 @@ describe('approval controller', () => { addWithCatch({ id: '3', origin: 'origin2', type: 'type1' }); expect(approvalController.getTotalApprovalCount()).toBe(3); - approvalController.reject('2', new Error('foo')); + approvalController.rejectRequest('2', new Error('foo')); expect(approvalController.getTotalApprovalCount()).toBe(2); - approvalController.clear(new JsonRpcError(1, 'clear')); + approvalController.clearRequests(new JsonRpcError(1, 'clear')); expect(approvalController.getTotalApprovalCount()).toBe(0); }); @@ -713,38 +713,38 @@ describe('approval controller', () => { addWithCatch({ id: '2', origin: 'origin1', type: 'type0' }); expect(approvalController.getTotalApprovalCount()).toBe(2); - approvalController.reject('2', new Error('foo')); + approvalController.rejectRequest('2', new Error('foo')); expect(approvalController.getTotalApprovalCount()).toBe(1); - approvalController.clear(new JsonRpcError(1, 'clear')); + approvalController.clearRequests(new JsonRpcError(1, 'clear')); expect(approvalController.getTotalApprovalCount()).toBe(0); }); }); describe('has', () => { it('validates input', () => { - expect(() => approvalController.has()).toThrow( + expect(() => approvalController.hasRequest()).toThrow( getInvalidHasParamsError(), ); - expect(() => approvalController.has({})).toThrow( + expect(() => approvalController.hasRequest({})).toThrow( getInvalidHasParamsError(), ); - expect(() => approvalController.has({ id: true } as never)).toThrow( - getInvalidHasIdError(), - ); + expect(() => + approvalController.hasRequest({ id: true } as never), + ).toThrow(getInvalidHasIdError()); - expect(() => approvalController.has({ origin: true } as never)).toThrow( - getInvalidHasOriginError(), - ); + expect(() => + approvalController.hasRequest({ origin: true } as never), + ).toThrow(getInvalidHasOriginError()); - expect(() => approvalController.has({ type: true } as never)).toThrow( - getInvalidHasTypeError(), - ); + expect(() => + approvalController.hasRequest({ type: true } as never), + ).toThrow(getInvalidHasTypeError()); expect(() => - approvalController.has({ origin: 'foo', type: true } as never), + approvalController.hasRequest({ origin: 'foo', type: true } as never), ).toThrow(getInvalidHasTypeError()); }); @@ -757,7 +757,7 @@ describe('approval controller', () => { type: TYPE, }); - expect(approvalController.has({ id: 'foo' })).toBe(true); + expect(approvalController.hasRequest({ id: 'foo' })).toBe(true); }); it('returns true for existing entry by origin', () => { @@ -765,7 +765,7 @@ describe('approval controller', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE }); - expect(approvalController.has({ origin: 'bar.baz' })).toBe(true); + expect(approvalController.hasRequest({ origin: 'bar.baz' })).toBe(true); }); it('returns true for existing entry by origin and type', () => { @@ -774,7 +774,7 @@ describe('approval controller', () => { approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType' }); expect( - approvalController.has({ origin: 'bar.baz', type: 'myType' }), + approvalController.hasRequest({ origin: 'bar.baz', type: 'myType' }), ).toBe(true); }); @@ -783,7 +783,7 @@ describe('approval controller', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType' }); - expect(approvalController.has({ type: 'myType' })).toBe(true); + expect(approvalController.hasRequest({ type: 'myType' })).toBe(true); }); it('returns false for non-existing entry by id', () => { @@ -791,7 +791,7 @@ describe('approval controller', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE }); - expect(approvalController.has({ id: 'fizz' })).toBe(false); + expect(approvalController.hasRequest({ id: 'fizz' })).toBe(false); }); it('returns false for non-existing entry by origin', () => { @@ -799,7 +799,9 @@ describe('approval controller', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE }); - expect(approvalController.has({ origin: 'fizz.buzz' })).toBe(false); + expect(approvalController.hasRequest({ origin: 'fizz.buzz' })).toBe( + false, + ); }); it('returns false for non-existing entry by existing origin and non-existing type', () => { @@ -808,7 +810,7 @@ describe('approval controller', () => { approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE }); expect( - approvalController.has({ origin: 'bar.baz', type: 'myType' }), + approvalController.hasRequest({ origin: 'bar.baz', type: 'myType' }), ).toBe(false); }); @@ -818,7 +820,7 @@ describe('approval controller', () => { approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType' }); expect( - approvalController.has({ origin: 'fizz.buzz', type: 'myType' }), + approvalController.hasRequest({ origin: 'fizz.buzz', type: 'myType' }), ).toBe(false); }); @@ -827,7 +829,7 @@ describe('approval controller', () => { // eslint-disable-next-line @typescript-eslint/no-floating-promises approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType1' }); - expect(approvalController.has({ type: 'myType2' })).toBe(false); + expect(approvalController.hasRequest({ type: 'myType2' })).toBe(false); }); }); @@ -840,7 +842,7 @@ describe('approval controller', () => { }); // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept('foo', 'success'); + approvalController.acceptRequest('foo', 'success'); const result = await approvalPromise; expect(result).toBe('success'); @@ -860,21 +862,21 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept('foo2', 'success2'); + approvalController.acceptRequest('foo2', 'success2'); let result = await approvalPromise2; expect(result).toBe('success2'); // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept('foo1', 'success1'); + approvalController.acceptRequest('foo1', 'success1'); result = await approvalPromise1; expect(result).toBe('success1'); }); it('throws on unknown id', () => { - expect(() => approvalController.accept('foo')).toThrow( + expect(() => approvalController.acceptRequest('foo')).toThrow( getIdNotFoundError('foo'), ); }); @@ -887,9 +889,13 @@ describe('approval controller', () => { expectsResult: true, }); - const resultPromise = approvalController.accept(ID_MOCK, VALUE_MOCK, { - waitForResult: true, - }); + const resultPromise = approvalController.acceptRequest( + ID_MOCK, + VALUE_MOCK, + { + waitForResult: true, + }, + ); const { resultCallbacks, value } = await approvalPromise; @@ -908,9 +914,13 @@ describe('approval controller', () => { expectsResult: true, }); - const resultPromise = approvalController.accept(ID_MOCK, VALUE_MOCK, { - waitForResult: true, - }); + const resultPromise = approvalController.acceptRequest( + ID_MOCK, + VALUE_MOCK, + { + waitForResult: true, + }, + ); const { resultCallbacks, value } = await approvalPromise; @@ -931,7 +941,7 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept(ID_MOCK, VALUE_MOCK); + approvalController.acceptRequest(ID_MOCK, VALUE_MOCK); expect(await approvalPromise).toStrictEqual({ resultCallbacks: undefined, @@ -949,7 +959,7 @@ describe('approval controller', () => { }); await expect( - approvalController.accept(ID_MOCK, VALUE_MOCK, { + approvalController.acceptRequest(ID_MOCK, VALUE_MOCK, { waitForResult: true, }), ).rejects.toThrow(new ApprovalRequestNoResultSupportError(ID_MOCK)); @@ -962,12 +972,12 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept('foo'); + approvalController.acceptRequest('foo'); expect( - !approvalController.has({ id: 'foo' }) && - !approvalController.has({ type: 'type' }) && - !approvalController.has({ origin: 'bar.baz' }) && + !approvalController.hasRequest({ id: 'foo' }) && + !approvalController.hasRequest({ type: 'type' }) && + !approvalController.hasRequest({ origin: 'bar.baz' }) && !approvalController.state[PENDING_APPROVALS_STORE_KEY].foo, ).toBe(true); }); @@ -982,16 +992,16 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept('fizz'); + approvalController.acceptRequest('fizz'); expect( - !approvalController.has({ id: 'fizz' }) && - !approvalController.has({ origin: 'bar.baz', type: 'type2' }), + !approvalController.hasRequest({ id: 'fizz' }) && + !approvalController.hasRequest({ origin: 'bar.baz', type: 'type2' }), ).toBe(true); expect( - approvalController.has({ id: 'foo' }) && - approvalController.has({ origin: 'bar.baz' }), + approvalController.hasRequest({ id: 'foo' }) && + approvalController.hasRequest({ origin: 'bar.baz' }), ).toBe(true); }); @@ -1004,22 +1014,26 @@ describe('approval controller', () => { expectsResult: true, }); - const resultPromise = approvalController.accept(ID_MOCK, VALUE_MOCK, { - waitForResult: true, - deleteAfterResult: true, - }); + const resultPromise = approvalController.acceptRequest( + ID_MOCK, + VALUE_MOCK, + { + waitForResult: true, + deleteAfterResult: true, + }, + ); const { resultCallbacks } = await approvalPromise; await flushPromises(); - expect(approvalController.has({ id: ID_MOCK })).toBe(true); + expect(approvalController.hasRequest({ id: ID_MOCK })).toBe(true); resultCallbacks?.success(RESULT_MOCK); await flushPromises(); - expect(approvalController.has({ id: ID_MOCK })).toBe(false); + expect(approvalController.hasRequest({ id: ID_MOCK })).toBe(false); await resultPromise; }); @@ -1034,22 +1048,26 @@ describe('approval controller', () => { expectsResult: true, }); - const resultPromise = approvalController.accept(ID_MOCK, VALUE_MOCK, { - waitForResult, - deleteAfterResult: true, - }); + const resultPromise = approvalController.acceptRequest( + ID_MOCK, + VALUE_MOCK, + { + waitForResult, + deleteAfterResult: true, + }, + ); const { resultCallbacks } = await approvalPromise; await flushPromises(); - expect(approvalController.has({ id: ID_MOCK })).toBe(false); + expect(approvalController.hasRequest({ id: ID_MOCK })).toBe(false); resultCallbacks?.success(RESULT_MOCK); await flushPromises(); - expect(approvalController.has({ id: ID_MOCK })).toBe(false); + expect(approvalController.hasRequest({ id: ID_MOCK })).toBe(false); await resultPromise; }, @@ -1063,16 +1081,20 @@ describe('approval controller', () => { expectsResult: true, }); - const resultPromise = approvalController.accept(ID_MOCK, VALUE_MOCK, { - waitForResult: true, - deleteAfterResult: true, - }); + const resultPromise = approvalController.acceptRequest( + ID_MOCK, + VALUE_MOCK, + { + waitForResult: true, + deleteAfterResult: true, + }, + ); const { resultCallbacks } = await approvalPromise; await flushPromises(); - await approvalController.accept(ID_MOCK, VALUE_MOCK); + await approvalController.acceptRequest(ID_MOCK, VALUE_MOCK); resultCallbacks?.success(RESULT_MOCK); @@ -1090,7 +1112,7 @@ describe('approval controller', () => { origin: 'bar.baz', type: TYPE, }); - approvalController.reject('foo', new Error('failure')); + approvalController.rejectRequest('foo', new Error('failure')); await expect(approvalPromise).rejects.toThrow('failure'); }); @@ -1106,16 +1128,16 @@ describe('approval controller', () => { type: 'myType2', }); - approvalController.reject('foo2', new Error('failure2')); - approvalController.reject('foo1', new Error('failure1')); + approvalController.rejectRequest('foo2', new Error('failure2')); + approvalController.rejectRequest('foo1', new Error('failure1')); await expect(rejectionPromise2).rejects.toThrow('failure2'); await expect(rejectionPromise1).rejects.toThrow('failure1'); }); it('throws on unknown id', () => { - expect(() => approvalController.reject('foo', new Error('bar'))).toThrow( - getIdNotFoundError('foo'), - ); + expect(() => + approvalController.rejectRequest('foo', new Error('bar')), + ).toThrow(getIdNotFoundError('foo')); }); it('deletes entry', () => { @@ -1123,12 +1145,12 @@ describe('approval controller', () => { .add({ id: 'foo', origin: 'bar.baz', type: 'type' }) .catch(() => undefined); - approvalController.reject('foo', new Error('failure')); + approvalController.rejectRequest('foo', new Error('failure')); expect( - !approvalController.has({ id: 'foo' }) && - !approvalController.has({ type: 'type' }) && - !approvalController.has({ origin: 'bar.baz' }) && + !approvalController.hasRequest({ id: 'foo' }) && + !approvalController.hasRequest({ type: 'type' }) && + !approvalController.hasRequest({ origin: 'bar.baz' }) && !approvalController.state[PENDING_APPROVALS_STORE_KEY].foo, ).toBe(true); }); @@ -1141,16 +1163,16 @@ describe('approval controller', () => { .add({ id: 'fizz', origin: 'bar.baz', type: 'type2' }) .catch(() => undefined); - approvalController.reject('fizz', new Error('failure')); + approvalController.rejectRequest('fizz', new Error('failure')); expect( - !approvalController.has({ id: 'fizz' }) && - !approvalController.has({ origin: 'bar.baz', type: 'type2' }), + !approvalController.hasRequest({ id: 'fizz' }) && + !approvalController.hasRequest({ origin: 'bar.baz', type: 'type2' }), ).toBe(true); expect( - approvalController.has({ id: 'foo' }) && - approvalController.has({ origin: 'bar.baz' }), + approvalController.hasRequest({ id: 'foo' }) && + approvalController.hasRequest({ origin: 'bar.baz' }), ).toBe(true); }); }); @@ -1180,40 +1202,42 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept('foo2', 'success2'); + approvalController.acceptRequest('foo2', 'success2'); let result = await promise2; expect(result).toBe('success2'); - approvalController.reject('foo4', new Error('failure4')); + approvalController.rejectRequest('foo4', new Error('failure4')); await expect(promise4).rejects.toThrow('failure4'); - approvalController.reject('foo3', new Error('failure3')); + approvalController.rejectRequest('foo3', new Error('failure3')); await expect(promise3).rejects.toThrow('failure3'); - expect(approvalController.has({ origin: 'fizz.buzz' })).toBe(false); - expect(approvalController.has({ origin: 'bar.baz' })).toBe(true); + expect(approvalController.hasRequest({ origin: 'fizz.buzz' })).toBe( + false, + ); + expect(approvalController.hasRequest({ origin: 'bar.baz' })).toBe(true); // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept('foo1', 'success1'); + approvalController.acceptRequest('foo1', 'success1'); result = await promise1; expect(result).toBe('success1'); - expect(approvalController.has({ origin: 'bar.baz' })).toBe(false); + expect(approvalController.hasRequest({ origin: 'bar.baz' })).toBe(false); }); }); describe('clear', () => { it('does nothing if state is already empty', () => { expect(() => - approvalController.clear(new JsonRpcError(1, 'clear')), + approvalController.clearRequests(new JsonRpcError(1, 'clear')), ).not.toThrow(); }); it('deletes existing entries', async () => { - const rejectSpy = jest.spyOn(approvalController, 'reject'); + const rejectSpy = jest.spyOn(approvalController, 'rejectRequest'); approvalController .add({ id: 'foo2', origin: 'bar.baz', type: 'myType' }) @@ -1223,7 +1247,7 @@ describe('approval controller', () => { .add({ id: 'foo3', origin: 'fizz.buzz', type: 'myType' }) .catch((_error) => undefined); - approvalController.clear(new JsonRpcError(1, 'clear')); + approvalController.clearRequests(new JsonRpcError(1, 'clear')); expect( approvalController.state[PENDING_APPROVALS_STORE_KEY], @@ -1238,7 +1262,7 @@ describe('approval controller', () => { type: 'myType', }); - approvalController.clear(new JsonRpcError(1000, 'foo')); + approvalController.clearRequests(new JsonRpcError(1000, 'foo')); await expect(rejectPromise).rejects.toThrow( new JsonRpcError(1000, 'foo'), ); @@ -1247,7 +1271,7 @@ describe('approval controller', () => { it('does not clear approval flows', async () => { approvalController.startFlow(); - approvalController.clear(new JsonRpcError(1, 'clear')); + approvalController.clearRequests(new JsonRpcError(1, 'clear')); expect(approvalController.state[APPROVAL_FLOWS_STORE_KEY]).toHaveLength( 1, @@ -1303,7 +1327,7 @@ describe('approval controller', () => { true, ); expect(showApprovalRequest).toHaveBeenCalledTimes(1); - expect(approvalController.has({ id: 'foo' })).toBe(true); + expect(approvalController.hasRequest({ id: 'foo' })).toBe(true); }); it('addApprovalRequest: shouldShowRequest = false', async () => { @@ -1322,7 +1346,7 @@ describe('approval controller', () => { false, ); expect(showApprovalRequest).toHaveBeenCalledTimes(0); - expect(approvalController.has({ id: 'foo' })).toBe(true); + expect(approvalController.hasRequest({ id: 'foo' })).toBe(true); }); it('updateRequestState', () => { @@ -1490,9 +1514,11 @@ describe('approval controller', () => { expect(request.id).toStrictEqual(expect.any(String)); expect(request.requestData).toStrictEqual(expectedData); - expect(approvalController.has({ id: request.id })).toBe(true); - expect(approvalController.has({ origin: ORIGIN_METAMASK })).toBe(true); - expect(approvalController.has({ type: expectedType })).toBe(true); + expect(approvalController.hasRequest({ id: request.id })).toBe(true); + expect(approvalController.hasRequest({ origin: ORIGIN_METAMASK })).toBe( + true, + ); + expect(approvalController.hasRequest({ type: expectedType })).toBe(true); } /** @@ -1513,7 +1539,7 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept(resultRequestId); + approvalController.acceptRequest(resultRequestId); await promise; expect(approvalController.state[APPROVAL_FLOWS_STORE_KEY]).toHaveLength( @@ -1563,7 +1589,7 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept(resultRequestId); + approvalController.acceptRequest(resultRequestId); await promise; expect(console.info).toHaveBeenCalledTimes(1); @@ -1577,14 +1603,14 @@ describe('approval controller', () => { it('adds request with result success approval type', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.success(SUCCESS_OPTIONS_MOCK); + approvalController.showSuccess(SUCCESS_OPTIONS_MOCK); expectRequestAdded(APPROVAL_TYPE_RESULT_SUCCESS, SUCCESS_OPTIONS_MOCK); }); it('adds request with no options', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.success(); + approvalController.showSuccess(); expectRequestAdded(APPROVAL_TYPE_RESULT_SUCCESS, { message: undefined, @@ -1597,7 +1623,7 @@ describe('approval controller', () => { it('only includes relevant options in request data', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.success({ + approvalController.showSuccess({ ...SUCCESS_OPTIONS_MOCK, extra: 'testValue', } as SuccessOptions); @@ -1612,13 +1638,13 @@ describe('approval controller', () => { it('shows approval request', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.success(SUCCESS_OPTIONS_MOCK); + approvalController.showSuccess(SUCCESS_OPTIONS_MOCK); expect(showApprovalRequest).toHaveBeenCalledTimes(1); }); it('ends specified flow', async () => { await endsSpecifiedFlowTemplate((flowId) => - approvalController.success({ + approvalController.showSuccess({ ...SUCCESS_OPTIONS_MOCK, flowToEnd: flowId, }), @@ -1629,13 +1655,13 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises doesNotThrowIfAddingRequestFails(() => - approvalController.success(SUCCESS_OPTIONS_MOCK), + approvalController.showSuccess(SUCCESS_OPTIONS_MOCK), ); }); it('does not throw if ending the flow fails', async () => { await doesNotThrowIfEndFlowFails(() => - approvalController.success({ + approvalController.showSuccess({ ...SUCCESS_OPTIONS_MOCK, flowToEnd: FLOW_ID_MOCK, }), @@ -1647,14 +1673,14 @@ describe('approval controller', () => { it('adds request with result error approval type', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.error(ERROR_OPTIONS_MOCK); + approvalController.showError(ERROR_OPTIONS_MOCK); expectRequestAdded(APPROVAL_TYPE_RESULT_ERROR, ERROR_OPTIONS_MOCK); }); it('adds request with no options', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.error(); + approvalController.showError(); expectRequestAdded(APPROVAL_TYPE_RESULT_ERROR, { error: undefined, @@ -1667,7 +1693,7 @@ describe('approval controller', () => { it('only includes relevant options in request data', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.error({ + approvalController.showError({ ...ERROR_OPTIONS_MOCK, extra: 'testValue', } as ErrorOptions); @@ -1682,13 +1708,13 @@ describe('approval controller', () => { it('shows approval request', async () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.error(ERROR_OPTIONS_MOCK); + approvalController.showError(ERROR_OPTIONS_MOCK); expect(showApprovalRequest).toHaveBeenCalledTimes(1); }); it('ends specified flow', async () => { await endsSpecifiedFlowTemplate((flowId) => - approvalController.error({ + approvalController.showError({ ...ERROR_OPTIONS_MOCK, flowToEnd: flowId, }), @@ -1699,13 +1725,13 @@ describe('approval controller', () => { // TODO: Either fix this lint violation or explain why it's necessary to ignore. // eslint-disable-next-line @typescript-eslint/no-floating-promises doesNotThrowIfAddingRequestFails(() => - approvalController.error(ERROR_OPTIONS_MOCK), + approvalController.showError(ERROR_OPTIONS_MOCK), ); }); it('does not throw if ending the flow fails', async () => { await doesNotThrowIfEndFlowFails(() => - approvalController.error({ + approvalController.showError({ ...ERROR_OPTIONS_MOCK, flowToEnd: FLOW_ID_MOCK, }), diff --git a/packages/approval-controller/src/ApprovalController.ts b/packages/approval-controller/src/ApprovalController.ts index ed92ddb451d..266d93658dc 100644 --- a/packages/approval-controller/src/ApprovalController.ts +++ b/packages/approval-controller/src/ApprovalController.ts @@ -10,6 +10,7 @@ import { rpcErrors } from '@metamask/rpc-errors'; import type { Json, OptionalField } from '@metamask/utils'; import { nanoid } from 'nanoid'; +import type { ApprovalControllerMethodActions } from './ApprovalController-method-action-types'; import { ApprovalRequestNotFoundError, ApprovalRequestNoResultSupportError, @@ -59,6 +60,27 @@ const getDefaultState = (): ApprovalControllerState => { }; }; +// === MESSENGER === + +const MESSENGER_EXPOSED_METHODS = [ + 'clearRequests', + 'addRequest', + 'hasRequest', + 'acceptRequest', + 'rejectRequest', + 'updateRequestState', + 'startFlow', + 'endFlow', + 'setFlowLoadingText', + 'showSuccess', + 'showError', + 'add', + 'addAndShowApprovalRequest', + 'get', + 'getApprovalCount', + 'getTotalApprovalCount', +] as const; + // Internal Types type ApprovalPromiseResolve = (value?: unknown | AddResult) => void; @@ -281,77 +303,9 @@ export type GetApprovalsState = ControllerGetStateAction< ApprovalControllerState >; -export type ClearApprovalRequests = { - type: `${typeof controllerName}:clearRequests`; - handler: (error: JsonRpcError) => void; -}; - -export type AddApprovalRequest = { - type: `${typeof controllerName}:addRequest`; - handler: ( - opts: AddApprovalOptions, - shouldShowRequest: boolean, - ) => ReturnType; -}; - -export type HasApprovalRequest = { - type: `${typeof controllerName}:hasRequest`; - handler: ApprovalController['has']; -}; - -export type AcceptRequest = { - type: `${typeof controllerName}:acceptRequest`; - handler: ApprovalController['accept']; -}; - -export type RejectRequest = { - type: `${typeof controllerName}:rejectRequest`; - handler: ApprovalController['reject']; -}; - -export type UpdateRequestState = { - type: `${typeof controllerName}:updateRequestState`; - handler: ApprovalController['updateRequestState']; -}; - -export type StartFlow = { - type: `${typeof controllerName}:startFlow`; - handler: ApprovalController['startFlow']; -}; - -export type EndFlow = { - type: `${typeof controllerName}:endFlow`; - handler: ApprovalController['endFlow']; -}; - -export type SetFlowLoadingText = { - type: `${typeof controllerName}:setFlowLoadingText`; - handler: ApprovalController['setFlowLoadingText']; -}; - -export type ShowSuccess = { - type: `${typeof controllerName}:showSuccess`; - handler: ApprovalController['success']; -}; - -export type ShowError = { - type: `${typeof controllerName}:showError`; - handler: ApprovalController['error']; -}; - export type ApprovalControllerActions = | GetApprovalsState - | ClearApprovalRequests - | AddApprovalRequest - | HasApprovalRequest - | AcceptRequest - | RejectRequest - | UpdateRequestState - | StartFlow - | EndFlow - | SetFlowLoadingText - | ShowSuccess - | ShowError; + | ApprovalControllerMethodActions; /** * Controller for managing requests that require user approval. @@ -404,73 +358,36 @@ export class ApprovalController extends BaseController< // eslint-disable-next-line @typescript-eslint/no-misused-promises this.#showApprovalRequest = showApprovalRequest; this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting; - this.registerMessageHandlers(); + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, + ); } /** - * Constructor helper for registering this controller's messaging system - * actions. + * Adds an approval request per the given arguments, optionally showing + * the approval request to the user. + * + * @param opts - Options bag. + * @param opts.id - The id of the approval request. A random id will be + * generated if none is provided. + * @param opts.origin - The origin of the approval request. + * @param opts.type - The type associated with the approval request. + * @param opts.requestData - Additional data associated with the request, + * if any. + * @param opts.requestState - Additional state associated with the request, + * if any. + * @param shouldShowRequest - Whether to show the approval request to the user. + * @returns The approval promise. */ - private registerMessageHandlers(): void { - this.messenger.registerActionHandler( - `${controllerName}:clearRequests` as const, - this.clear.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:addRequest` as const, - (opts: AddApprovalOptions, shouldShowRequest: boolean) => { - if (shouldShowRequest) { - return this.addAndShowApprovalRequest(opts); - } - return this.add(opts); - }, - ); - - this.messenger.registerActionHandler( - `${controllerName}:hasRequest` as const, - this.has.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:acceptRequest` as const, - this.accept.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:rejectRequest` as const, - this.reject.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:updateRequestState` as const, - this.updateRequestState.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:startFlow` as const, - this.startFlow.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:endFlow` as const, - this.endFlow.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:setFlowLoadingText` as const, - this.setFlowLoadingText.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:showSuccess` as const, - this.success.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:showError` as const, - this.error.bind(this), - ); + addRequest( + opts: AddApprovalOptions, + shouldShowRequest: boolean, + ): Promise { + if (shouldShowRequest) { + return this.addAndShowApprovalRequest(opts); + } + return this.add(opts); } /** @@ -650,7 +567,9 @@ export class ApprovalController extends BaseController< * @param opts.type - The type to check for. * @returns `true` if a matching approval is found, and `false` otherwise. */ - has(opts: { id?: string; origin?: string; type?: string } = {}): boolean { + hasRequest( + opts: { id?: string; origin?: string; type?: string } = {}, + ): boolean { const { id, origin, type: _type } = opts; if (id) { @@ -700,7 +619,7 @@ export class ApprovalController extends BaseController< * the creator of the approval request, or immediately if `options.waitForResult` * is `false` or `undefined`. */ - accept( + acceptRequest( id: string, value?: unknown, options?: AcceptOptions, @@ -751,7 +670,7 @@ export class ApprovalController extends BaseController< * @param id - The id of the approval request. * @param error - The error to reject the approval promise with. */ - reject(id: string, error: unknown): void { + rejectRequest(id: string, error: unknown): void { const callbacks = this.#getCallbacks(id); this.#delete(id); callbacks.reject(error); @@ -763,9 +682,9 @@ export class ApprovalController extends BaseController< * @param rejectionError - The JsonRpcError to reject the approval * requests with. */ - clear(rejectionError: JsonRpcError): void { + clearRequests(rejectionError: JsonRpcError): void { for (const id of this.#approvals.keys()) { - this.reject(id, rejectionError); + this.rejectRequest(id, rejectionError); } this.#origins.clear(); this.update((draftState) => { @@ -874,7 +793,7 @@ export class ApprovalController extends BaseController< * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`. * @returns Empty object to support future additions. */ - async success(opts: SuccessOptions = {}): Promise { + async showSuccess(opts: SuccessOptions = {}): Promise { await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, { message: opts.message, header: opts.header, @@ -896,7 +815,7 @@ export class ApprovalController extends BaseController< * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`. * @returns Empty object to support future additions. */ - async error(opts: ErrorOptions = {}): Promise { + async showError(opts: ErrorOptions = {}): Promise { await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, { error: opts.error, header: opts.header, @@ -930,7 +849,7 @@ export class ApprovalController extends BaseController< if ( !this.#typesExcludedFromRateLimiting.includes(type) && - this.has({ origin, type }) + this.hasRequest({ origin, type }) ) { throw rpcErrors.resourceUnavailable( getAlreadyPendingMessage(origin, type), diff --git a/packages/approval-controller/src/index.ts b/packages/approval-controller/src/index.ts index 40addb379ba..5a8f6173ff2 100644 --- a/packages/approval-controller/src/index.ts +++ b/packages/approval-controller/src/index.ts @@ -1,2 +1,20 @@ export * from './ApprovalController'; +export type { + ApprovalControllerAddRequestAction, + ApprovalControllerAddAndShowApprovalRequestAction, + ApprovalControllerAddAction, + ApprovalControllerGetAction, + ApprovalControllerGetApprovalCountAction, + ApprovalControllerGetTotalApprovalCountAction, + ApprovalControllerHasRequestAction, + ApprovalControllerAcceptRequestAction, + ApprovalControllerRejectRequestAction, + ApprovalControllerClearRequestsAction, + ApprovalControllerUpdateRequestStateAction, + ApprovalControllerStartFlowAction, + ApprovalControllerEndFlowAction, + ApprovalControllerSetFlowLoadingTextAction, + ApprovalControllerShowSuccessAction, + ApprovalControllerShowErrorAction, +} from './ApprovalController-method-action-types'; export * from './errors'; diff --git a/packages/assets-controllers/src/NftController.test.ts b/packages/assets-controllers/src/NftController.test.ts index 4b60131d371..47f5d03a4b9 100644 --- a/packages/assets-controllers/src/NftController.test.ts +++ b/packages/assets-controllers/src/NftController.test.ts @@ -1220,8 +1220,9 @@ describe('NftController', () => { // now accept the request // TODO: Either fix this lint violation or explain why it's necessary to ignore. + // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept(requestId); + approvalController.acceptRequest(requestId); await acceptedRequest; // check that the NFT was added to the correct chainId/selectedAddress in state @@ -1330,8 +1331,9 @@ describe('NftController', () => { }); // now accept the request // TODO: Either fix this lint violation or explain why it's necessary to ignore. + // eslint-disable-next-line @typescript-eslint/no-floating-promises - approvalController.accept(requestId); + approvalController.acceptRequest(requestId); await acceptedRequest; // check that the NFT was added to the correct chainId/selectedAddress in state diff --git a/packages/assets-controllers/src/NftController.ts b/packages/assets-controllers/src/NftController.ts index 9e71b7ef5c4..81e8f5d0830 100644 --- a/packages/assets-controllers/src/NftController.ts +++ b/packages/assets-controllers/src/NftController.ts @@ -4,7 +4,7 @@ import type { AccountsControllerGetAccountAction, AccountsControllerGetSelectedAccountAction, } from '@metamask/accounts-controller'; -import type { AddApprovalRequest } from '@metamask/approval-controller'; +import type { ApprovalControllerAddRequestAction as AddApprovalRequest } from '@metamask/approval-controller'; import { BaseController } from '@metamask/base-controller'; import type { ControllerStateChangeEvent, diff --git a/packages/assets-controllers/src/NftDetectionController.ts b/packages/assets-controllers/src/NftDetectionController.ts index 24a4ae70b44..6e3f12f788d 100644 --- a/packages/assets-controllers/src/NftDetectionController.ts +++ b/packages/assets-controllers/src/NftDetectionController.ts @@ -1,5 +1,5 @@ import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller'; -import type { AddApprovalRequest } from '@metamask/approval-controller'; +import type { ApprovalControllerAddRequestAction as AddApprovalRequest } from '@metamask/approval-controller'; import { BaseController } from '@metamask/base-controller'; import type { ControllerGetStateAction, diff --git a/packages/assets-controllers/src/TokensController.test.ts b/packages/assets-controllers/src/TokensController.test.ts index 3a91a5bba23..1f61d6b5e33 100644 --- a/packages/assets-controllers/src/TokensController.test.ts +++ b/packages/assets-controllers/src/TokensController.test.ts @@ -2803,8 +2803,8 @@ describe('TokensController', () => { await promiseForApprovals; - await approvalController.accept(requestId); - await approvalController.accept('67890'); + await approvalController.acceptRequest(requestId); + await approvalController.acceptRequest('67890'); await acceptedRequest; expect( diff --git a/packages/assets-controllers/src/TokensController.ts b/packages/assets-controllers/src/TokensController.ts index d8687ed4d77..0b4619e1840 100644 --- a/packages/assets-controllers/src/TokensController.ts +++ b/packages/assets-controllers/src/TokensController.ts @@ -6,7 +6,7 @@ import type { AccountsControllerListAccountsAction, AccountsControllerSelectedEvmAccountChangeEvent, } from '@metamask/accounts-controller'; -import type { AddApprovalRequest } from '@metamask/approval-controller'; +import type { ApprovalControllerAddRequestAction as AddApprovalRequest } from '@metamask/approval-controller'; import type { ControllerGetStateAction, ControllerStateChangeEvent, diff --git a/packages/ens-controller/CHANGELOG.md b/packages/ens-controller/CHANGELOG.md index 34722c1ce0c..077dc55b641 100644 --- a/packages/ens-controller/CHANGELOG.md +++ b/packages/ens-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New messenger actions: `EnsControllerResetStateAction`, `EnsControllerClearAction`, `EnsControllerDeleteAction`, `EnsControllerGetAction`, `EnsControllerSetAction`, `EnsControllerReverseResolveAddressAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + ## [19.0.3] ### Changed diff --git a/packages/ens-controller/package.json b/packages/ens-controller/package.json index 1df1e5a809e..46aa4e199e3 100644 --- a/packages/ens-controller/package.json +++ b/packages/ens-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/ens-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/ens-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", @@ -62,6 +63,7 @@ "deepmerge": "^4.2.2", "jest": "^29.7.0", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/ens-controller/src/EnsController-method-action-types.ts b/packages/ens-controller/src/EnsController-method-action-types.ts new file mode 100644 index 00000000000..f516dd91109 --- /dev/null +++ b/packages/ens-controller/src/EnsController-method-action-types.ts @@ -0,0 +1,83 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { EnsController } from './EnsController'; + +/** + * Clears ensResolutionsByAddress state property. + */ +export type EnsControllerResetStateAction = { + type: `EnsController:resetState`; + handler: EnsController['resetState']; +}; + +/** + * Remove all chain Ids and ENS entries from state. + */ +export type EnsControllerClearAction = { + type: `EnsController:clear`; + handler: EnsController['clear']; +}; + +/** + * Delete an ENS entry. + * + * @param chainId - Parent chain of the ENS entry to delete. + * @param ensName - Name of the ENS entry to delete. + * @returns Boolean indicating if the entry was deleted. + */ +export type EnsControllerDeleteAction = { + type: `EnsController:delete`; + handler: EnsController['delete']; +}; + +/** + * Retrieve a DNS entry. + * + * @param chainId - Parent chain of the ENS entry to retrieve. + * @param ensName - Name of the ENS entry to retrieve. + * @returns The EnsEntry or null if it does not exist. + */ +export type EnsControllerGetAction = { + type: `EnsController:get`; + handler: EnsController['get']; +}; + +/** + * Add or update an ENS entry by chainId and ensName. + * + * A null address indicates that the ENS name does not resolve. + * + * @param chainId - Id of the associated chain. + * @param ensName - The ENS name. + * @param address - Associated address (or null) to add or update. + * @returns Boolean indicating if the entry was set. + */ +export type EnsControllerSetAction = { + type: `EnsController:set`; + handler: EnsController['set']; +}; + +/** + * Resolve ens by address. + * + * @param nonChecksummedAddress - address + * @returns ens resolution + */ +export type EnsControllerReverseResolveAddressAction = { + type: `EnsController:reverseResolveAddress`; + handler: EnsController['reverseResolveAddress']; +}; + +/** + * Union of all EnsController action types. + */ +export type EnsControllerMethodActions = + | EnsControllerResetStateAction + | EnsControllerClearAction + | EnsControllerDeleteAction + | EnsControllerGetAction + | EnsControllerSetAction + | EnsControllerReverseResolveAddressAction; diff --git a/packages/ens-controller/src/EnsController.ts b/packages/ens-controller/src/EnsController.ts index 1e20c835b29..b7bf94458c6 100644 --- a/packages/ens-controller/src/EnsController.ts +++ b/packages/ens-controller/src/EnsController.ts @@ -25,10 +25,21 @@ import type { Hex } from '@metamask/utils'; import { createProjectLogger } from '@metamask/utils'; import { toASCII } from 'punycode/punycode.js'; +import type { EnsControllerMethodActions } from './EnsController-method-action-types'; + const log = createProjectLogger('ens-controller'); const name = 'EnsController'; +const MESSENGER_EXPOSED_METHODS = [ + 'resetState', + 'clear', + 'delete', + 'get', + 'set', + 'reverseResolveAddress', +] as const; + // Map of chainIDs and ENS registry contract addresses export const DEFAULT_ENS_NETWORK_MAP: Record = { // Mainnet @@ -76,11 +87,15 @@ export type EnsControllerState = { ensResolutionsByAddress: { [key: string]: string }; }; -export type EnsControllerActions = ControllerGetStateAction< +export type EnsControllerGetStateAction = ControllerGetStateAction< typeof name, EnsControllerState >; +export type EnsControllerActions = + | EnsControllerGetStateAction + | EnsControllerMethodActions; + export type EnsControllerEvents = ControllerStateChangeEvent< typeof name, EnsControllerState @@ -174,6 +189,11 @@ export class EnsController extends BaseController< }, }); + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, + ); + this.#setDefaultEthProvider(registriesByChainId); if (onNetworkDidChange) { diff --git a/packages/ens-controller/src/index.ts b/packages/ens-controller/src/index.ts index 14cbf704a6b..a2f476a1a05 100644 --- a/packages/ens-controller/src/index.ts +++ b/packages/ens-controller/src/index.ts @@ -1 +1,9 @@ export * from './EnsController'; +export type { + EnsControllerResetStateAction, + EnsControllerClearAction, + EnsControllerDeleteAction, + EnsControllerGetAction, + EnsControllerSetAction, + EnsControllerReverseResolveAddressAction, +} from './EnsController-method-action-types'; diff --git a/packages/gas-fee-controller/CHANGELOG.md b/packages/gas-fee-controller/CHANGELOG.md index 8b11eeb249b..131d80f7530 100644 --- a/packages/gas-fee-controller/CHANGELOG.md +++ b/packages/gas-fee-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New messenger actions: `GasFeeControllerResetPollingAction`, `GasFeeControllerFetchGasFeeEstimatesAction`, `GasFeeControllerGetGasFeeEstimatesAndStartPollingAction`, `GasFeeControllerDisconnectPollerAction`, `GasFeeControllerStopPollingAction`, `GasFeeControllerGetTimeEstimateAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + ## [26.0.3] ### Changed diff --git a/packages/gas-fee-controller/package.json b/packages/gas-fee-controller/package.json index 54e75afba1f..01895cc8e9f 100644 --- a/packages/gas-fee-controller/package.json +++ b/packages/gas-fee-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/gas-fee-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/gas-fee-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", @@ -70,6 +71,7 @@ "jest-when": "^3.4.2", "nock": "^13.3.1", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/gas-fee-controller/src/GasFeeController-method-action-types.ts b/packages/gas-fee-controller/src/GasFeeController-method-action-types.ts new file mode 100644 index 00000000000..d00beb19b45 --- /dev/null +++ b/packages/gas-fee-controller/src/GasFeeController-method-action-types.ts @@ -0,0 +1,80 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { GasFeeController } from './GasFeeController'; + +/** + * Resets the polling interval by stopping and restarting polling + * with the existing poll tokens. + */ +export type GasFeeControllerResetPollingAction = { + type: `GasFeeController:resetPolling`; + handler: GasFeeController['resetPolling']; +}; + +/** + * Fetches gas fee estimates. + * + * @param options - The gas fee estimate options. + * @returns The gas fee estimates. + */ +export type GasFeeControllerFetchGasFeeEstimatesAction = { + type: `GasFeeController:fetchGasFeeEstimates`; + handler: GasFeeController['fetchGasFeeEstimates']; +}; + +/** + * Gets gas fee estimates and starts polling for updates. + * + * @param pollToken - An existing poll token to reuse, or undefined to + * generate a new one. + * @returns The poll token that can be used to stop polling. + */ +export type GasFeeControllerGetGasFeeEstimatesAndStartPollingAction = { + type: `GasFeeController:getGasFeeEstimatesAndStartPolling`; + handler: GasFeeController['getGasFeeEstimatesAndStartPolling']; +}; + +/** + * Remove the poll token, and stop polling if the set of poll tokens is empty. + * + * @param pollToken - The poll token to disconnect. + */ +export type GasFeeControllerDisconnectPollerAction = { + type: `GasFeeController:disconnectPoller`; + handler: GasFeeController['disconnectPoller']; +}; + +/** + * Stops polling for gas fee estimates and clears all poll tokens. + */ +export type GasFeeControllerStopPollingAction = { + type: `GasFeeController:stopPolling`; + handler: GasFeeController['stopPolling']; +}; + +/** + * Gets the estimated time for a transaction based on the given gas parameters. + * + * @param maxPriorityFeePerGas - The maximum priority fee per gas in GWEI. + * @param maxFeePerGas - The maximum fee per gas in GWEI. + * @returns The estimated time bounds, or an empty object if fee market + * estimates are not available. + */ +export type GasFeeControllerGetTimeEstimateAction = { + type: `GasFeeController:getTimeEstimate`; + handler: GasFeeController['getTimeEstimate']; +}; + +/** + * Union of all GasFeeController action types. + */ +export type GasFeeControllerMethodActions = + | GasFeeControllerResetPollingAction + | GasFeeControllerFetchGasFeeEstimatesAction + | GasFeeControllerGetGasFeeEstimatesAndStartPollingAction + | GasFeeControllerDisconnectPollerAction + | GasFeeControllerStopPollingAction + | GasFeeControllerGetTimeEstimateAction; diff --git a/packages/gas-fee-controller/src/GasFeeController.ts b/packages/gas-fee-controller/src/GasFeeController.ts index f68a381ac24..a35a910093e 100644 --- a/packages/gas-fee-controller/src/GasFeeController.ts +++ b/packages/gas-fee-controller/src/GasFeeController.ts @@ -30,6 +30,7 @@ import { fetchEthGasPriceEstimate, calculateTimeEstimate, } from './gas-util'; +import type { GasFeeControllerMethodActions } from './GasFeeController-method-action-types'; export const LEGACY_GAS_PRICES_API_URL = `https://api.metaswap.codefi.network/gasPrices`; @@ -250,6 +251,15 @@ export type GasFeeState = GasFeeEstimatesByChainId & const name = 'GasFeeController'; +const MESSENGER_EXPOSED_METHODS = [ + 'resetPolling', + 'fetchGasFeeEstimates', + 'getGasFeeEstimatesAndStartPolling', + 'disconnectPoller', + 'stopPolling', + 'getTimeEstimate', +] as const; + export type GasFeeStateChange = ControllerStateChangeEvent< typeof name, GasFeeState @@ -257,7 +267,9 @@ export type GasFeeStateChange = ControllerStateChangeEvent< export type GetGasFeeState = ControllerGetStateAction; -export type GasFeeControllerActions = GetGasFeeState; +export type GasFeeControllerActions = + | GetGasFeeState + | GasFeeControllerMethodActions; export type GasFeeControllerEvents = GasFeeStateChange; @@ -389,6 +401,11 @@ export class GasFeeController extends StaticIntervalPollingController { @@ -552,6 +586,9 @@ export class GasFeeController extends StaticIntervalPollingController; -export type LoggingControllerActions = LoggingControllerGetStateAction | AddLog; +export type LoggingControllerActions = + | LoggingControllerGetStateAction + | LoggingControllerMethodActions; export type LoggingControllerStateChangeEvent = ControllerStateChangeEvent< typeof name, @@ -106,8 +103,9 @@ export class LoggingController extends BaseController< }, }); - this.messenger.registerActionHandler(`${name}:add` as const, (log: Log) => - this.add(log), + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, ); } diff --git a/packages/logging-controller/src/index.ts b/packages/logging-controller/src/index.ts index e52d08b05da..aaf85b45b3b 100644 --- a/packages/logging-controller/src/index.ts +++ b/packages/logging-controller/src/index.ts @@ -1,2 +1,6 @@ export * from './LoggingController'; +export type { + LoggingControllerAddAction, + LoggingControllerClearAction, +} from './LoggingController-method-action-types'; export * from './logTypes'; diff --git a/packages/name-controller/CHANGELOG.md b/packages/name-controller/CHANGELOG.md index b822a94f617..7cf1d695e76 100644 --- a/packages/name-controller/CHANGELOG.md +++ b/packages/name-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New messenger actions: `NameControllerSetNameAction`, `NameControllerUpdateProposedNamesAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + ### Changed - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) diff --git a/packages/name-controller/package.json b/packages/name-controller/package.json index de8329673df..2c75ce550d9 100644 --- a/packages/name-controller/package.json +++ b/packages/name-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/name-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/name-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", @@ -61,6 +62,7 @@ "deepmerge": "^4.2.2", "jest": "^29.7.0", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/name-controller/src/NameController-method-action-types.ts b/packages/name-controller/src/NameController-method-action-types.ts new file mode 100644 index 00000000000..5990d7a2618 --- /dev/null +++ b/packages/name-controller/src/NameController-method-action-types.ts @@ -0,0 +1,43 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { NameController } from './NameController'; + +/** + * Set the user specified name for a value. + * + * @param request - Request object. + * @param request.name - Name to set. + * @param request.sourceId - Optional ID of the source of the proposed name. + * @param request.type - Type of value to set the name for. + * @param request.value - Value to set the name for. + * @param request.variation - Variation of the raw value to set the name for. The chain ID if the type is Ethereum address. + */ +export type NameControllerSetNameAction = { + type: `NameController:setName`; + handler: NameController['setName']; +}; + +/** + * Generate the proposed names for a value using the name providers and store them in the state. + * + * @param request - Request object. + * @param request.value - Value to update the proposed names for. + * @param request.type - Type of value to update the proposed names for. + * @param request.sourceIds - Optional array of source IDs to limit which sources are used by the providers. If not provided, all sources in all providers will be used. + * @param request.variation - Variation of the raw value to update proposed names for. The chain ID if the type is Ethereum address. + * @returns The updated proposed names for the value. + */ +export type NameControllerUpdateProposedNamesAction = { + type: `NameController:updateProposedNames`; + handler: NameController['updateProposedNames']; +}; + +/** + * Union of all NameController action types. + */ +export type NameControllerMethodActions = + | NameControllerSetNameAction + | NameControllerUpdateProposedNamesAction; diff --git a/packages/name-controller/src/NameController.test.ts b/packages/name-controller/src/NameController.test.ts index 0896434d901..403688fd249 100644 --- a/packages/name-controller/src/NameController.test.ts +++ b/packages/name-controller/src/NameController.test.ts @@ -25,6 +25,7 @@ const TIME_MOCK = 123; const MESSENGER_MOCK = { registerActionHandler: jest.fn(), + registerMethodActionHandlers: jest.fn(), registerInitialEventPayload: jest.fn(), publish: jest.fn(), // TODO: Replace `any` with type diff --git a/packages/name-controller/src/NameController.ts b/packages/name-controller/src/NameController.ts index 36d55321efe..1d9cb25c087 100644 --- a/packages/name-controller/src/NameController.ts +++ b/packages/name-controller/src/NameController.ts @@ -6,6 +6,7 @@ import { BaseController } from '@metamask/base-controller'; import { isSafeDynamicKey } from '@metamask/controller-utils'; import type { Messenger } from '@metamask/messenger'; +import type { NameControllerMethodActions } from './NameController-method-action-types'; import type { NameProvider, NameProviderRequest, @@ -36,6 +37,8 @@ const DEFAULT_VARIATION = ''; const controllerName = 'NameController'; +const MESSENGER_EXPOSED_METHODS = ['setName', 'updateProposedNames'] as const; + const stateMetadata = { names: { includeInStateLogs: true, @@ -91,7 +94,7 @@ export type NameStateChange = ControllerStateChangeEvent< NameControllerState >; -export type NameControllerActions = GetNameState; +export type NameControllerActions = GetNameState | NameControllerMethodActions; export type NameControllerEvents = NameStateChange; @@ -163,6 +166,11 @@ export class NameController extends BaseController< state: { ...getDefaultState(), ...state }, }); + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, + ); + this.#providers = providers; this.#updateDelay = updateDelay ?? DEFAULT_UPDATE_DELAY; } diff --git a/packages/name-controller/src/index.ts b/packages/name-controller/src/index.ts index 4647caa08c1..7a9bdceff5e 100644 --- a/packages/name-controller/src/index.ts +++ b/packages/name-controller/src/index.ts @@ -1,4 +1,8 @@ export * from './NameController'; +export type { + NameControllerSetNameAction, + NameControllerUpdateProposedNamesAction, +} from './NameController-method-action-types'; export * from './types'; export * from './providers/ens'; export * from './providers/etherscan'; diff --git a/packages/permission-controller/src/PermissionController.ts b/packages/permission-controller/src/PermissionController.ts index c09569dc36e..64f226c4c1b 100644 --- a/packages/permission-controller/src/PermissionController.ts +++ b/packages/permission-controller/src/PermissionController.ts @@ -1,8 +1,8 @@ import type { - AcceptRequest as AcceptApprovalRequest, - AddApprovalRequest, - HasApprovalRequest, - RejectRequest as RejectApprovalRequest, + ApprovalControllerAcceptRequestAction as AcceptApprovalRequest, + ApprovalControllerAddRequestAction as AddApprovalRequest, + ApprovalControllerHasRequestAction as HasApprovalRequest, + ApprovalControllerRejectRequestAction as RejectApprovalRequest, } from '@metamask/approval-controller'; import type { StateMetadata, @@ -2450,7 +2450,7 @@ export class PermissionController< /** * Adds a request to the {@link ApprovalController} using the - * {@link AddApprovalRequest} action. Also validates the resulting approved + * {@link ApprovalControllerAddRequestAction} action. Also validates the resulting approved * permissions request, and throws an error if validation fails. * * @param permissionsRequest - The permissions request object. @@ -2738,7 +2738,7 @@ export class PermissionController< * * @see {@link PermissionController.acceptPermissionsRequest} and * {@link PermissionController.rejectPermissionsRequest} for usage. - * @param options - The {@link HasApprovalRequest} options. + * @param options - The {@link ApprovalControllerHasRequestAction} options. * @param options.id - The id of the approval request to check for. * @returns Whether the specified request exists. */ diff --git a/packages/signature-controller/CHANGELOG.md b/packages/signature-controller/CHANGELOG.md index d3460df50f9..3ba5bcf88b5 100644 --- a/packages/signature-controller/CHANGELOG.md +++ b/packages/signature-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New messenger actions: `SignatureControllerResetStateAction`, `SignatureControllerRejectUnapprovedAction`, `SignatureControllerClearUnapprovedAction`, `SignatureControllerNewUnsignedPersonalMessageAction`, `SignatureControllerNewUnsignedTypedMessageAction`, `SignatureControllerSetDeferredSignSuccessAction`, `SignatureControllerSetMessageMetadataAction`, `SignatureControllerSetDeferredSignErrorAction`, `SignatureControllerSetTypedMessageInProgressAction`, `SignatureControllerSetPersonalMessageInProgressAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + ### Changed - Bump `@metamask/gator-permissions-controller` from `^2.0.0` to `^2.1.0` ([#8156](https://github.com/MetaMask/core/pull/8156)) diff --git a/packages/signature-controller/package.json b/packages/signature-controller/package.json index d3581bb72cc..bd8a0fcfb7c 100644 --- a/packages/signature-controller/package.json +++ b/packages/signature-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/signature-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/signature-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", @@ -69,6 +70,7 @@ "deepmerge": "^4.2.2", "jest": "^29.7.0", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/signature-controller/src/SignatureController-method-action-types.ts b/packages/signature-controller/src/SignatureController-method-action-types.ts new file mode 100644 index 00000000000..3c1676c0921 --- /dev/null +++ b/packages/signature-controller/src/SignatureController-method-action-types.ts @@ -0,0 +1,132 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { SignatureController } from './SignatureController'; + +/** + * Reset the controller state to the initial state. + */ +export type SignatureControllerResetStateAction = { + type: `SignatureController:resetState`; + handler: SignatureController['resetState']; +}; + +/** + * Reject all unapproved messages of any type. + * + * @param reason - A message to indicate why. + */ +export type SignatureControllerRejectUnapprovedAction = { + type: `SignatureController:rejectUnapproved`; + handler: SignatureController['rejectUnapproved']; +}; + +/** + * Clears all unapproved messages from memory. + */ +export type SignatureControllerClearUnapprovedAction = { + type: `SignatureController:clearUnapproved`; + handler: SignatureController['clearUnapproved']; +}; + +/** + * Called when a dApp uses the personal_sign method. + * We currently provide personal_sign mostly for legacy dApps. + * + * @param messageParams - The params of the message to sign and return to the dApp. + * @param request - The original request, containing the origin. + * @param options - An options bag for the method. + * @param options.traceContext - The parent context for any new traces. + * @returns Promise resolving to the raw signature hash generated from the signature request. + */ +export type SignatureControllerNewUnsignedPersonalMessageAction = { + type: `SignatureController:newUnsignedPersonalMessage`; + handler: SignatureController['newUnsignedPersonalMessage']; +}; + +/** + * Called when a dapp uses the eth_signTypedData method, per EIP-712. + * + * @param messageParams - The params of the message to sign and return to the dApp. + * @param request - The original request, containing the origin. + * @param versionString - The version of the signTypedData request. + * @param signingOptions - Options for signing the typed message. + * @param options - An options bag for the method. + * @param options.traceContext - The parent context for any new traces. + * @returns Promise resolving to the raw signature hash generated from the signature request. + */ +export type SignatureControllerNewUnsignedTypedMessageAction = { + type: `SignatureController:newUnsignedTypedMessage`; + handler: SignatureController['newUnsignedTypedMessage']; +}; + +/** + * Provide a signature for a pending signature request that used `deferSetAsSigned`. + * Changes the status of the signature request to `signed`. + * + * @param signatureRequestId - The ID of the signature request. + * @param signature - The signature to provide. + */ +export type SignatureControllerSetDeferredSignSuccessAction = { + type: `SignatureController:setDeferredSignSuccess`; + handler: SignatureController['setDeferredSignSuccess']; +}; + +/** + * Set custom metadata on a signature request. + * + * @param signatureRequestId - The ID of the signature request. + * @param metadata - The custom metadata to set. + */ +export type SignatureControllerSetMessageMetadataAction = { + type: `SignatureController:setMessageMetadata`; + handler: SignatureController['setMessageMetadata']; +}; + +/** + * Reject a pending signature request that used `deferSetAsSigned`. + * Changes the status of the signature request to `rejected`. + * + * @param signatureRequestId - The ID of the signature request. + */ +export type SignatureControllerSetDeferredSignErrorAction = { + type: `SignatureController:setDeferredSignError`; + handler: SignatureController['setDeferredSignError']; +}; + +/** + * Set the status of a signature request to 'inProgress'. + * + * @param signatureRequestId - The ID of the signature request. + */ +export type SignatureControllerSetTypedMessageInProgressAction = { + type: `SignatureController:setTypedMessageInProgress`; + handler: SignatureController['setTypedMessageInProgress']; +}; + +/** + * Set the status of a signature request to 'inProgress'. + * + * @param signatureRequestId - The ID of the signature request. + */ +export type SignatureControllerSetPersonalMessageInProgressAction = { + type: `SignatureController:setPersonalMessageInProgress`; + handler: SignatureController['setPersonalMessageInProgress']; +}; + +/** + * Union of all SignatureController action types. + */ +export type SignatureControllerMethodActions = + | SignatureControllerResetStateAction + | SignatureControllerRejectUnapprovedAction + | SignatureControllerClearUnapprovedAction + | SignatureControllerNewUnsignedPersonalMessageAction + | SignatureControllerNewUnsignedTypedMessageAction + | SignatureControllerSetDeferredSignSuccessAction + | SignatureControllerSetMessageMetadataAction + | SignatureControllerSetDeferredSignErrorAction + | SignatureControllerSetTypedMessageInProgressAction + | SignatureControllerSetPersonalMessageInProgressAction; diff --git a/packages/signature-controller/src/SignatureController.test.ts b/packages/signature-controller/src/SignatureController.test.ts index e90100117f1..83ab7e654df 100644 --- a/packages/signature-controller/src/SignatureController.test.ts +++ b/packages/signature-controller/src/SignatureController.test.ts @@ -148,6 +148,7 @@ function createMessengerMock() { const messenger = { registerActionHandler: jest.fn(), + registerMethodActionHandlers: jest.fn(), registerInitialEventPayload: jest.fn(), publish: jest.fn(), call: callMock, diff --git a/packages/signature-controller/src/SignatureController.ts b/packages/signature-controller/src/SignatureController.ts index 9dc134e34a0..a3c0da366d7 100644 --- a/packages/signature-controller/src/SignatureController.ts +++ b/packages/signature-controller/src/SignatureController.ts @@ -1,6 +1,6 @@ import type { AccountsControllerGetStateAction } from '@metamask/accounts-controller'; import type { - AddApprovalRequest, + ApprovalControllerAddRequestAction as AddApprovalRequest, AcceptResultCallbacks, AddResult, } from '@metamask/approval-controller'; @@ -30,7 +30,7 @@ import { LogType, SigningStage, } from '@metamask/logging-controller'; -import type { AddLog } from '@metamask/logging-controller'; +import type { LoggingControllerAddAction } from '@metamask/logging-controller'; import type { Messenger } from '@metamask/messenger'; import type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller'; import type { Hex, Json } from '@metamask/utils'; @@ -40,6 +40,7 @@ import EventEmitter from 'events'; import { v1 as random } from 'uuid'; import { projectLogger as log } from './logger'; +import type { SignatureControllerMethodActions } from './SignatureController-method-action-types'; import { SignatureRequestStatus, SignatureRequestType } from './types'; import type { MessageParamsPersonal, @@ -69,6 +70,19 @@ import { const controllerName = 'SignatureController'; +const MESSENGER_EXPOSED_METHODS = [ + 'resetState', + 'rejectUnapproved', + 'clearUnapproved', + 'newUnsignedPersonalMessage', + 'newUnsignedTypedMessage', + 'setDeferredSignSuccess', + 'setMessageMetadata', + 'setDeferredSignError', + 'setTypedMessageInProgress', + 'setPersonalMessageInProgress', +] as const; + const stateMetadata = { signatureRequests: { includeInStateLogs: true, @@ -155,7 +169,7 @@ export type SignatureControllerState = { type AllowedActions = | AccountsControllerGetStateAction | AddApprovalRequest - | AddLog + | LoggingControllerAddAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | NetworkControllerGetNetworkClientByIdAction | KeyringControllerSignMessageAction @@ -172,7 +186,9 @@ export type SignatureStateChange = ControllerStateChangeEvent< SignatureControllerState >; -export type SignatureControllerActions = GetSignatureState; +export type SignatureControllerActions = + | GetSignatureState + | SignatureControllerMethodActions; export type SignatureControllerEvents = SignatureStateChange; @@ -263,6 +279,12 @@ export class SignatureController extends BaseController< }); this.hub = new EventEmitter(); + + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, + ); + this.#trace = trace ?? (((_request, fn) => fn?.()) as TraceCallback); this.#decodingApiUrl = decodingApiUrl; this.#isDecodeSignatureRequestEnabled = isDecodeSignatureRequestEnabled; diff --git a/packages/signature-controller/src/index.ts b/packages/signature-controller/src/index.ts index 739421c4be2..82447289f46 100644 --- a/packages/signature-controller/src/index.ts +++ b/packages/signature-controller/src/index.ts @@ -1,2 +1,14 @@ export * from './SignatureController'; +export type { + SignatureControllerResetStateAction, + SignatureControllerRejectUnapprovedAction, + SignatureControllerClearUnapprovedAction, + SignatureControllerNewUnsignedPersonalMessageAction, + SignatureControllerNewUnsignedTypedMessageAction, + SignatureControllerSetDeferredSignSuccessAction, + SignatureControllerSetMessageMetadataAction, + SignatureControllerSetDeferredSignErrorAction, + SignatureControllerSetTypedMessageInProgressAction, + SignatureControllerSetPersonalMessageInProgressAction, +} from './SignatureController-method-action-types'; export * from './types'; diff --git a/packages/transaction-controller/CHANGELOG.md b/packages/transaction-controller/CHANGELOG.md index 3496ae5b8c1..c40e14a73b0 100644 --- a/packages/transaction-controller/CHANGELOG.md +++ b/packages/transaction-controller/CHANGELOG.md @@ -11,9 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add optional `sourceHash` field to `MetamaskPayMetadata` for tracking source chain transaction hashes when no local transaction exists ([#8133](https://github.com/MetaMask/core/pull/8133)) - Add `predictDepositAndOrder` to `TransactionType` ([#8135](https://github.com/MetaMask/core/pull/8135)) +- New public `getGasFeeTokens()` method ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger actions: `TransactionControllerHandleMethodDataAction`, `TransactionControllerIsAtomicBatchSupportedAction`, `TransactionControllerStartIncomingTransactionPollingAction`, `TransactionControllerStopIncomingTransactionPollingAction`, `TransactionControllerUpdateIncomingTransactionsAction`, `TransactionControllerStopTransactionAction`, `TransactionControllerSpeedUpTransactionAction`, `TransactionControllerEstimateGasBufferedAction`, `TransactionControllerUpdateEditableParamsAction`, `TransactionControllerSetTransactionActiveAction`, `TransactionControllerApproveTransactionsWithSameNonceAction`, `TransactionControllerEstimateGasFeeAction`, `TransactionControllerGetLayer1GasFeeAction`, `TransactionControllerClearUnapprovedTransactionsAction`, `TransactionControllerAbortTransactionSigningAction`, `TransactionControllerUpdateAtomicBatchDataAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) ### Changed +- **BREAKING:** Action type names standardized with `Action` suffix (e.g. `TransactionControllerEmulateNewTransaction` → `TransactionControllerEmulateNewTransactionAction`) ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) - Bump `@metamask/core-backend` from `^6.1.0` to `^6.1.1` ([#8162](https://github.com/MetaMask/core/pull/8162)) ### Fixed diff --git a/packages/transaction-controller/package.json b/packages/transaction-controller/package.json index 07e73ea040d..badb43b0bfc 100644 --- a/packages/transaction-controller/package.json +++ b/packages/transaction-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/transaction-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/transaction-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache", @@ -92,6 +93,7 @@ "jest-environment-jsdom": "^29.7.0", "nock": "^13.3.1", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/transaction-controller/src/TransactionController-method-action-types.ts b/packages/transaction-controller/src/TransactionController-method-action-types.ts new file mode 100644 index 00000000000..ed29b5f3057 --- /dev/null +++ b/packages/transaction-controller/src/TransactionController-method-action-types.ts @@ -0,0 +1,384 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { TransactionController } from './TransactionController'; + +/** + * Handle new method data request. + * + * @param fourBytePrefix - The method prefix. + * @param networkClientId - The ID of the network client used to fetch the method data. + * @returns The method data object corresponding to the given signature prefix. + */ +export type TransactionControllerHandleMethodDataAction = { + type: `TransactionController:handleMethodData`; + handler: TransactionController['handleMethodData']; +}; + +/** + * Add a batch of transactions to be submitted after approval. + * + * @param request - Request object containing the transactions to add. + * @returns Result object containing the generated batch ID. + */ +export type TransactionControllerAddTransactionBatchAction = { + type: `TransactionController:addTransactionBatch`; + handler: TransactionController['addTransactionBatch']; +}; + +/** + * Determine which chains support atomic batch transactions with the given account address. + * + * @param request - Request object containing the account address and other parameters. + * @returns Result object containing the supported chains and related information. + */ +export type TransactionControllerIsAtomicBatchSupportedAction = { + type: `TransactionController:isAtomicBatchSupported`; + handler: TransactionController['isAtomicBatchSupported']; +}; + +/** + * Add a new unapproved transaction to state. Parameters will be validated, a + * unique transaction ID will be generated, and `gas` and `gasPrice` will be calculated + * if not provided. A `:unapproved` hub event will be emitted once added. + * + * @param txParams - Standard parameters for an Ethereum transaction. + * @param options - Additional options to control how the transaction is added. + * @returns Object containing a promise resolving to the transaction hash if approved. + */ +export type TransactionControllerAddTransactionAction = { + type: `TransactionController:addTransaction`; + handler: TransactionController['addTransaction']; +}; + +/** + * Starts polling for incoming transactions from the remote transaction source. + */ +export type TransactionControllerStartIncomingTransactionPollingAction = { + type: `TransactionController:startIncomingTransactionPolling`; + handler: TransactionController['startIncomingTransactionPolling']; +}; + +/** + * Stops polling for incoming transactions from the remote transaction source. + */ +export type TransactionControllerStopIncomingTransactionPollingAction = { + type: `TransactionController:stopIncomingTransactionPolling`; + handler: TransactionController['stopIncomingTransactionPolling']; +}; + +/** + * Update the incoming transactions by polling the remote transaction source. + * + * @param request - Request object. + * @param request.tags - Additional tags to identify the source of the request. + */ +export type TransactionControllerUpdateIncomingTransactionsAction = { + type: `TransactionController:updateIncomingTransactions`; + handler: TransactionController['updateIncomingTransactions']; +}; + +/** + * Attempts to cancel a transaction based on its ID by setting its status to "rejected" + * and emitting a `:finished` hub event. + * + * @param transactionId - The ID of the transaction to cancel. + * @param gasValues - The gas values to use for the cancellation transaction. + * @param options - The options for the cancellation transaction. + * @param options.actionId - Unique ID to prevent duplicate requests. + * @param options.estimatedBaseFee - The estimated base fee of the transaction. + */ +export type TransactionControllerStopTransactionAction = { + type: `TransactionController:stopTransaction`; + handler: TransactionController['stopTransaction']; +}; + +/** + * Attempts to speed up a transaction increasing transaction gasPrice by ten percent. + * + * @param transactionId - The ID of the transaction to speed up. + * @param gasValues - The gas values to use for the speed up transaction. + * @param options - The options for the speed up transaction. + * @param options.actionId - Unique ID to prevent duplicate requests + * @param options.estimatedBaseFee - The estimated base fee of the transaction. + */ +export type TransactionControllerSpeedUpTransactionAction = { + type: `TransactionController:speedUpTransaction`; + handler: TransactionController['speedUpTransaction']; +}; + +/** + * Estimates required gas for a given transaction. + * + * @param transaction - The transaction to estimate gas for. + * @param networkClientId - The network client id to use for the estimate. + * @param options - Additional options for the estimate. + * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager. + * @returns The gas and gas price. + */ +export type TransactionControllerEstimateGasAction = { + type: `TransactionController:estimateGas`; + handler: TransactionController['estimateGas']; +}; + +/** + * Estimates required gas for a batch of transactions. + * + * @param request - Request object. + * @param request.chainId - Chain ID of the transactions. + * @param request.from - Address of the sender. + * @param request.transactions - Array of transactions within a batch request. + * @returns Object containing the gas limit. + */ +export type TransactionControllerEstimateGasBatchAction = { + type: `TransactionController:estimateGasBatch`; + handler: TransactionController['estimateGasBatch']; +}; + +/** + * Estimates required gas for a given transaction and add additional gas buffer with the given multiplier. + * + * @param transaction - The transaction params to estimate gas for. + * @param multiplier - The multiplier to use for the gas buffer. + * @param networkClientId - The network client id to use for the estimate. + * @returns The buffered estimated gas and whether the estimation failed. + */ +export type TransactionControllerEstimateGasBufferedAction = { + type: `TransactionController:estimateGasBuffered`; + handler: TransactionController['estimateGasBuffered']; +}; + +/** + * Updates an existing transaction in state. + * + * @param transactionMeta - The new transaction to store in state. + * @param note - A note or update reason to be logged. + */ +export type TransactionControllerUpdateTransactionAction = { + type: `TransactionController:updateTransaction`; + handler: TransactionController['updateTransaction']; +}; + +/** + * Adds external provided transaction to state as confirmed transaction. + * + * @param transactionMeta - TransactionMeta to add transactions. + * @param transactionReceipt - TransactionReceipt of the external transaction. + * @param baseFeePerGas - Base fee per gas of the external transaction. + */ +export type TransactionControllerConfirmExternalTransactionAction = { + type: `TransactionController:confirmExternalTransaction`; + handler: TransactionController['confirmExternalTransaction']; +}; + +/** + * Acquires a nonce lock for the given address on the specified network, + * ensuring that nonces are assigned sequentially without conflicts. + * + * @param address - The account address for which to acquire the nonce lock. + * @param networkClientId - The ID of the network client to use. + * @returns A promise that resolves to a nonce lock containing the next nonce and a release function. + */ +export type TransactionControllerGetNonceLockAction = { + type: `TransactionController:getNonceLock`; + handler: TransactionController['getNonceLock']; +}; + +/** + * Updates the editable parameters of a transaction. + * + * @param txId - The ID of the transaction to update. + * @param params - The editable parameters to update. + * @param params.containerTypes - Container types applied to the parameters. + * @param params.data - Data to pass with the transaction. + * @param params.from - Address to send the transaction from. + * @param params.gas - Maximum number of units of gas to use for the transaction. + * @param params.gasPrice - Price per gas for legacy transactions. + * @param params.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee. + * @param params.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive. + * @param params.updateType - Whether to update the transaction type. Defaults to `true`. + * @param params.to - Address to send the transaction to. + * @param params.value - Value associated with the transaction. + * @returns The updated transaction metadata. + */ +export type TransactionControllerUpdateEditableParamsAction = { + type: `TransactionController:updateEditableParams`; + handler: TransactionController['updateEditableParams']; +}; + +/** + * Update the isActive state of a transaction. + * + * @param transactionId - The ID of the transaction to update. + * @param isActive - The active state. + */ +export type TransactionControllerSetTransactionActiveAction = { + type: `TransactionController:setTransactionActive`; + handler: TransactionController['setTransactionActive']; +}; + +/** + * Signs and returns the raw transaction data for provided transaction params list. + * + * @param listOfTxParams - The list of transaction params to approve. + * @param opts - Options bag. + * @param opts.hasNonce - Whether the transactions already have a nonce. + * @returns The raw transactions. + */ +export type TransactionControllerApproveTransactionsWithSameNonceAction = { + type: `TransactionController:approveTransactionsWithSameNonce`; + handler: TransactionController['approveTransactionsWithSameNonce']; +}; + +/** + * Update a custodial transaction. + * + * @param request - The custodial transaction update request. + * + * @returns The updated transaction metadata. + */ +export type TransactionControllerUpdateCustodialTransactionAction = { + type: `TransactionController:updateCustodialTransaction`; + handler: TransactionController['updateCustodialTransaction']; +}; + +/** + * Search transaction metadata for matching entries. + * + * @param opts - Options bag. + * @param opts.initialList - The transactions to search. Defaults to the current state. + * @param opts.limit - The maximum number of transactions to return. No limit by default. + * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with. + * @returns An array of transactions matching the provided options. + */ +export type TransactionControllerGetTransactionsAction = { + type: `TransactionController:getTransactions`; + handler: TransactionController['getTransactions']; +}; + +/** + * Estimates the gas fees for a transaction. + * + * @param args - The arguments for estimating gas fees. + * @param args.transactionParams - The transaction parameters to estimate fees for. + * @param args.chainId - The chain ID to use. If not provided, the network client ID is used to determine the chain. + * @param args.networkClientId - The network client ID to use for the estimation. + * @returns A promise that resolves to the estimated gas fee response. + */ +export type TransactionControllerEstimateGasFeeAction = { + type: `TransactionController:estimateGasFee`; + handler: TransactionController['estimateGasFee']; +}; + +/** + * Determine the layer 1 gas fee for the given transaction parameters. + * + * @param request - The request object. + * @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for. + * @param request.chainId - The ID of the chain where the transaction will be executed. + * @param request.networkClientId - The ID of a specific network client to process the transaction. + * @returns The layer 1 gas fee. + */ +export type TransactionControllerGetLayer1GasFeeAction = { + type: `TransactionController:getLayer1GasFee`; + handler: TransactionController['getLayer1GasFee']; +}; + +/** + * Retrieve available gas fee tokens for a transaction. + * + * @param request - The request object containing transaction details. + * @returns The list of available gas fee tokens. + */ +export type TransactionControllerGetGasFeeTokensAction = { + type: `TransactionController:getGasFeeTokens`; + handler: TransactionController['getGasFeeTokens']; +}; + +/** + * Removes unapproved transactions from state. + */ +export type TransactionControllerClearUnapprovedTransactionsAction = { + type: `TransactionController:clearUnapprovedTransactions`; + handler: TransactionController['clearUnapprovedTransactions']; +}; + +/** + * Stop the signing process for a specific transaction. + * Throws an error causing the transaction status to be set to failed. + * + * @param transactionId - The ID of the transaction to stop signing. + */ +export type TransactionControllerAbortTransactionSigningAction = { + type: `TransactionController:abortTransactionSigning`; + handler: TransactionController['abortTransactionSigning']; +}; + +/** + * Update the transaction data of a single nested transaction within an atomic batch transaction. + * + * @param options - The options bag. + * @param options.transactionId - ID of the atomic batch transaction. + * @param options.transactionIndex - Index of the nested transaction within the atomic batch transaction. + * @param options.transactionData - New data to set for the nested transaction. + * @returns The updated data for the atomic batch transaction. + */ +export type TransactionControllerUpdateAtomicBatchDataAction = { + type: `TransactionController:updateAtomicBatchData`; + handler: TransactionController['updateAtomicBatchData']; +}; + +/** + * Emulate a new transaction. + * + * @param transactionId - The transaction ID. + */ +export type TransactionControllerEmulateNewTransactionAction = { + type: `TransactionController:emulateNewTransaction`; + handler: TransactionController['emulateNewTransaction']; +}; + +/** + * Emulate a transaction update. + * + * @param transactionMeta - Transaction metadata. + */ +export type TransactionControllerEmulateTransactionUpdateAction = { + type: `TransactionController:emulateTransactionUpdate`; + handler: TransactionController['emulateTransactionUpdate']; +}; + +/** + * Union of all TransactionController action types. + */ +export type TransactionControllerMethodActions = + | TransactionControllerHandleMethodDataAction + | TransactionControllerAddTransactionBatchAction + | TransactionControllerIsAtomicBatchSupportedAction + | TransactionControllerAddTransactionAction + | TransactionControllerStartIncomingTransactionPollingAction + | TransactionControllerStopIncomingTransactionPollingAction + | TransactionControllerUpdateIncomingTransactionsAction + | TransactionControllerStopTransactionAction + | TransactionControllerSpeedUpTransactionAction + | TransactionControllerEstimateGasAction + | TransactionControllerEstimateGasBatchAction + | TransactionControllerEstimateGasBufferedAction + | TransactionControllerUpdateTransactionAction + | TransactionControllerConfirmExternalTransactionAction + | TransactionControllerGetNonceLockAction + | TransactionControllerUpdateEditableParamsAction + | TransactionControllerSetTransactionActiveAction + | TransactionControllerApproveTransactionsWithSameNonceAction + | TransactionControllerUpdateCustodialTransactionAction + | TransactionControllerGetTransactionsAction + | TransactionControllerEstimateGasFeeAction + | TransactionControllerGetLayer1GasFeeAction + | TransactionControllerGetGasFeeTokensAction + | TransactionControllerClearUnapprovedTransactionsAction + | TransactionControllerAbortTransactionSigningAction + | TransactionControllerUpdateAtomicBatchDataAction + | TransactionControllerEmulateNewTransactionAction + | TransactionControllerEmulateTransactionUpdateAction; diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index 60d53ad977c..c31f51a41ab 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -5,7 +5,7 @@ import { TransactionFactory } from '@ethereumjs/tx'; import type { - AddApprovalRequest, + ApprovalControllerAddRequestAction as AddApprovalRequest, AddResult, } from '@metamask/approval-controller'; import { deriveStateFromMetadata } from '@metamask/base-controller'; diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index cc6e47cb5e2..2b9f7011a26 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -7,7 +7,7 @@ import type { } from '@metamask/accounts-controller'; import type { AcceptResultCallbacks, - AddApprovalRequest, + ApprovalControllerAddRequestAction as AddApprovalRequest, AddResult, } from '@metamask/approval-controller'; import type { @@ -91,6 +91,7 @@ import { } from './helpers/ResimulateHelper'; import { ExtraTransactionsPublishHook } from './hooks/ExtraTransactionsPublishHook'; import { projectLogger as log } from './logger'; +import type { TransactionControllerMethodActions } from './TransactionController-method-action-types'; import type { DappSuggestedGasFees, Layer1GasFeeFlow, @@ -307,123 +308,12 @@ export type TransactionControllerGetStateAction = ControllerGetStateAction< TransactionControllerState >; -/** - * Represents the `TransactionController:updateCustodialTransaction` action. - */ -export type TransactionControllerUpdateCustodialTransactionAction = { - type: `${typeof controllerName}:updateCustodialTransaction`; - handler: TransactionController['updateCustodialTransaction']; -}; - -export type TransactionControllerEstimateGasAction = { - type: `${typeof controllerName}:estimateGas`; - handler: TransactionController['estimateGas']; -}; - -export type TransactionControllerEstimateGasBatchAction = { - type: `${typeof controllerName}:estimateGasBatch`; - handler: TransactionController['estimateGasBatch']; -}; - -/** - * Adds external provided transaction to state as confirmed transaction. - * - * @param transactionMeta - TransactionMeta to add transactions. - * @param transactionReceipt - TransactionReceipt of the external transaction. - * @param baseFeePerGas - Base fee per gas of the external transaction. - */ -export type TransactionControllerConfirmExternalTransactionAction = { - type: `${typeof controllerName}:confirmExternalTransaction`; - handler: TransactionController['confirmExternalTransaction']; -}; - -export type TransactionControllerGetNonceLockAction = { - type: `${typeof controllerName}:getNonceLock`; - handler: TransactionController['getNonceLock']; -}; - -/** - * Search transaction metadata for matching entries. - * - * @param opts - Options bag. - * @param opts.initialList - The transactions to search. Defaults to the current state. - * @param opts.limit - The maximum number of transactions to return. No limit by default. - * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with. - * @returns An array of transactions matching the provided options. - */ -export type TransactionControllerGetTransactionsAction = { - type: `${typeof controllerName}:getTransactions`; - handler: TransactionController['getTransactions']; -}; - -/** - * Updates an existing transaction in state. - * - * @param transactionMeta - The new transaction to store in state. - * @param note - A note or update reason to be logged. - */ -export type TransactionControllerUpdateTransactionAction = { - type: `${typeof controllerName}:updateTransaction`; - handler: TransactionController['updateTransaction']; -}; - -/** Add a single transaction to be submitted after approval. */ -export type TransactionControllerAddTransactionAction = { - type: `${typeof controllerName}:addTransaction`; - handler: TransactionController['addTransaction']; -}; - -/** Add a batch of transactions to be submitted after approval. */ -export type TransactionControllerAddTransactionBatchAction = { - type: `${typeof controllerName}:addTransactionBatch`; - handler: TransactionController['addTransactionBatch']; -}; - -/** - * Emulate a new transaction. - * - * @param transactionId - The transaction ID. - */ -export type TransactionControllerEmulateNewTransaction = { - type: `${typeof controllerName}:emulateNewTransaction`; - handler: TransactionController['emulateNewTransaction']; -}; - -/** - * Emmulate a transaction update. - * - * @param transactionMeta - Transaction metadata. - */ -export type TransactionControllerEmulateTransactionUpdate = { - type: `${typeof controllerName}:emulateTransactionUpdate`; - handler: TransactionController['emulateTransactionUpdate']; -}; - -/** - * Retrieve available gas fee tokens for a transaction. - */ -export type TransactionControllerGetGasFeeTokensAction = { - type: `${typeof controllerName}:getGasFeeTokens`; - handler: (request: GetGasFeeTokensRequest) => Promise; -}; - /** * The internal actions available to the TransactionController. */ export type TransactionControllerActions = - | TransactionControllerAddTransactionAction - | TransactionControllerAddTransactionBatchAction - | TransactionControllerConfirmExternalTransactionAction - | TransactionControllerEstimateGasAction - | TransactionControllerEstimateGasBatchAction - | TransactionControllerGetGasFeeTokensAction - | TransactionControllerGetNonceLockAction | TransactionControllerGetStateAction - | TransactionControllerGetTransactionsAction - | TransactionControllerUpdateCustodialTransactionAction - | TransactionControllerUpdateTransactionAction - | TransactionControllerEmulateNewTransaction - | TransactionControllerEmulateTransactionUpdate; + | TransactionControllerMethodActions; /** * Configuration options for the PendingTransactionTracker @@ -837,6 +727,39 @@ function getDefaultTransactionControllerState(): TransactionControllerState { }; } +// === MESSENGER === + +const MESSENGER_EXPOSED_METHODS = [ + 'addTransaction', + 'addTransactionBatch', + 'confirmExternalTransaction', + 'emulateNewTransaction', + 'emulateTransactionUpdate', + 'estimateGas', + 'estimateGasBatch', + 'getGasFeeTokens', + 'getNonceLock', + 'getTransactions', + 'updateCustodialTransaction', + 'updateTransaction', + 'handleMethodData', + 'isAtomicBatchSupported', + 'startIncomingTransactionPolling', + 'stopIncomingTransactionPolling', + 'updateIncomingTransactions', + 'stopTransaction', + 'speedUpTransaction', + 'estimateGasBuffered', + 'updateEditableParams', + 'setTransactionActive', + 'approveTransactionsWithSameNonce', + 'estimateGasFee', + 'getLayer1GasFee', + 'clearUnapprovedTransactions', + 'abortTransactionSigning', + 'updateAtomicBatchData', +] as const; + /** * Controller responsible for submitting and managing transactions. */ @@ -1532,10 +1455,16 @@ export class TransactionController extends BaseController< }; } + /** + * Starts polling for incoming transactions from the remote transaction source. + */ startIncomingTransactionPolling(): void { this.#incomingTransactionHelper.start(); } + /** + * Stops polling for incoming transactions from the remote transaction source. + */ stopIncomingTransactionPolling(): void { this.#incomingTransactionHelper.stop(); } @@ -2212,6 +2141,14 @@ export class TransactionController extends BaseController< return this.#getTransaction(transactionId) as TransactionMeta; } + /** + * Acquires a nonce lock for the given address on the specified network, + * ensuring that nonces are assigned sequentially without conflicts. + * + * @param address - The account address for which to acquire the nonce lock. + * @param networkClientId - The ID of the network client to use. + * @returns A promise that resolves to a nonce lock containing the next nonce and a release function. + */ async getNonceLock( address: string, networkClientId: NetworkClientId, @@ -2614,6 +2551,15 @@ export class TransactionController extends BaseController< return filteredTransactions; } + /** + * Estimates the gas fees for a transaction. + * + * @param args - The arguments for estimating gas fees. + * @param args.transactionParams - The transaction parameters to estimate fees for. + * @param args.chainId - The chain ID to use. If not provided, the network client ID is used to determine the chain. + * @param args.networkClientId - The network client ID to use for the estimation. + * @returns A promise that resolves to the estimated gas fee response. + */ async estimateGasFee({ transactionParams, chainId, @@ -2690,6 +2636,18 @@ export class TransactionController extends BaseController< }); } + /** + * Retrieve available gas fee tokens for a transaction. + * + * @param request - The request object containing transaction details. + * @returns The list of available gas fee tokens. + */ + async getGasFeeTokens( + request: GetGasFeeTokensRequest, + ): Promise { + return this.#getGasFeeTokensAction(request); + } + async #signExternalTransaction( chainId: Hex, transactionParams: TransactionParams, @@ -4598,64 +4556,9 @@ export class TransactionController extends BaseController< } #registerActionHandlers(): void { - this.messenger.registerActionHandler( - `${controllerName}:addTransaction`, - this.addTransaction.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:addTransactionBatch`, - this.addTransactionBatch.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:confirmExternalTransaction`, - this.confirmExternalTransaction.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:emulateNewTransaction`, - this.emulateNewTransaction.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:emulateTransactionUpdate`, - this.emulateTransactionUpdate.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:estimateGas`, - this.estimateGas.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:estimateGasBatch`, - this.estimateGasBatch.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:getGasFeeTokens`, - this.#getGasFeeTokensAction.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:getNonceLock`, - this.getNonceLock.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:getTransactions`, - this.getTransactions.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:updateCustodialTransaction`, - this.updateCustodialTransaction.bind(this), - ); - - this.messenger.registerActionHandler( - `${controllerName}:updateTransaction`, - this.updateTransaction.bind(this), + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, ); } diff --git a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts index 4fa61e6e7c2..768878546a5 100644 --- a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts +++ b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts @@ -535,7 +535,7 @@ describe('TransactionController Integration', () => { { networkClientId: 'sepolia' }, ); - await approvalController.accept(transactionMeta.id); + await approvalController.acceptRequest(transactionMeta.id); await jestAdvanceTime({ duration: 1 }); await result; @@ -580,7 +580,7 @@ describe('TransactionController Integration', () => { { networkClientId: 'sepolia' }, ); - await approvalController.accept(transactionMeta.id); + await approvalController.acceptRequest(transactionMeta.id); await jestAdvanceTime({ duration: 1 }); await result; @@ -657,8 +657,10 @@ describe('TransactionController Integration', () => { ); await Promise.all([ - approvalController.accept(firstTransaction.transactionMeta.id), - approvalController.accept(secondTransaction.transactionMeta.id), + approvalController.acceptRequest(firstTransaction.transactionMeta.id), + approvalController.acceptRequest( + secondTransaction.transactionMeta.id, + ), ]); await jestAdvanceTime({ duration: 1 }); await jestAdvanceTime({ duration: 1 }); @@ -725,7 +727,7 @@ describe('TransactionController Integration', () => { { networkClientId: 'sepolia' }, ); - await approvalController.accept(transactionMeta.id); + await approvalController.acceptRequest(transactionMeta.id); await jestAdvanceTime({ duration: 1 }); await result; @@ -790,7 +792,7 @@ describe('TransactionController Integration', () => { { networkClientId: 'sepolia' }, ); - await approvalController.accept(transactionMeta.id); + await approvalController.acceptRequest(transactionMeta.id); await jestAdvanceTime({ duration: 1 }); await result; @@ -867,7 +869,7 @@ describe('TransactionController Integration', () => { { networkClientId: 'sepolia' }, ); - await approvalController.accept(transactionMeta.id); + await approvalController.acceptRequest(transactionMeta.id); await jestAdvanceTime({ duration: 1 }); await result; @@ -1010,8 +1012,8 @@ describe('TransactionController Integration', () => { ); await Promise.all([ - approvalController.accept(addTx1.transactionMeta.id), - approvalController.accept(addTx2.transactionMeta.id), + approvalController.acceptRequest(addTx1.transactionMeta.id), + approvalController.acceptRequest(addTx2.transactionMeta.id), ]); await jestAdvanceTime({ duration: 1 }); await jestAdvanceTime({ duration: 1 }); @@ -1087,8 +1089,8 @@ describe('TransactionController Integration', () => { await jestAdvanceTime({ duration: 1 }); await Promise.all([ - approvalController.accept(addTx1.transactionMeta.id), - approvalController.accept(addTx2.transactionMeta.id), + approvalController.acceptRequest(addTx1.transactionMeta.id), + approvalController.acceptRequest(addTx2.transactionMeta.id), ]); await jestAdvanceTime({ duration: 1 }); diff --git a/packages/transaction-controller/src/index.ts b/packages/transaction-controller/src/index.ts index fe1dc7ad587..2c453180533 100644 --- a/packages/transaction-controller/src/index.ts +++ b/packages/transaction-controller/src/index.ts @@ -2,18 +2,8 @@ export type { MethodData, Result, TransactionControllerActions, - TransactionControllerAddTransactionAction, - TransactionControllerAddTransactionBatchAction, - TransactionControllerConfirmExternalTransactionAction, - TransactionControllerEmulateNewTransaction, - TransactionControllerEmulateTransactionUpdate, TransactionControllerEvents, - TransactionControllerEstimateGasAction, - TransactionControllerEstimateGasBatchAction, - TransactionControllerGetGasFeeTokensAction, - TransactionControllerGetNonceLockAction, TransactionControllerGetStateAction, - TransactionControllerGetTransactionsAction, TransactionControllerIncomingTransactionsReceivedEvent, TransactionControllerPostTransactionBalanceUpdatedEvent, TransactionControllerSpeedupTransactionAddedEvent, @@ -31,11 +21,39 @@ export type { TransactionControllerTransactionStatusUpdatedEvent, TransactionControllerTransactionSubmittedEvent, TransactionControllerUnapprovedTransactionAddedEvent, - TransactionControllerUpdateCustodialTransactionAction, - TransactionControllerUpdateTransactionAction, TransactionControllerMessenger, TransactionControllerOptions, } from './TransactionController'; +export type { + TransactionControllerAddTransactionAction, + TransactionControllerAddTransactionBatchAction, + TransactionControllerConfirmExternalTransactionAction, + TransactionControllerEmulateNewTransactionAction, + TransactionControllerEmulateTransactionUpdateAction, + TransactionControllerEstimateGasAction, + TransactionControllerEstimateGasBatchAction, + TransactionControllerGetGasFeeTokensAction, + TransactionControllerGetNonceLockAction, + TransactionControllerGetTransactionsAction, + TransactionControllerUpdateCustodialTransactionAction, + TransactionControllerUpdateTransactionAction, + TransactionControllerHandleMethodDataAction, + TransactionControllerIsAtomicBatchSupportedAction, + TransactionControllerStartIncomingTransactionPollingAction, + TransactionControllerStopIncomingTransactionPollingAction, + TransactionControllerUpdateIncomingTransactionsAction, + TransactionControllerStopTransactionAction, + TransactionControllerSpeedUpTransactionAction, + TransactionControllerEstimateGasBufferedAction, + TransactionControllerUpdateEditableParamsAction, + TransactionControllerSetTransactionActiveAction, + TransactionControllerApproveTransactionsWithSameNonceAction, + TransactionControllerEstimateGasFeeAction, + TransactionControllerGetLayer1GasFeeAction, + TransactionControllerClearUnapprovedTransactionsAction, + TransactionControllerAbortTransactionSigningAction, + TransactionControllerUpdateAtomicBatchDataAction, +} from './TransactionController-method-action-types'; export { CANCEL_RATE, SPEED_UP_RATE, diff --git a/packages/transaction-pay-controller/CHANGELOG.md b/packages/transaction-pay-controller/CHANGELOG.md index f7e5ef39508..c3c3ae6a3ed 100644 --- a/packages/transaction-pay-controller/CHANGELOG.md +++ b/packages/transaction-pay-controller/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- New public wrapper methods: `getDelegationTransaction()`, `getStrategy()` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) - Support gasless Relay deposits via `execute` endpoint ([#8133](https://github.com/MetaMask/core/pull/8133)) - Build Across post-swap transfer actions for `predictDeposit` quotes so Predict deposits can bridge swapped output into the destination proxy wallet ([#8159](https://github.com/MetaMask/core/pull/8159)) diff --git a/packages/transaction-pay-controller/package.json b/packages/transaction-pay-controller/package.json index c4345e7d81d..c7d0ac33869 100644 --- a/packages/transaction-pay-controller/package.json +++ b/packages/transaction-pay-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/transaction-pay-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/transaction-pay-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", @@ -75,6 +76,7 @@ "deepmerge": "^4.2.2", "jest": "^29.7.0", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/transaction-pay-controller/src/TransactionPayController-method-action-types.ts b/packages/transaction-pay-controller/src/TransactionPayController-method-action-types.ts new file mode 100644 index 00000000000..380361c8d81 --- /dev/null +++ b/packages/transaction-pay-controller/src/TransactionPayController-method-action-types.ts @@ -0,0 +1,92 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { TransactionPayController } from './TransactionPayController'; + +/** + * Sets the transaction configuration. + * + * The callback receives the current configuration properties and can mutate + * them in place. Updated values are written back to the transaction data. + * + * @param transactionId - The ID of the transaction to configure. + * @param callback - A callback that receives a mutable {@link TransactionConfig} object. + */ +export type TransactionPayControllerSetTransactionConfigAction = { + type: `TransactionPayController:setTransactionConfig`; + handler: TransactionPayController['setTransactionConfig']; +}; + +/** + * Updates the payment token for a transaction. + * + * Resolves token metadata and balances, then stores the new payment token + * in the transaction data. This triggers recalculation of source amounts + * and quote retrieval. + * + * @param request - The payment token update request containing the + * transaction ID, token address, and chain ID. + */ +export type TransactionPayControllerUpdatePaymentTokenAction = { + type: `TransactionPayController:updatePaymentToken`; + handler: TransactionPayController['updatePaymentToken']; +}; + +/** + * Updates the fiat payment state for a transaction. + * + * The request callback receives the current fiat payment state and can + * mutate it to update properties such as the selected payment method or + * fiat amount. + * + * @param request - The fiat payment update request containing the + * transaction ID and a callback to mutate fiat payment state. + */ +export type TransactionPayControllerUpdateFiatPaymentAction = { + type: `TransactionPayController:updateFiatPayment`; + handler: TransactionPayController['updateFiatPayment']; +}; + +/** + * Gets the delegation transaction for a given transaction. + * + * Converts the provided transaction into a redeem delegation by delegating + * to the configured callback. Returns the delegation transaction data + * including the encoded call data, target address, value, and an optional + * authorization list. + * + * @param args - The arguments forwarded to the {@link GetDelegationTransactionCallback}, + * containing the transaction metadata. + * @returns A promise resolving to the delegation transaction data. + */ +export type TransactionPayControllerGetDelegationTransactionAction = { + type: `TransactionPayController:getDelegationTransaction`; + handler: TransactionPayController['getDelegationTransaction']; +}; + +/** + * Gets the preferred strategy for a transaction. + * + * Returns the first strategy from the ordered list of strategies applicable + * to the given transaction. Falls back to the default strategy order derived + * from feature flags when no custom strategy callback is configured. + * + * @param transaction - The transaction metadata to determine the strategy for. + * @returns The preferred {@link TransactionPayStrategy} for the transaction. + */ +export type TransactionPayControllerGetStrategyAction = { + type: `TransactionPayController:getStrategy`; + handler: TransactionPayController['getStrategy']; +}; + +/** + * Union of all TransactionPayController action types. + */ +export type TransactionPayControllerMethodActions = + | TransactionPayControllerSetTransactionConfigAction + | TransactionPayControllerUpdatePaymentTokenAction + | TransactionPayControllerUpdateFiatPaymentAction + | TransactionPayControllerGetDelegationTransactionAction + | TransactionPayControllerGetStrategyAction; diff --git a/packages/transaction-pay-controller/src/TransactionPayController.ts b/packages/transaction-pay-controller/src/TransactionPayController.ts index 7e8a65bfc24..6cf650df644 100644 --- a/packages/transaction-pay-controller/src/TransactionPayController.ts +++ b/packages/transaction-pay-controller/src/TransactionPayController.ts @@ -27,6 +27,14 @@ import { updateQuotes } from './utils/quotes'; import { updateSourceAmounts } from './utils/source-amounts'; import { pollTransactionChanges } from './utils/transaction'; +const MESSENGER_EXPOSED_METHODS = [ + 'getDelegationTransaction', + 'getStrategy', + 'setTransactionConfig', + 'updatePaymentToken', + 'updateFiatPayment', +] as const; + const stateMetadata: StateMetadata = { transactionData: { includeInDebugSnapshot: false, @@ -73,7 +81,10 @@ export class TransactionPayController extends BaseController< this.#getStrategy = getStrategy; this.#getStrategies = getStrategies; - this.#registerActionHandlers(); + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, + ); pollTransactionChanges( messenger, @@ -89,6 +100,15 @@ export class TransactionPayController extends BaseController< }); } + /** + * Sets the transaction configuration. + * + * The callback receives the current configuration properties and can mutate + * them in place. Updated values are written back to the transaction data. + * + * @param transactionId - The ID of the transaction to configure. + * @param callback - A callback that receives a mutable {@link TransactionConfig} object. + */ setTransactionConfig( transactionId: string, callback: TransactionConfigCallback, @@ -108,6 +128,16 @@ export class TransactionPayController extends BaseController< }); } + /** + * Updates the payment token for a transaction. + * + * Resolves token metadata and balances, then stores the new payment token + * in the transaction data. This triggers recalculation of source amounts + * and quote retrieval. + * + * @param request - The payment token update request containing the + * transaction ID, token address, and chain ID. + */ updatePaymentToken(request: UpdatePaymentTokenRequest): void { updatePaymentToken(request, { messenger: this.messenger, @@ -115,6 +145,16 @@ export class TransactionPayController extends BaseController< }); } + /** + * Updates the fiat payment state for a transaction. + * + * The request callback receives the current fiat payment state and can + * mutate it to update properties such as the selected payment method or + * fiat amount. + * + * @param request - The fiat payment update request containing the + * transaction ID and a callback to mutate fiat payment state. + */ updateFiatPayment(request: UpdateFiatPaymentRequest): void { updateFiatPayment(request, { messenger: this.messenger, @@ -122,6 +162,38 @@ export class TransactionPayController extends BaseController< }); } + /** + * Gets the delegation transaction for a given transaction. + * + * Converts the provided transaction into a redeem delegation by delegating + * to the configured callback. Returns the delegation transaction data + * including the encoded call data, target address, value, and an optional + * authorization list. + * + * @param args - The arguments forwarded to the {@link GetDelegationTransactionCallback}, + * containing the transaction metadata. + * @returns A promise resolving to the delegation transaction data. + */ + getDelegationTransaction( + ...args: Parameters + ): ReturnType { + return this.#getDelegationTransaction(...args); + } + + /** + * Gets the preferred strategy for a transaction. + * + * Returns the first strategy from the ordered list of strategies applicable + * to the given transaction. Falls back to the default strategy order derived + * from feature flags when no custom strategy callback is configured. + * + * @param transaction - The transaction metadata to determine the strategy for. + * @returns The preferred {@link TransactionPayStrategy} for the transaction. + */ + getStrategy(transaction: TransactionMeta): TransactionPayStrategy { + return this.#getStrategiesWithFallback(transaction)[0]; + } + #removeTransactionData(transactionId: string): void { this.update((state) => { delete state.transactionData[transactionId]; @@ -186,34 +258,6 @@ export class TransactionPayController extends BaseController< } } - #registerActionHandlers(): void { - this.messenger.registerActionHandler( - 'TransactionPayController:getDelegationTransaction', - this.#getDelegationTransaction.bind(this), - ); - - this.messenger.registerActionHandler( - 'TransactionPayController:getStrategy', - (transaction: TransactionMeta): TransactionPayStrategy => - this.#getStrategiesWithFallback(transaction)[0], - ); - - this.messenger.registerActionHandler( - 'TransactionPayController:setTransactionConfig', - this.setTransactionConfig.bind(this), - ); - - this.messenger.registerActionHandler( - 'TransactionPayController:updatePaymentToken', - this.updatePaymentToken.bind(this), - ); - - this.messenger.registerActionHandler( - 'TransactionPayController:updateFiatPayment', - this.updateFiatPayment.bind(this), - ); - } - #getStrategiesWithFallback( transaction: TransactionMeta, ): TransactionPayStrategy[] { diff --git a/packages/transaction-pay-controller/src/index.ts b/packages/transaction-pay-controller/src/index.ts index 8dd9ec3be8b..53cc04fa203 100644 --- a/packages/transaction-pay-controller/src/index.ts +++ b/packages/transaction-pay-controller/src/index.ts @@ -5,16 +5,11 @@ export type { TransactionFiatPaymentCallback, TransactionPayControllerActions, TransactionPayControllerEvents, - TransactionPayControllerGetDelegationTransactionAction, TransactionPayControllerGetStateAction, - TransactionPayControllerGetStrategyAction, TransactionPayControllerMessenger, TransactionPayControllerOptions, - TransactionPayControllerSetTransactionConfigAction, - TransactionPayControllerUpdateFiatPaymentAction, TransactionPayControllerState, TransactionPayControllerStateChangeEvent, - TransactionPayControllerUpdatePaymentTokenAction, TransactionPaymentToken, TransactionPayQuote, TransactionPayRequiredToken, @@ -23,6 +18,13 @@ export type { UpdateFiatPaymentRequest, UpdatePaymentTokenRequest, } from './types'; +export type { + TransactionPayControllerGetDelegationTransactionAction, + TransactionPayControllerGetStrategyAction, + TransactionPayControllerSetTransactionConfigAction, + TransactionPayControllerUpdatePaymentTokenAction, + TransactionPayControllerUpdateFiatPaymentAction, +} from './TransactionPayController-method-action-types'; export { TransactionPayStrategy } from './constants'; export { TransactionPayController } from './TransactionPayController'; export { TransactionPayPublishHook } from './helpers/TransactionPayPublishHook'; diff --git a/packages/transaction-pay-controller/src/tests/messenger-mock.ts b/packages/transaction-pay-controller/src/tests/messenger-mock.ts index b6d69d4f22d..86453901446 100644 --- a/packages/transaction-pay-controller/src/tests/messenger-mock.ts +++ b/packages/transaction-pay-controller/src/tests/messenger-mock.ts @@ -27,7 +27,7 @@ import type { BridgeStatusControllerSubmitTxAction } from '../../../bridge-statu import type { TransactionPayControllerGetDelegationTransactionAction, TransactionPayControllerGetStrategyAction, -} from '../types'; +} from '../TransactionPayController-method-action-types'; import type { TransactionPayControllerGetStateAction } from '../types'; type AllActions = MessengerActions; diff --git a/packages/transaction-pay-controller/src/types.ts b/packages/transaction-pay-controller/src/types.ts index ff99540dac5..bd4af64b177 100644 --- a/packages/transaction-pay-controller/src/types.ts +++ b/packages/transaction-pay-controller/src/types.ts @@ -35,6 +35,7 @@ import type { Hex, Json } from '@metamask/utils'; import type { Draft } from 'immer'; import type { CONTROLLER_NAME, TransactionPayStrategy } from './constants'; +import type { TransactionPayControllerMethodActions } from './TransactionPayController-method-action-types'; export type AllowedActions = | AccountTrackerControllerGetStateAction @@ -66,35 +67,6 @@ export type TransactionPayControllerGetStateAction = ControllerGetStateAction< TransactionPayControllerState >; -export type TransactionPayControllerGetDelegationTransactionAction = { - type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`; - handler: GetDelegationTransactionCallback; -}; - -/** Action to get the pay strategy type used for a transaction. */ -export type TransactionPayControllerGetStrategyAction = { - type: `${typeof CONTROLLER_NAME}:getStrategy`; - handler: (transaction: TransactionMeta) => TransactionPayStrategy; -}; - -/** Action to update fiat payment state for a transaction. */ -export type TransactionPayControllerUpdateFiatPaymentAction = { - type: `${typeof CONTROLLER_NAME}:updateFiatPayment`; - handler: (request: UpdateFiatPaymentRequest) => void; -}; - -/** Action to update the payment token for a transaction. */ -export type TransactionPayControllerUpdatePaymentTokenAction = { - type: `${typeof CONTROLLER_NAME}:updatePaymentToken`; - handler: (request: UpdatePaymentTokenRequest) => void; -}; - -/** Action to update transaction configuration using a callback. */ -export type TransactionPayControllerSetTransactionConfigAction = { - type: `${typeof CONTROLLER_NAME}:setTransactionConfig`; - handler: (transactionId: string, callback: TransactionConfigCallback) => void; -}; - /** Configurable properties of a transaction. */ export type TransactionConfig = { /** Whether the user has selected the maximum amount. */ @@ -132,12 +104,8 @@ export type TransactionPayControllerStateChangeEvent = >; export type TransactionPayControllerActions = - | TransactionPayControllerGetDelegationTransactionAction | TransactionPayControllerGetStateAction - | TransactionPayControllerGetStrategyAction - | TransactionPayControllerSetTransactionConfigAction - | TransactionPayControllerUpdateFiatPaymentAction - | TransactionPayControllerUpdatePaymentTokenAction; + | TransactionPayControllerMethodActions; export type TransactionPayControllerEvents = TransactionPayControllerStateChangeEvent; diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index b3deaf6dbb2..98f0259f6b0 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New messenger actions: `UserOperationControllerAddUserOperationAction`, `UserOperationControllerAddUserOperationFromTransactionAction`, `UserOperationControllerStartPollingByNetworkClientIdAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + ### Changed - Bump `@metamask/transaction-controller` from `^62.17.1` to `^62.21.0` ([#8005](https://github.com/MetaMask/core/pull/8005), [#8031](https://github.com/MetaMask/core/pull/8031), [#8104](https://github.com/MetaMask/core/pull/8104), [#8140](https://github.com/MetaMask/core/pull/8140)) diff --git a/packages/user-operation-controller/package.json b/packages/user-operation-controller/package.json index 434faa46943..ad9edb447b8 100644 --- a/packages/user-operation-controller/package.json +++ b/packages/user-operation-controller/package.json @@ -40,6 +40,7 @@ "build:docs": "typedoc", "changelog:update": "../../scripts/update-changelog.sh @metamask/user-operation-controller", "changelog:validate": "../../scripts/validate-changelog.sh @metamask/user-operation-controller", + "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", "prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh", "since-latest-release": "../../scripts/since-latest-release.sh", "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", @@ -74,6 +75,7 @@ "deepmerge": "^4.2.2", "jest": "^29.7.0", "ts-jest": "^29.2.5", + "tsx": "^4.20.5", "typedoc": "^0.25.13", "typedoc-plugin-missing-exports": "^2.0.0", "typescript": "~5.3.3" diff --git a/packages/user-operation-controller/src/UserOperationController-method-action-types.ts b/packages/user-operation-controller/src/UserOperationController-method-action-types.ts new file mode 100644 index 00000000000..33978bc98f0 --- /dev/null +++ b/packages/user-operation-controller/src/UserOperationController-method-action-types.ts @@ -0,0 +1,64 @@ +/** + * This file is auto generated by `scripts/generate-method-action-types.ts`. + * Do not edit manually. + */ + +import type { UserOperationController } from './UserOperationController'; + +/** + * Create and submit a user operation. + * + * @param request - Information required to create a user operation. + * @param request.data - Data to include in the resulting transaction. + * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction. + * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction. + * @param request.to - Destination address of the resulting transaction. + * @param request.value - Value to include in the resulting transaction. + * @param options - Configuration options when creating a user operation. + * @param options.networkClientId - ID of the network client used to query the chain. + * @param options.origin - Origin of the user operation, such as the hostname of a dApp. + * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true. + * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account. + * @param options.swaps - Swap metadata to record with the user operation. + * @param options.type - Type of the transaction. + */ +export type UserOperationControllerAddUserOperationAction = { + type: `UserOperationController:addUserOperation`; + handler: UserOperationController['addUserOperation']; +}; + +/** + * Create and submit a user operation equivalent to the provided transaction. + * + * @param transaction - Transaction to use as the basis for the user operation. + * @param options - Configuration options when creating a user operation. + * @param options.networkClientId - ID of the network client used to query the chain. + * @param options.origin - Origin of the user operation, such as the hostname of a dApp. + * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true. + * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account. + * @param options.swaps - Swap metadata to record with the user operation. + * @param options.type - Type of the transaction. + */ +export type UserOperationControllerAddUserOperationFromTransactionAction = { + type: `UserOperationController:addUserOperationFromTransaction`; + handler: UserOperationController['addUserOperationFromTransaction']; +}; + +/** + * Starts polling for pending user operations on the given network. + * + * @param networkClientId - The ID of the network client to poll. + * @returns The polling token that can be used to stop polling. + */ +export type UserOperationControllerStartPollingByNetworkClientIdAction = { + type: `UserOperationController:startPollingByNetworkClientId`; + handler: UserOperationController['startPollingByNetworkClientId']; +}; + +/** + * Union of all UserOperationController action types. + */ +export type UserOperationControllerMethodActions = + | UserOperationControllerAddUserOperationAction + | UserOperationControllerAddUserOperationFromTransactionAction + | UserOperationControllerStartPollingByNetworkClientIdAction; diff --git a/packages/user-operation-controller/src/UserOperationController.test.ts b/packages/user-operation-controller/src/UserOperationController.test.ts index 06b977354bd..c66ea1aea5d 100644 --- a/packages/user-operation-controller/src/UserOperationController.test.ts +++ b/packages/user-operation-controller/src/UserOperationController.test.ts @@ -106,6 +106,7 @@ function createMessengerMock() { call: jest.fn(), publish: jest.fn(), registerActionHandler: jest.fn(), + registerMethodActionHandlers: jest.fn(), registerInitialEventPayload: jest.fn(), } as unknown as jest.Mocked; } diff --git a/packages/user-operation-controller/src/UserOperationController.ts b/packages/user-operation-controller/src/UserOperationController.ts index 94701a0a984..5059f466ae7 100644 --- a/packages/user-operation-controller/src/UserOperationController.ts +++ b/packages/user-operation-controller/src/UserOperationController.ts @@ -1,6 +1,6 @@ import type { AcceptResultCallbacks, - AddApprovalRequest, + ApprovalControllerAddRequestAction as AddApprovalRequest, AddResult, } from '@metamask/approval-controller'; import { BaseController } from '@metamask/base-controller'; @@ -46,6 +46,7 @@ import type { UserOperationMetadata, } from './types'; import { UserOperationStatus } from './types'; +import type { UserOperationControllerMethodActions } from './UserOperationController-method-action-types'; import { updateGas } from './utils/gas'; import { updateGasFees } from './utils/gas-fees'; import { getTransactionMetadata } from './utils/transaction'; @@ -59,6 +60,12 @@ import { const controllerName = 'UserOperationController'; +const MESSENGER_EXPOSED_METHODS = [ + 'addUserOperation', + 'addUserOperationFromTransaction', + 'startPollingByNetworkClientId', +] as const; + const stateMetadata = { userOperations: { includeInStateLogs: true, @@ -111,6 +118,7 @@ export type UserOperationStateChange = ControllerStateChangeEvent< export type UserOperationControllerActions = | GetUserOperationState + | UserOperationControllerMethodActions | NetworkControllerGetNetworkClientByIdAction | AddApprovalRequest | KeyringControllerPrepareUserOperationAction @@ -229,6 +237,11 @@ export class UserOperationController extends BaseController< this.hub = new EventEmitter() as UserOperationControllerEventEmitter; + this.messenger.registerMethodActionHandlers( + this, + MESSENGER_EXPOSED_METHODS, + ); + this.#entrypoint = entrypoint; this.#getGasFeeEstimates = getGasFeeEstimates; @@ -303,6 +316,12 @@ export class UserOperationController extends BaseController< return await this.#addUserOperation(request, { ...options, transaction }); } + /** + * Starts polling for pending user operations on the given network. + * + * @param networkClientId - The ID of the network client to poll. + * @returns The polling token that can be used to stop polling. + */ startPollingByNetworkClientId(networkClientId: string): string { return this.#pendingUserOperationTracker.startPolling({ networkClientId, diff --git a/packages/user-operation-controller/src/index.ts b/packages/user-operation-controller/src/index.ts index fc4cd8a6e7e..a6a4fee803a 100644 --- a/packages/user-operation-controller/src/index.ts +++ b/packages/user-operation-controller/src/index.ts @@ -1,2 +1,7 @@ export * from './UserOperationController'; +export type { + UserOperationControllerAddUserOperationAction, + UserOperationControllerAddUserOperationFromTransactionAction, + UserOperationControllerStartPollingByNetworkClientIdAction, +} from './UserOperationController-method-action-types'; export * from './types'; diff --git a/yarn.lock b/yarn.lock index 5a654440c02..db9dd9ff4e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2627,6 +2627,7 @@ __metadata: deepmerge: "npm:^4.2.2" jest: "npm:^29.7.0" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -2753,6 +2754,7 @@ __metadata: jest: "npm:^29.7.0" nanoid: "npm:^3.3.8" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -3542,6 +3544,7 @@ __metadata: jest: "npm:^29.7.0" punycode: "npm:^2.1.1" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -4016,6 +4019,7 @@ __metadata: jest-when: "npm:^3.4.2" nock: "npm:^13.3.1" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -4271,6 +4275,7 @@ __metadata: deepmerge: "npm:^4.2.2" jest: "npm:^29.7.0" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -4479,6 +4484,7 @@ __metadata: deepmerge: "npm:^4.2.2" jest: "npm:^29.7.0" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -5110,6 +5116,7 @@ __metadata: jsonschema: "npm:^1.4.1" lodash: "npm:^4.17.21" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -5400,6 +5407,7 @@ __metadata: lodash: "npm:^4.17.21" nock: "npm:^13.3.1" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -5439,6 +5447,7 @@ __metadata: jest: "npm:^29.7.0" lodash: "npm:^4.17.21" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" @@ -5472,6 +5481,7 @@ __metadata: jest: "npm:^29.7.0" lodash: "npm:^4.17.21" ts-jest: "npm:^29.2.5" + tsx: "npm:^4.20.5" typedoc: "npm:^0.25.13" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:~5.3.3" From 4e3c2dd97f289478ddf2b6dfed267ba619ddbf09 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 11 Mar 2026 16:56:31 +0100 Subject: [PATCH 02/10] chore: Update CHANGELOG PR references to #8183 --- packages/address-book-controller/CHANGELOG.md | 2 +- packages/approval-controller/CHANGELOG.md | 6 +++--- packages/ens-controller/CHANGELOG.md | 2 +- packages/gas-fee-controller/CHANGELOG.md | 2 +- packages/logging-controller/CHANGELOG.md | 4 ++-- packages/name-controller/CHANGELOG.md | 2 +- packages/signature-controller/CHANGELOG.md | 2 +- packages/transaction-controller/CHANGELOG.md | 6 +++--- packages/transaction-pay-controller/CHANGELOG.md | 2 +- packages/user-operation-controller/CHANGELOG.md | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/address-book-controller/CHANGELOG.md b/packages/address-book-controller/CHANGELOG.md index 272493229cf..bd2a502f399 100644 --- a/packages/address-book-controller/CHANGELOG.md +++ b/packages/address-book-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger action: `AddressBookControllerClearAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger action: `AddressBookControllerClearAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ### Changed diff --git a/packages/approval-controller/CHANGELOG.md b/packages/approval-controller/CHANGELOG.md index df724d39bd7..33742dd167a 100644 --- a/packages/approval-controller/CHANGELOG.md +++ b/packages/approval-controller/CHANGELOG.md @@ -9,13 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **BREAKING:** Renamed methods: `clear()` → `clearRequests()`, `has()` → `hasRequest()`, `accept()` → `acceptRequest()`, `reject()` → `rejectRequest()`, `success()` → `showSuccess()`, `error()` → `showError()` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- **BREAKING:** Renamed methods: `clear()` → `clearRequests()`, `has()` → `hasRequest()`, `accept()` → `acceptRequest()`, `reject()` → `rejectRequest()`, `success()` → `showSuccess()`, `error()` → `showError()` ([#8183](https://github.com/MetaMask/core/pull/8183)) - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) ### Added -- New `addRequest()` public method ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) -- New messenger actions: `ApprovalControllerAddAction`, `ApprovalControllerAddAndShowApprovalRequestAction`, `ApprovalControllerGetAction`, `ApprovalControllerGetApprovalCountAction`, `ApprovalControllerGetTotalApprovalCountAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New `addRequest()` public method ([#8183](https://github.com/MetaMask/core/pull/8183)) +- New messenger actions: `ApprovalControllerAddAction`, `ApprovalControllerAddAndShowApprovalRequestAction`, `ApprovalControllerGetAction`, `ApprovalControllerGetApprovalCountAction`, `ApprovalControllerGetTotalApprovalCountAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ## [8.0.0] diff --git a/packages/ens-controller/CHANGELOG.md b/packages/ens-controller/CHANGELOG.md index 077dc55b641..1a71a37c534 100644 --- a/packages/ens-controller/CHANGELOG.md +++ b/packages/ens-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `EnsControllerResetStateAction`, `EnsControllerClearAction`, `EnsControllerDeleteAction`, `EnsControllerGetAction`, `EnsControllerSetAction`, `EnsControllerReverseResolveAddressAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger actions: `EnsControllerResetStateAction`, `EnsControllerClearAction`, `EnsControllerDeleteAction`, `EnsControllerGetAction`, `EnsControllerSetAction`, `EnsControllerReverseResolveAddressAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ## [19.0.3] diff --git a/packages/gas-fee-controller/CHANGELOG.md b/packages/gas-fee-controller/CHANGELOG.md index 131d80f7530..3ec61fc127e 100644 --- a/packages/gas-fee-controller/CHANGELOG.md +++ b/packages/gas-fee-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `GasFeeControllerResetPollingAction`, `GasFeeControllerFetchGasFeeEstimatesAction`, `GasFeeControllerGetGasFeeEstimatesAndStartPollingAction`, `GasFeeControllerDisconnectPollerAction`, `GasFeeControllerStopPollingAction`, `GasFeeControllerGetTimeEstimateAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger actions: `GasFeeControllerResetPollingAction`, `GasFeeControllerFetchGasFeeEstimatesAction`, `GasFeeControllerGetGasFeeEstimatesAndStartPollingAction`, `GasFeeControllerDisconnectPollerAction`, `GasFeeControllerStopPollingAction`, `GasFeeControllerGetTimeEstimateAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ## [26.0.3] diff --git a/packages/logging-controller/CHANGELOG.md b/packages/logging-controller/CHANGELOG.md index c5f5a9bf16a..a66beabfb4a 100644 --- a/packages/logging-controller/CHANGELOG.md +++ b/packages/logging-controller/CHANGELOG.md @@ -9,12 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **BREAKING:** Removed `AddLog` type alias; use `LoggingControllerAddAction` instead ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- **BREAKING:** Removed `AddLog` type alias; use `LoggingControllerAddAction` instead ([#8183](https://github.com/MetaMask/core/pull/8183)) - Bump `@metamask/controller-utils` from `^11.16.0` to `^11.19.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583), [#7995](https://github.com/MetaMask/core/pull/7995)) ### Added -- New messenger action: `LoggingControllerClearAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger action: `LoggingControllerClearAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ## [7.0.1] diff --git a/packages/name-controller/CHANGELOG.md b/packages/name-controller/CHANGELOG.md index 7cf1d695e76..e74bfa09aa2 100644 --- a/packages/name-controller/CHANGELOG.md +++ b/packages/name-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `NameControllerSetNameAction`, `NameControllerUpdateProposedNamesAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger actions: `NameControllerSetNameAction`, `NameControllerUpdateProposedNamesAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ### Changed diff --git a/packages/signature-controller/CHANGELOG.md b/packages/signature-controller/CHANGELOG.md index 3ba5bcf88b5..dc784cbab06 100644 --- a/packages/signature-controller/CHANGELOG.md +++ b/packages/signature-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `SignatureControllerResetStateAction`, `SignatureControllerRejectUnapprovedAction`, `SignatureControllerClearUnapprovedAction`, `SignatureControllerNewUnsignedPersonalMessageAction`, `SignatureControllerNewUnsignedTypedMessageAction`, `SignatureControllerSetDeferredSignSuccessAction`, `SignatureControllerSetMessageMetadataAction`, `SignatureControllerSetDeferredSignErrorAction`, `SignatureControllerSetTypedMessageInProgressAction`, `SignatureControllerSetPersonalMessageInProgressAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger actions: `SignatureControllerResetStateAction`, `SignatureControllerRejectUnapprovedAction`, `SignatureControllerClearUnapprovedAction`, `SignatureControllerNewUnsignedPersonalMessageAction`, `SignatureControllerNewUnsignedTypedMessageAction`, `SignatureControllerSetDeferredSignSuccessAction`, `SignatureControllerSetMessageMetadataAction`, `SignatureControllerSetDeferredSignErrorAction`, `SignatureControllerSetTypedMessageInProgressAction`, `SignatureControllerSetPersonalMessageInProgressAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ### Changed diff --git a/packages/transaction-controller/CHANGELOG.md b/packages/transaction-controller/CHANGELOG.md index c40e14a73b0..73ae0747bbe 100644 --- a/packages/transaction-controller/CHANGELOG.md +++ b/packages/transaction-controller/CHANGELOG.md @@ -11,12 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add optional `sourceHash` field to `MetamaskPayMetadata` for tracking source chain transaction hashes when no local transaction exists ([#8133](https://github.com/MetaMask/core/pull/8133)) - Add `predictDepositAndOrder` to `TransactionType` ([#8135](https://github.com/MetaMask/core/pull/8135)) -- New public `getGasFeeTokens()` method ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) -- New messenger actions: `TransactionControllerHandleMethodDataAction`, `TransactionControllerIsAtomicBatchSupportedAction`, `TransactionControllerStartIncomingTransactionPollingAction`, `TransactionControllerStopIncomingTransactionPollingAction`, `TransactionControllerUpdateIncomingTransactionsAction`, `TransactionControllerStopTransactionAction`, `TransactionControllerSpeedUpTransactionAction`, `TransactionControllerEstimateGasBufferedAction`, `TransactionControllerUpdateEditableParamsAction`, `TransactionControllerSetTransactionActiveAction`, `TransactionControllerApproveTransactionsWithSameNonceAction`, `TransactionControllerEstimateGasFeeAction`, `TransactionControllerGetLayer1GasFeeAction`, `TransactionControllerClearUnapprovedTransactionsAction`, `TransactionControllerAbortTransactionSigningAction`, `TransactionControllerUpdateAtomicBatchDataAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New public `getGasFeeTokens()` method ([#8183](https://github.com/MetaMask/core/pull/8183)) +- New messenger actions: `TransactionControllerHandleMethodDataAction`, `TransactionControllerIsAtomicBatchSupportedAction`, `TransactionControllerStartIncomingTransactionPollingAction`, `TransactionControllerStopIncomingTransactionPollingAction`, `TransactionControllerUpdateIncomingTransactionsAction`, `TransactionControllerStopTransactionAction`, `TransactionControllerSpeedUpTransactionAction`, `TransactionControllerEstimateGasBufferedAction`, `TransactionControllerUpdateEditableParamsAction`, `TransactionControllerSetTransactionActiveAction`, `TransactionControllerApproveTransactionsWithSameNonceAction`, `TransactionControllerEstimateGasFeeAction`, `TransactionControllerGetLayer1GasFeeAction`, `TransactionControllerClearUnapprovedTransactionsAction`, `TransactionControllerAbortTransactionSigningAction`, `TransactionControllerUpdateAtomicBatchDataAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ### Changed -- **BREAKING:** Action type names standardized with `Action` suffix (e.g. `TransactionControllerEmulateNewTransaction` → `TransactionControllerEmulateNewTransactionAction`) ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- **BREAKING:** Action type names standardized with `Action` suffix (e.g. `TransactionControllerEmulateNewTransaction` → `TransactionControllerEmulateNewTransactionAction`) ([#8183](https://github.com/MetaMask/core/pull/8183)) - Bump `@metamask/core-backend` from `^6.1.0` to `^6.1.1` ([#8162](https://github.com/MetaMask/core/pull/8162)) ### Fixed diff --git a/packages/transaction-pay-controller/CHANGELOG.md b/packages/transaction-pay-controller/CHANGELOG.md index c3c3ae6a3ed..c169108d9d5 100644 --- a/packages/transaction-pay-controller/CHANGELOG.md +++ b/packages/transaction-pay-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New public wrapper methods: `getDelegationTransaction()`, `getStrategy()` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New public wrapper methods: `getDelegationTransaction()`, `getStrategy()` ([#8183](https://github.com/MetaMask/core/pull/8183)) - Support gasless Relay deposits via `execute` endpoint ([#8133](https://github.com/MetaMask/core/pull/8133)) - Build Across post-swap transfer actions for `predictDeposit` quotes so Predict deposits can bridge swapped output into the destination proxy wallet ([#8159](https://github.com/MetaMask/core/pull/8159)) diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index 98f0259f6b0..d44fc34cf05 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `UserOperationControllerAddUserOperationAction`, `UserOperationControllerAddUserOperationFromTransactionAction`, `UserOperationControllerStartPollingByNetworkClientIdAction` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) +- New messenger actions: `UserOperationControllerAddUserOperationAction`, `UserOperationControllerAddUserOperationFromTransactionAction`, `UserOperationControllerStartPollingByNetworkClientIdAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) ### Changed From cb39e70f912a7f6a1cfaa81d52b7aafb69af8aef Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 11 Mar 2026 17:18:38 +0100 Subject: [PATCH 03/10] chore: Remove type aliases, use full action type names directly Replace AddApprovalRequest, AcceptApprovalRequest, HasApprovalRequest, RejectApprovalRequest aliases with their full generated names across all consumer packages. Add CHANGELOG entries for permission-controller and assets-controllers. --- packages/assets-controllers/CHANGELOG.md | 4 ++++ .../assets-controllers/src/NftController.test.ts | 2 -- packages/assets-controllers/src/NftController.ts | 4 ++-- .../src/NftDetectionController.ts | 4 ++-- .../assets-controllers/src/TokensController.ts | 4 ++-- packages/permission-controller/CHANGELOG.md | 1 + .../src/PermissionController.ts | 16 ++++++++-------- .../src/SignatureController.ts | 4 ++-- .../src/TransactionController.test.ts | 10 +++++----- .../src/TransactionController.ts | 4 ++-- .../src/UserOperationController.ts | 4 ++-- 11 files changed, 30 insertions(+), 27 deletions(-) diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index 9fe0114b609..295c85c66d3 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Updated `ApprovalController` usage to match renamed methods and action types ([#8183](https://github.com/MetaMask/core/pull/8183)) + ### Added - Expose missing public `AssetsContractController` methods through its messenger ([#8164](https://github.com/MetaMask/core/pull/8164)) diff --git a/packages/assets-controllers/src/NftController.test.ts b/packages/assets-controllers/src/NftController.test.ts index 47f5d03a4b9..84507bbfd90 100644 --- a/packages/assets-controllers/src/NftController.test.ts +++ b/packages/assets-controllers/src/NftController.test.ts @@ -1220,7 +1220,6 @@ describe('NftController', () => { // now accept the request // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/no-floating-promises approvalController.acceptRequest(requestId); await acceptedRequest; @@ -1331,7 +1330,6 @@ describe('NftController', () => { }); // now accept the request // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/no-floating-promises approvalController.acceptRequest(requestId); await acceptedRequest; diff --git a/packages/assets-controllers/src/NftController.ts b/packages/assets-controllers/src/NftController.ts index 81e8f5d0830..13a81487f10 100644 --- a/packages/assets-controllers/src/NftController.ts +++ b/packages/assets-controllers/src/NftController.ts @@ -4,7 +4,7 @@ import type { AccountsControllerGetAccountAction, AccountsControllerGetSelectedAccountAction, } from '@metamask/accounts-controller'; -import type { ApprovalControllerAddRequestAction as AddApprovalRequest } from '@metamask/approval-controller'; +import type { ApprovalControllerAddRequestAction } from '@metamask/approval-controller'; import { BaseController } from '@metamask/base-controller'; import type { ControllerStateChangeEvent, @@ -297,7 +297,7 @@ export type NftControllerActions = NftControllerGetStateAction; * The external actions available to the {@link NftController}. */ export type AllowedActions = - | AddApprovalRequest + | ApprovalControllerAddRequestAction | AccountsControllerGetAccountAction | AccountsControllerGetSelectedAccountAction | NetworkControllerGetNetworkClientByIdAction diff --git a/packages/assets-controllers/src/NftDetectionController.ts b/packages/assets-controllers/src/NftDetectionController.ts index 6e3f12f788d..9db600572b3 100644 --- a/packages/assets-controllers/src/NftDetectionController.ts +++ b/packages/assets-controllers/src/NftDetectionController.ts @@ -1,5 +1,5 @@ import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller'; -import type { ApprovalControllerAddRequestAction as AddApprovalRequest } from '@metamask/approval-controller'; +import type { ApprovalControllerAddRequestAction } from '@metamask/approval-controller'; import { BaseController } from '@metamask/base-controller'; import type { ControllerGetStateAction, @@ -42,7 +42,7 @@ export type NFTDetectionControllerState = Record; export type AllowedActions = | ControllerGetStateAction - | AddApprovalRequest + | ApprovalControllerAddRequestAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | PreferencesControllerGetStateAction diff --git a/packages/assets-controllers/src/TokensController.ts b/packages/assets-controllers/src/TokensController.ts index 0b4619e1840..5b2ae1e351e 100644 --- a/packages/assets-controllers/src/TokensController.ts +++ b/packages/assets-controllers/src/TokensController.ts @@ -6,7 +6,7 @@ import type { AccountsControllerListAccountsAction, AccountsControllerSelectedEvmAccountChangeEvent, } from '@metamask/accounts-controller'; -import type { ApprovalControllerAddRequestAction as AddApprovalRequest } from '@metamask/approval-controller'; +import type { ApprovalControllerAddRequestAction } from '@metamask/approval-controller'; import type { ControllerGetStateAction, ControllerStateChangeEvent, @@ -145,7 +145,7 @@ export type TokensControllerActions = * The external actions available to the {@link TokensController}. */ export type AllowedActions = - | AddApprovalRequest + | ApprovalControllerAddRequestAction | NetworkControllerGetNetworkClientByIdAction | AccountsControllerGetAccountAction | AccountsControllerGetSelectedAccountAction diff --git a/packages/permission-controller/CHANGELOG.md b/packages/permission-controller/CHANGELOG.md index 46262073622..9952f407fa5 100644 --- a/packages/permission-controller/CHANGELOG.md +++ b/packages/permission-controller/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **BREAKING:** Updated `ApprovalController` action type imports: `AcceptApprovalRequest` → `ApprovalControllerAcceptRequestAction`, `AddApprovalRequest` → `ApprovalControllerAddRequestAction`, `HasApprovalRequest` → `ApprovalControllerHasRequestAction`, `RejectApprovalRequest` → `ApprovalControllerRejectRequestAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) - Bump `@metamask/json-rpc-engine` from `^10.2.0` to `^10.2.3` ([#7642](https://github.com/MetaMask/core/pull/7642), [#7856](https://github.com/MetaMask/core/pull/7856), [#8078](https://github.com/MetaMask/core/pull/8078)) - Bump `@metamask/controller-utils` from `^11.17.0` to `^11.19.0` ([#7583](https://github.com/MetaMask/core/pull/7583), [#7995](https://github.com/MetaMask/core/pull/7995)) diff --git a/packages/permission-controller/src/PermissionController.ts b/packages/permission-controller/src/PermissionController.ts index 64f226c4c1b..098d3017c97 100644 --- a/packages/permission-controller/src/PermissionController.ts +++ b/packages/permission-controller/src/PermissionController.ts @@ -1,8 +1,8 @@ import type { - ApprovalControllerAcceptRequestAction as AcceptApprovalRequest, - ApprovalControllerAddRequestAction as AddApprovalRequest, - ApprovalControllerHasRequestAction as HasApprovalRequest, - ApprovalControllerRejectRequestAction as RejectApprovalRequest, + ApprovalControllerAcceptRequestAction, + ApprovalControllerAddRequestAction, + ApprovalControllerHasRequestAction, + ApprovalControllerRejectRequestAction, } from '@metamask/approval-controller'; import type { StateMetadata, @@ -417,10 +417,10 @@ export type PermissionControllerEvents = PermissionControllerStateChange; * {@link PermissionController}. */ type AllowedActions = - | AddApprovalRequest - | HasApprovalRequest - | AcceptApprovalRequest - | RejectApprovalRequest + | ApprovalControllerAddRequestAction + | ApprovalControllerHasRequestAction + | ApprovalControllerAcceptRequestAction + | ApprovalControllerRejectRequestAction | GetSubjectMetadata; /** diff --git a/packages/signature-controller/src/SignatureController.ts b/packages/signature-controller/src/SignatureController.ts index a3c0da366d7..7cbbfcae890 100644 --- a/packages/signature-controller/src/SignatureController.ts +++ b/packages/signature-controller/src/SignatureController.ts @@ -1,6 +1,6 @@ import type { AccountsControllerGetStateAction } from '@metamask/accounts-controller'; import type { - ApprovalControllerAddRequestAction as AddApprovalRequest, + ApprovalControllerAddRequestAction, AcceptResultCallbacks, AddResult, } from '@metamask/approval-controller'; @@ -168,7 +168,7 @@ export type SignatureControllerState = { type AllowedActions = | AccountsControllerGetStateAction - | AddApprovalRequest + | ApprovalControllerAddRequestAction | LoggingControllerAddAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | NetworkControllerGetNetworkClientByIdAction diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index c31f51a41ab..4ed5d3f5bd5 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -5,7 +5,7 @@ import { TransactionFactory } from '@ethereumjs/tx'; import type { - ApprovalControllerAddRequestAction as AddApprovalRequest, + ApprovalControllerAddRequestAction, AddResult, } from '@metamask/approval-controller'; import { deriveStateFromMetadata } from '@metamask/base-controller'; @@ -848,8 +848,8 @@ describe('TransactionController', () => { approve: (approvalResult?: Partial) => void; reject: (rejectionError: unknown) => void; actionHandlerMock: jest.Mock< - ReturnType, - Parameters + ReturnType, + Parameters >; } { const { promise, resolve, reject } = createDeferredPromise(); @@ -877,8 +877,8 @@ describe('TransactionController', () => { }; const actionHandlerMock: jest.Mock< - ReturnType, - Parameters + ReturnType, + Parameters > = jest.fn().mockReturnValue(promise); if (options.state === 'approved') { approveTransaction(options.result); diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index 2b9f7011a26..92407767bfc 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -7,7 +7,7 @@ import type { } from '@metamask/accounts-controller'; import type { AcceptResultCallbacks, - ApprovalControllerAddRequestAction as AddApprovalRequest, + ApprovalControllerAddRequestAction, AddResult, } from '@metamask/approval-controller'; import type { @@ -490,7 +490,7 @@ const controllerName = 'TransactionController'; export type AllowedActions = | AccountsControllerGetSelectedAccountAction | AccountsControllerGetStateAction - | AddApprovalRequest + | ApprovalControllerAddRequestAction | KeyringControllerSignEip7702AuthorizationAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction diff --git a/packages/user-operation-controller/src/UserOperationController.ts b/packages/user-operation-controller/src/UserOperationController.ts index 5059f466ae7..a9e590627a3 100644 --- a/packages/user-operation-controller/src/UserOperationController.ts +++ b/packages/user-operation-controller/src/UserOperationController.ts @@ -1,6 +1,6 @@ import type { AcceptResultCallbacks, - ApprovalControllerAddRequestAction as AddApprovalRequest, + ApprovalControllerAddRequestAction, AddResult, } from '@metamask/approval-controller'; import { BaseController } from '@metamask/base-controller'; @@ -120,7 +120,7 @@ export type UserOperationControllerActions = | GetUserOperationState | UserOperationControllerMethodActions | NetworkControllerGetNetworkClientByIdAction - | AddApprovalRequest + | ApprovalControllerAddRequestAction | KeyringControllerPrepareUserOperationAction | KeyringControllerPatchUserOperationAction | KeyringControllerSignUserOperationAction; From 0593ac103f50d2144577541d2359fa8b1fde8a0d Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 11 Mar 2026 17:31:57 +0100 Subject: [PATCH 04/10] test: Add getDelegationTransaction test to meet coverage threshold --- .../src/TransactionPayController.test.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/transaction-pay-controller/src/TransactionPayController.test.ts b/packages/transaction-pay-controller/src/TransactionPayController.test.ts index 5c228f36f10..09e1e3c99c8 100644 --- a/packages/transaction-pay-controller/src/TransactionPayController.test.ts +++ b/packages/transaction-pay-controller/src/TransactionPayController.test.ts @@ -217,6 +217,30 @@ describe('TransactionPayController', () => { }); }); + describe('getDelegationTransaction', () => { + it('delegates to the callback', async () => { + const resultMock = { data: '0x1', to: '0x2', value: '0x3' }; + const getDelegationTransactionMock = jest + .fn() + .mockResolvedValue(resultMock); + + new TransactionPayController({ + getDelegationTransaction: getDelegationTransactionMock, + messenger, + }); + + const result = await messenger.call( + 'TransactionPayController:getDelegationTransaction', + { transaction: TRANSACTION_META_MOCK }, + ); + + expect(getDelegationTransactionMock).toHaveBeenCalledWith({ + transaction: TRANSACTION_META_MOCK, + }); + expect(result).toBe(resultMock); + }); + }); + describe('getStrategy Action', () => { it('returns relay if no callback', async () => { createController(); From aae9a022ae73b5a572a90353c2108f4d07d758f2 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 11 Mar 2026 17:43:40 +0100 Subject: [PATCH 05/10] chore: Fix CHANGELOG section ordering to pass validation --- packages/approval-controller/CHANGELOG.md | 10 +++++----- packages/assets-controllers/CHANGELOG.md | 5 +---- packages/logging-controller/CHANGELOG.md | 8 ++++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/approval-controller/CHANGELOG.md b/packages/approval-controller/CHANGELOG.md index 33742dd167a..e6d33f945bd 100644 --- a/packages/approval-controller/CHANGELOG.md +++ b/packages/approval-controller/CHANGELOG.md @@ -7,16 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Changed - -- **BREAKING:** Renamed methods: `clear()` → `clearRequests()`, `has()` → `hasRequest()`, `accept()` → `acceptRequest()`, `reject()` → `rejectRequest()`, `success()` → `showSuccess()`, `error()` → `showError()` ([#8183](https://github.com/MetaMask/core/pull/8183)) -- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) - ### Added - New `addRequest()` public method ([#8183](https://github.com/MetaMask/core/pull/8183)) - New messenger actions: `ApprovalControllerAddAction`, `ApprovalControllerAddAndShowApprovalRequestAction`, `ApprovalControllerGetAction`, `ApprovalControllerGetApprovalCountAction`, `ApprovalControllerGetTotalApprovalCountAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +### Changed + +- **BREAKING:** Renamed methods: `clear()` → `clearRequests()`, `has()` → `hasRequest()`, `accept()` → `acceptRequest()`, `reject()` → `rejectRequest()`, `success()` → `showSuccess()`, `error()` → `showError()` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) + ## [8.0.0] ### Changed diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index 295c85c66d3..c3527e6559a 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Changed - -- Updated `ApprovalController` usage to match renamed methods and action types ([#8183](https://github.com/MetaMask/core/pull/8183)) - ### Added - Expose missing public `AssetsContractController` methods through its messenger ([#8164](https://github.com/MetaMask/core/pull/8164)) @@ -40,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Updated `ApprovalController` usage to match renamed methods and action types ([#8183](https://github.com/MetaMask/core/pull/8183)) - **BREAKING:** Standardize names of `AccountTrackerController` messenger action types ([#8164](https://github.com/MetaMask/core/pull/8164)) - All existing types for messenger actions have been renamed so they include `Controller` (e.g. `AccountTrackerUpdateNativeBalancesAction` -> `AccountTrackerControllerUpdateNativeBalancesAction`). 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 `AccountTrackerController` messengers. diff --git a/packages/logging-controller/CHANGELOG.md b/packages/logging-controller/CHANGELOG.md index a66beabfb4a..aa4faaf2d6c 100644 --- a/packages/logging-controller/CHANGELOG.md +++ b/packages/logging-controller/CHANGELOG.md @@ -7,15 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New messenger action: `LoggingControllerClearAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) + ### Changed - **BREAKING:** Removed `AddLog` type alias; use `LoggingControllerAddAction` instead ([#8183](https://github.com/MetaMask/core/pull/8183)) - Bump `@metamask/controller-utils` from `^11.16.0` to `^11.19.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583), [#7995](https://github.com/MetaMask/core/pull/7995)) -### Added - -- New messenger action: `LoggingControllerClearAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) - ## [7.0.1] ### Changed From f30cfcb2147ab2bc67a42acdc7f26344f26fa5f6 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Wed, 11 Mar 2026 17:51:05 +0100 Subject: [PATCH 06/10] chore: Make assets-controllers CHANGELOG entry more explicit --- packages/assets-controllers/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index c3527e6559a..237954a10c7 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -36,7 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Updated `ApprovalController` usage to match renamed methods and action types ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Updated `ApprovalController` method calls (`accept` → `acceptRequest`) and replaced `AddApprovalRequest` type alias with `ApprovalControllerAddRequestAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) - **BREAKING:** Standardize names of `AccountTrackerController` messenger action types ([#8164](https://github.com/MetaMask/core/pull/8164)) - All existing types for messenger actions have been renamed so they include `Controller` (e.g. `AccountTrackerUpdateNativeBalancesAction` -> `AccountTrackerControllerUpdateNativeBalancesAction`). 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 `AccountTrackerController` messengers. From 2a5a952b42983b3dbda8dfa200db6da59aefcf34 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Thu, 12 Mar 2026 13:48:07 +0100 Subject: [PATCH 07/10] fix: address pr reviews --- packages/address-book-controller/CHANGELOG.md | 5 ++- packages/approval-controller/CHANGELOG.md | 14 +++++- .../src/ApprovalController.ts | 4 +- packages/assets-controllers/CHANGELOG.md | 2 +- packages/ens-controller/CHANGELOG.md | 10 ++++- packages/ens-controller/src/EnsController.ts | 4 +- packages/gas-fee-controller/CHANGELOG.md | 10 ++++- .../src/GasFeeController.ts | 6 +-- packages/logging-controller/CHANGELOG.md | 9 +++- packages/name-controller/CHANGELOG.md | 6 ++- packages/permission-controller/CHANGELOG.md | 1 - packages/signature-controller/CHANGELOG.md | 14 +++++- .../src/SignatureController.ts | 8 ++-- packages/transaction-controller/CHANGELOG.md | 32 +++++++++++--- .../src/TransactionController.ts | 44 ++++++++----------- .../src/TransactionPayController.ts | 2 +- .../user-operation-controller/CHANGELOG.md | 7 ++- 17 files changed, 123 insertions(+), 55 deletions(-) diff --git a/packages/address-book-controller/CHANGELOG.md b/packages/address-book-controller/CHANGELOG.md index bd2a502f399..076dabcade5 100644 --- a/packages/address-book-controller/CHANGELOG.md +++ b/packages/address-book-controller/CHANGELOG.md @@ -9,7 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger action: `AddressBookControllerClearAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `AddressBookController` method through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following action is now available: + - `AddressBookController:clear` + - Corresponding action type (`AddressBookControllerClearAction`) is available as well. ### Changed diff --git a/packages/approval-controller/CHANGELOG.md b/packages/approval-controller/CHANGELOG.md index e6d33f945bd..05bb9ebc088 100644 --- a/packages/approval-controller/CHANGELOG.md +++ b/packages/approval-controller/CHANGELOG.md @@ -10,11 +10,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New `addRequest()` public method ([#8183](https://github.com/MetaMask/core/pull/8183)) -- New messenger actions: `ApprovalControllerAddAction`, `ApprovalControllerAddAndShowApprovalRequestAction`, `ApprovalControllerGetAction`, `ApprovalControllerGetApprovalCountAction`, `ApprovalControllerGetTotalApprovalCountAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `ApprovalController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following actions are now available: + - `ApprovalController:add` + - `ApprovalController:addAndShowApprovalRequest` + - `ApprovalController:get` + - `ApprovalController:getApprovalCount` + - `ApprovalController:getTotalApprovalCount` + - Corresponding action types (e.g. `ApprovalControllerAddAction`) are available as well. ### Changed -- **BREAKING:** Renamed methods: `clear()` → `clearRequests()`, `has()` → `hasRequest()`, `accept()` → `acceptRequest()`, `reject()` → `rejectRequest()`, `success()` → `showSuccess()`, `error()` → `showError()` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- **BREAKING:** Standardize names of `ApprovalController` methods ([#8183](https://github.com/MetaMask/core/pull/8183)) + - All existing methods for handling requests have been renamed so they include `Request` (e.g. `clear()` -> `clearRequest()`). You will need to update usage appropriately. + - The error handling method `error()` has been renamed to include `show` (`error()` -> `showError()`). You will need to update usage appropriately. +- **BREAKING:** Rename get-state action type: `GetApprovalsState` → `ApprovalControllerGetStateAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) ## [8.0.0] diff --git a/packages/approval-controller/src/ApprovalController.ts b/packages/approval-controller/src/ApprovalController.ts index 266d93658dc..1811535bb12 100644 --- a/packages/approval-controller/src/ApprovalController.ts +++ b/packages/approval-controller/src/ApprovalController.ts @@ -298,13 +298,13 @@ export type ApprovalControllerEvents = ApprovalStateChange; // Action Types -export type GetApprovalsState = ControllerGetStateAction< +export type ApprovalControllerGetStateAction = ControllerGetStateAction< typeof controllerName, ApprovalControllerState >; export type ApprovalControllerActions = - | GetApprovalsState + | ApprovalControllerGetStateAction | ApprovalControllerMethodActions; /** diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index 237954a10c7..418b4a7ada1 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -36,7 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Updated `ApprovalController` method calls (`accept` → `acceptRequest`) and replaced `AddApprovalRequest` type alias with `ApprovalControllerAddRequestAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Updated `ApprovalController` method calls (`accept` → `acceptRequest`) ([#8183](https://github.com/MetaMask/core/pull/8183)) - **BREAKING:** Standardize names of `AccountTrackerController` messenger action types ([#8164](https://github.com/MetaMask/core/pull/8164)) - All existing types for messenger actions have been renamed so they include `Controller` (e.g. `AccountTrackerUpdateNativeBalancesAction` -> `AccountTrackerControllerUpdateNativeBalancesAction`). 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 `AccountTrackerController` messengers. diff --git a/packages/ens-controller/CHANGELOG.md b/packages/ens-controller/CHANGELOG.md index 1a71a37c534..1dc1803c11e 100644 --- a/packages/ens-controller/CHANGELOG.md +++ b/packages/ens-controller/CHANGELOG.md @@ -9,7 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `EnsControllerResetStateAction`, `EnsControllerClearAction`, `EnsControllerDeleteAction`, `EnsControllerGetAction`, `EnsControllerSetAction`, `EnsControllerReverseResolveAddressAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `EnsController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following actions are now available: + - `EnsController:resetState` + - `EnsController:clear` + - `EnsController:delete` + - `EnsController:get` + - `EnsController:set` + - `EnsController:reverseResolveAddress` + - Corresponding action types (e.g. `EnsControllerResetStateAction`) are available as well. ## [19.0.3] diff --git a/packages/ens-controller/src/EnsController.ts b/packages/ens-controller/src/EnsController.ts index b7bf94458c6..9d974bce5be 100644 --- a/packages/ens-controller/src/EnsController.ts +++ b/packages/ens-controller/src/EnsController.ts @@ -32,12 +32,12 @@ const log = createProjectLogger('ens-controller'); const name = 'EnsController'; const MESSENGER_EXPOSED_METHODS = [ - 'resetState', 'clear', 'delete', 'get', - 'set', + 'resetState', 'reverseResolveAddress', + 'set', ] as const; // Map of chainIDs and ENS registry contract addresses diff --git a/packages/gas-fee-controller/CHANGELOG.md b/packages/gas-fee-controller/CHANGELOG.md index 3ec61fc127e..4b2d2d5dfc5 100644 --- a/packages/gas-fee-controller/CHANGELOG.md +++ b/packages/gas-fee-controller/CHANGELOG.md @@ -9,7 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `GasFeeControllerResetPollingAction`, `GasFeeControllerFetchGasFeeEstimatesAction`, `GasFeeControllerGetGasFeeEstimatesAndStartPollingAction`, `GasFeeControllerDisconnectPollerAction`, `GasFeeControllerStopPollingAction`, `GasFeeControllerGetTimeEstimateAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `GasFeeController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following actions are now available: + - `GasFeeController:resetPolling` + - `GasFeeController:fetchGasFeeEstimates` + - `GasFeeController:getGasFeeEstimatesAndStartPolling` + - `GasFeeController:disconnectPoller` + - `GasFeeController:stopPolling` + - `GasFeeController:getTimeEstimate` + - Corresponding action types (e.g. `GasFeeControllerResetPollingAction`) are available as well. ## [26.0.3] diff --git a/packages/gas-fee-controller/src/GasFeeController.ts b/packages/gas-fee-controller/src/GasFeeController.ts index a35a910093e..ce0a232baa1 100644 --- a/packages/gas-fee-controller/src/GasFeeController.ts +++ b/packages/gas-fee-controller/src/GasFeeController.ts @@ -252,12 +252,12 @@ export type GasFeeState = GasFeeEstimatesByChainId & const name = 'GasFeeController'; const MESSENGER_EXPOSED_METHODS = [ - 'resetPolling', + 'disconnectPoller', 'fetchGasFeeEstimates', 'getGasFeeEstimatesAndStartPolling', - 'disconnectPoller', - 'stopPolling', 'getTimeEstimate', + 'resetPolling', + 'stopPolling', ] as const; export type GasFeeStateChange = ControllerStateChangeEvent< diff --git a/packages/logging-controller/CHANGELOG.md b/packages/logging-controller/CHANGELOG.md index aa4faaf2d6c..d993e976e1a 100644 --- a/packages/logging-controller/CHANGELOG.md +++ b/packages/logging-controller/CHANGELOG.md @@ -9,11 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger action: `LoggingControllerClearAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `LoggingController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following action is now available: + - `LoggingController:clear` + - Corresponding action type (`LoggingControllerClearAction`) is available as well. ### Changed -- **BREAKING:** Removed `AddLog` type alias; use `LoggingControllerAddAction` instead ([#8183](https://github.com/MetaMask/core/pull/8183)) +- **BREAKING:** Standardize names of `LoggingController` messenger action types ([#8183](https://github.com/MetaMask/core/pull/8183)) + - All existing types for messenger actions have been renamed so they end in `Action` and include the controller name (e.g. `AddLog` -> `LoggingControllerAddAction`). 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 `LoggingController` messengers. - Bump `@metamask/controller-utils` from `^11.16.0` to `^11.19.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583), [#7995](https://github.com/MetaMask/core/pull/7995)) ## [7.0.1] diff --git a/packages/name-controller/CHANGELOG.md b/packages/name-controller/CHANGELOG.md index e74bfa09aa2..ccbdc50a32f 100644 --- a/packages/name-controller/CHANGELOG.md +++ b/packages/name-controller/CHANGELOG.md @@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `NameControllerSetNameAction`, `NameControllerUpdateProposedNamesAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `NameController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following actions are now available: + - `NameController:setName` + - `NameController:updateProposedNames` + - Corresponding action types (e.g. `NameControllerSetNameAction`) are available as well. ### Changed diff --git a/packages/permission-controller/CHANGELOG.md b/packages/permission-controller/CHANGELOG.md index 9952f407fa5..46262073622 100644 --- a/packages/permission-controller/CHANGELOG.md +++ b/packages/permission-controller/CHANGELOG.md @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **BREAKING:** Updated `ApprovalController` action type imports: `AcceptApprovalRequest` → `ApprovalControllerAcceptRequestAction`, `AddApprovalRequest` → `ApprovalControllerAddRequestAction`, `HasApprovalRequest` → `ApprovalControllerHasRequestAction`, `RejectApprovalRequest` → `ApprovalControllerRejectRequestAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) - Bump `@metamask/json-rpc-engine` from `^10.2.0` to `^10.2.3` ([#7642](https://github.com/MetaMask/core/pull/7642), [#7856](https://github.com/MetaMask/core/pull/7856), [#8078](https://github.com/MetaMask/core/pull/8078)) - Bump `@metamask/controller-utils` from `^11.17.0` to `^11.19.0` ([#7583](https://github.com/MetaMask/core/pull/7583), [#7995](https://github.com/MetaMask/core/pull/7995)) diff --git a/packages/signature-controller/CHANGELOG.md b/packages/signature-controller/CHANGELOG.md index dc784cbab06..68dcfded6f3 100644 --- a/packages/signature-controller/CHANGELOG.md +++ b/packages/signature-controller/CHANGELOG.md @@ -9,7 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `SignatureControllerResetStateAction`, `SignatureControllerRejectUnapprovedAction`, `SignatureControllerClearUnapprovedAction`, `SignatureControllerNewUnsignedPersonalMessageAction`, `SignatureControllerNewUnsignedTypedMessageAction`, `SignatureControllerSetDeferredSignSuccessAction`, `SignatureControllerSetMessageMetadataAction`, `SignatureControllerSetDeferredSignErrorAction`, `SignatureControllerSetTypedMessageInProgressAction`, `SignatureControllerSetPersonalMessageInProgressAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `SignatureController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following actions are now available: + - `SignatureController:resetState` + - `SignatureController:rejectUnapproved` + - `SignatureController:clearUnapproved` + - `SignatureController:newUnsignedPersonalMessage` + - `SignatureController:newUnsignedTypedMessage` + - `SignatureController:setDeferredSignSuccess` + - `SignatureController:setMessageMetadata` + - `SignatureController:setDeferredSignError` + - `SignatureController:setTypedMessageInProgress` + - `SignatureController:setPersonalMessageInProgress` + - Corresponding action types (e.g. `SignatureControllerResetStateAction`) are available as well. ### Changed diff --git a/packages/signature-controller/src/SignatureController.ts b/packages/signature-controller/src/SignatureController.ts index 7cbbfcae890..c24b6bebe33 100644 --- a/packages/signature-controller/src/SignatureController.ts +++ b/packages/signature-controller/src/SignatureController.ts @@ -71,16 +71,16 @@ import { const controllerName = 'SignatureController'; const MESSENGER_EXPOSED_METHODS = [ - 'resetState', - 'rejectUnapproved', 'clearUnapproved', 'newUnsignedPersonalMessage', 'newUnsignedTypedMessage', + 'rejectUnapproved', + 'resetState', + 'setDeferredSignError', 'setDeferredSignSuccess', 'setMessageMetadata', - 'setDeferredSignError', - 'setTypedMessageInProgress', 'setPersonalMessageInProgress', + 'setTypedMessageInProgress', ] as const; const stateMetadata = { diff --git a/packages/transaction-controller/CHANGELOG.md b/packages/transaction-controller/CHANGELOG.md index 73ae0747bbe..c91b83cbb1d 100644 --- a/packages/transaction-controller/CHANGELOG.md +++ b/packages/transaction-controller/CHANGELOG.md @@ -11,12 +11,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add optional `sourceHash` field to `MetamaskPayMetadata` for tracking source chain transaction hashes when no local transaction exists ([#8133](https://github.com/MetaMask/core/pull/8133)) - Add `predictDepositAndOrder` to `TransactionType` ([#8135](https://github.com/MetaMask/core/pull/8135)) -- New public `getGasFeeTokens()` method ([#8183](https://github.com/MetaMask/core/pull/8183)) -- New messenger actions: `TransactionControllerHandleMethodDataAction`, `TransactionControllerIsAtomicBatchSupportedAction`, `TransactionControllerStartIncomingTransactionPollingAction`, `TransactionControllerStopIncomingTransactionPollingAction`, `TransactionControllerUpdateIncomingTransactionsAction`, `TransactionControllerStopTransactionAction`, `TransactionControllerSpeedUpTransactionAction`, `TransactionControllerEstimateGasBufferedAction`, `TransactionControllerUpdateEditableParamsAction`, `TransactionControllerSetTransactionActiveAction`, `TransactionControllerApproveTransactionsWithSameNonceAction`, `TransactionControllerEstimateGasFeeAction`, `TransactionControllerGetLayer1GasFeeAction`, `TransactionControllerClearUnapprovedTransactionsAction`, `TransactionControllerAbortTransactionSigningAction`, `TransactionControllerUpdateAtomicBatchDataAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) - -### Changed - -- **BREAKING:** Action type names standardized with `Action` suffix (e.g. `TransactionControllerEmulateNewTransaction` → `TransactionControllerEmulateNewTransactionAction`) ([#8183](https://github.com/MetaMask/core/pull/8183)) +- New public `getGasFeeTokens()` controller method ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `TransactionController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following actions are now available: + - `TransactionController:handleMethodData` + - `TransactionController:isAtomicBatchSupported` + - `TransactionController:startIncomingTransactionPolling` + - `TransactionController:stopIncomingTransactionPolling` + - `TransactionController:updateIncomingTransactions` + - `TransactionController:stopTransaction` + - `TransactionController:speedUpTransaction` + - `TransactionController:estimateGasBuffered` + - `TransactionController:updateEditableParams` + - `TransactionController:setTransactionActive` + - `TransactionController:approveTransactionsWithSameNonce` + - `TransactionController:estimateGasFee` + - `TransactionController:getLayer1GasFee` + - `TransactionController:clearUnapprovedTransactions` + - `TransactionController:abortTransactionSigning` + - `TransactionController:updateAtomicBatchData` + - Corresponding action types (e.g. `TransactionControllerHandleMethodDataAction`) are available as well. + +### Changed + +- **BREAKING:** Standardize names of `TransactionController` messenger action types ([#8183](https://github.com/MetaMask/core/pull/8183)) + - All existing types for messenger actions have been renamed so they end in `Action` (e.g. `TransactionControllerEmulateNewTransaction` -> `TransactionControllerEmulateNewTransactionAction`). 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 `TransactionController` messenger. - Bump `@metamask/core-backend` from `^6.1.0` to `^6.1.1` ([#8162](https://github.com/MetaMask/core/pull/8162)) ### Fixed diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index 92407767bfc..3eacf05d413 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -730,34 +730,34 @@ function getDefaultTransactionControllerState(): TransactionControllerState { // === MESSENGER === const MESSENGER_EXPOSED_METHODS = [ + 'abortTransactionSigning', 'addTransaction', 'addTransactionBatch', + 'approveTransactionsWithSameNonce', + 'clearUnapprovedTransactions', 'confirmExternalTransaction', 'emulateNewTransaction', 'emulateTransactionUpdate', 'estimateGas', 'estimateGasBatch', + 'estimateGasBuffered', + 'estimateGasFee', 'getGasFeeTokens', + 'getLayer1GasFee', 'getNonceLock', 'getTransactions', - 'updateCustodialTransaction', - 'updateTransaction', 'handleMethodData', 'isAtomicBatchSupported', + 'setTransactionActive', + 'speedUpTransaction', 'startIncomingTransactionPolling', 'stopIncomingTransactionPolling', - 'updateIncomingTransactions', 'stopTransaction', - 'speedUpTransaction', - 'estimateGasBuffered', - 'updateEditableParams', - 'setTransactionActive', - 'approveTransactionsWithSameNonce', - 'estimateGasFee', - 'getLayer1GasFee', - 'clearUnapprovedTransactions', - 'abortTransactionSigning', 'updateAtomicBatchData', + 'updateCustodialTransaction', + 'updateEditableParams', + 'updateIncomingTransactions', + 'updateTransaction', ] as const; /** @@ -2636,18 +2636,6 @@ export class TransactionController extends BaseController< }); } - /** - * Retrieve available gas fee tokens for a transaction. - * - * @param request - The request object containing transaction details. - * @returns The list of available gas fee tokens. - */ - async getGasFeeTokens( - request: GetGasFeeTokensRequest, - ): Promise { - return this.#getGasFeeTokensAction(request); - } - async #signExternalTransaction( chainId: Hex, transactionParams: TransactionParams, @@ -4734,7 +4722,13 @@ export class TransactionController extends BaseController< }); } - async #getGasFeeTokensAction( + /** + * Retrieve available gas fee tokens for a transaction. + * + * @param request - The request object containing transaction details. + * @returns The list of available gas fee tokens. + */ + async getGasFeeTokens( request: GetGasFeeTokensRequest, ): Promise { const { chainId, data, from, to, value } = request; diff --git a/packages/transaction-pay-controller/src/TransactionPayController.ts b/packages/transaction-pay-controller/src/TransactionPayController.ts index 6cf650df644..96938df0cd1 100644 --- a/packages/transaction-pay-controller/src/TransactionPayController.ts +++ b/packages/transaction-pay-controller/src/TransactionPayController.ts @@ -31,8 +31,8 @@ const MESSENGER_EXPOSED_METHODS = [ 'getDelegationTransaction', 'getStrategy', 'setTransactionConfig', - 'updatePaymentToken', 'updateFiatPayment', + 'updatePaymentToken', ] as const; const stateMetadata: StateMetadata = { diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index d44fc34cf05..745af9cd896 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -9,7 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New messenger actions: `UserOperationControllerAddUserOperationAction`, `UserOperationControllerAddUserOperationFromTransactionAction`, `UserOperationControllerStartPollingByNetworkClientIdAction` ([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `UserOperationController` methods through its messenger (([#8183](https://github.com/MetaMask/core/pull/8183)) + - The following actions are now available: + - `UserOperationController:addUserOperation` + - `UserOperationController:addUserOperationFromTransaction` + - `UserOperationController:startPollingByNetworkClientId` + - Corresponding action types (e.g. `UserOperationControllerAddUserOperationAction`) are available as well. ### Changed From cd2daacf2401ddf7f405d8eef96c9bb93b980fb0 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Thu, 12 Mar 2026 13:55:59 +0100 Subject: [PATCH 08/10] Sort ApprovalController MESSENGER_EXPOSED_METHODS alphabetically --- .../src/ApprovalController.ts | 20 +++++++------- ...ansactionController-method-action-types.ts | 26 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/approval-controller/src/ApprovalController.ts b/packages/approval-controller/src/ApprovalController.ts index 1811535bb12..0457c0aec89 100644 --- a/packages/approval-controller/src/ApprovalController.ts +++ b/packages/approval-controller/src/ApprovalController.ts @@ -63,22 +63,22 @@ const getDefaultState = (): ApprovalControllerState => { // === MESSENGER === const MESSENGER_EXPOSED_METHODS = [ - 'clearRequests', - 'addRequest', - 'hasRequest', 'acceptRequest', - 'rejectRequest', - 'updateRequestState', - 'startFlow', - 'endFlow', - 'setFlowLoadingText', - 'showSuccess', - 'showError', 'add', 'addAndShowApprovalRequest', + 'addRequest', + 'clearRequests', + 'endFlow', 'get', 'getApprovalCount', 'getTotalApprovalCount', + 'hasRequest', + 'rejectRequest', + 'setFlowLoadingText', + 'showError', + 'showSuccess', + 'startFlow', + 'updateRequestState', ] as const; // Internal Types diff --git a/packages/transaction-controller/src/TransactionController-method-action-types.ts b/packages/transaction-controller/src/TransactionController-method-action-types.ts index ed29b5f3057..7dd6e81c13e 100644 --- a/packages/transaction-controller/src/TransactionController-method-action-types.ts +++ b/packages/transaction-controller/src/TransactionController-method-action-types.ts @@ -286,17 +286,6 @@ export type TransactionControllerGetLayer1GasFeeAction = { handler: TransactionController['getLayer1GasFee']; }; -/** - * Retrieve available gas fee tokens for a transaction. - * - * @param request - The request object containing transaction details. - * @returns The list of available gas fee tokens. - */ -export type TransactionControllerGetGasFeeTokensAction = { - type: `TransactionController:getGasFeeTokens`; - handler: TransactionController['getGasFeeTokens']; -}; - /** * Removes unapproved transactions from state. */ @@ -350,6 +339,17 @@ export type TransactionControllerEmulateTransactionUpdateAction = { handler: TransactionController['emulateTransactionUpdate']; }; +/** + * Retrieve available gas fee tokens for a transaction. + * + * @param request - The request object containing transaction details. + * @returns The list of available gas fee tokens. + */ +export type TransactionControllerGetGasFeeTokensAction = { + type: `TransactionController:getGasFeeTokens`; + handler: TransactionController['getGasFeeTokens']; +}; + /** * Union of all TransactionController action types. */ @@ -376,9 +376,9 @@ export type TransactionControllerMethodActions = | TransactionControllerGetTransactionsAction | TransactionControllerEstimateGasFeeAction | TransactionControllerGetLayer1GasFeeAction - | TransactionControllerGetGasFeeTokensAction | TransactionControllerClearUnapprovedTransactionsAction | TransactionControllerAbortTransactionSigningAction | TransactionControllerUpdateAtomicBatchDataAction | TransactionControllerEmulateNewTransactionAction - | TransactionControllerEmulateTransactionUpdateAction; + | TransactionControllerEmulateTransactionUpdateAction + | TransactionControllerGetGasFeeTokensAction; From 6cb7e4bcfc29b5e7a8d8c630f56f1e8aa0e7b197 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Tue, 17 Mar 2026 10:34:19 +0100 Subject: [PATCH 09/10] fix: changelog --- packages/transaction-pay-controller/CHANGELOG.md | 2 +- packages/user-operation-controller/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/transaction-pay-controller/CHANGELOG.md b/packages/transaction-pay-controller/CHANGELOG.md index b635c02aedb..7f0019b8018 100644 --- a/packages/transaction-pay-controller/CHANGELOG.md +++ b/packages/transaction-pay-controller/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - **BREAKING:** Add `AssetsControllerGetStateForTransactionPayAction` to the `AllowedActions` messenger type ([#8163](https://github.com/MetaMask/core/pull/8163)) +- New public wrapper methods: `getDelegationTransaction()`, `getStrategy()` ([#8183](https://github.com/MetaMask/core/pull/8183)) ### Changed @@ -20,7 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- New public wrapper methods: `getDelegationTransaction()`, `getStrategy()` ([#8183](https://github.com/MetaMask/core/pull/8183)) - Support gasless Relay deposits via `execute` endpoint ([#8133](https://github.com/MetaMask/core/pull/8133)) - Build Across post-swap transfer actions for `predictDeposit` quotes so Predict deposits can bridge swapped output into the destination proxy wallet ([#8159](https://github.com/MetaMask/core/pull/8159)) diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index 745af9cd896..592f98e78a9 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Expose missing public `UserOperationController` methods through its messenger (([#8183](https://github.com/MetaMask/core/pull/8183)) +- Expose missing public `UserOperationController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183)) - The following actions are now available: - `UserOperationController:addUserOperation` - `UserOperationController:addUserOperationFromTransaction` From 33534a4382e6e659de6fff80eeaf5aa40af47490 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Tue, 17 Mar 2026 12:10:31 +0100 Subject: [PATCH 10/10] fix: changelog --- packages/transaction-pay-controller/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/transaction-pay-controller/CHANGELOG.md b/packages/transaction-pay-controller/CHANGELOG.md index 19d71196074..b6bbc662677 100644 --- a/packages/transaction-pay-controller/CHANGELOG.md +++ b/packages/transaction-pay-controller/CHANGELOG.md @@ -7,12 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- New public wrapper methods: `getDelegationTransaction()`, `getStrategy()` ([#8183](https://github.com/MetaMask/core/pull/8183)) + ## [17.0.0] ### Added - **BREAKING:** Add `AssetsControllerGetStateForTransactionPayAction` to the `AllowedActions` messenger type ([#8163](https://github.com/MetaMask/core/pull/8163)) -- New public wrapper methods: `getDelegationTransaction()`, `getStrategy()` ([#8183](https://github.com/MetaMask/core/pull/8183)) ### Changed