Skip to content

Commit 85e928e

Browse files
authored
chore: Migrate Confirmations-involved legacy API method calls to messengers (#47326)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> Currently, the background process aggregates methods from various controllers and services into an API object, and the UI calls a method on this object by passing its name and arguments to `submitRequestToBackground`. The "root" messenger — the messenger for MetamaskController — is meant to replace this API, and we want to transition to it by replacing `submitRequestToBackground` calls so that they pass action type strings (e.g. `NetworkController:addNetwork`) instead of method names (e.g. `addNetwork`). Then, eventually, we want to remove the original methods from the legacy API object. This PR is one of a series of PRs which aims to unlock this refactor. The tactic used to create this PR was to look for `submitRequestToBackground` calls in controllers, services, and files owned by the Confirmations team (although the changes may have affected other files as well). Most of the migrations that would have taken place in this commit have already happened in a previous one. As a result, the following API methods have been removed from the TransactionController init file: - `getLayer1GasFee` - `getTransactions` - `isAtomicBatchSupported` - `updateAtomicBatchData` - `updateEditableParams` - `updatePreviousGasParams` - `updateSelectedGasFeeToken` - `updateTransactionGasFees` Calls for the following API methods defined within `MetamaskController.getApi` were migrated to use messenger action type strings: - `updateTransaction` (-> `TransactionController:updateTransaction`) Calls for the following API methods defined within the TransactionController wallet library config file were not migrated for the following reasons: - `abortTransactionSigning` (is used by hardware wallets, and will be migrated later) - `updateBatchTransactions` (not registered on the messenger) - `checkFirstTimeInteraction` (not registered on the messenger) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** https://consensyssoftware.atlassian.net/browse/WPC-1426 ## **Manual testing steps** This PR should have no functional changes. All flows should work like they do today, and the changes here should be covered by tests. ## **Screenshots/Recordings** (N/A) ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches transaction persistence and gas-fee update IPC paths in confirmations; behavior should be unchanged but regressions would affect signing and approval flows. > > **Overview** > Continues the move from the legacy background API to **messenger action strings** for Confirmations-related transaction work. > > **Legacy API cleanup:** `getTransactionControllerApi` no longer exposes eight `TransactionController` methods (`getLayer1GasFee`, `getTransactions`, atomic-batch and gas-fee updaters, etc.); callers are expected to use the corresponding `TransactionController:*` messenger actions instead. **`updateBatchTransactions`** and **`checkFirstTimeInteraction`** remain on the legacy surface. > > **UI call sites:** Money Account withdraw persistence now invokes **`TransactionController:updateTransaction`** (not `updateTransaction`) and passes a note string, **`Prepared Money Account withdrawal for approval`**, alongside the transaction meta; tests assert that shape. > > **Gas fees thunk:** The background request was already **`TransactionController:updateTransactionGasFees`**; the change replaces a `@ts-expect-error` with an explicit cast for the **`userEditedGasLimit`** string vs boolean mismatch. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c8e1ac3. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent cf3309c commit 85e928e

4 files changed

Lines changed: 18 additions & 32 deletions

File tree

‎app/scripts/wallet-init/instance-options/transaction-controller.ts‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,35 +175,9 @@ export function getTransactionControllerApi(
175175
transactionController: TransactionController,
176176
) {
177177
return {
178-
getLayer1GasFee: transactionController.getLayer1GasFee.bind(
179-
transactionController,
180-
),
181-
getTransactions: transactionController.getTransactions.bind(
182-
transactionController,
183-
),
184-
isAtomicBatchSupported: transactionController.isAtomicBatchSupported.bind(
185-
transactionController,
186-
),
187-
updateAtomicBatchData: transactionController.updateAtomicBatchData.bind(
188-
transactionController,
189-
),
190178
updateBatchTransactions: transactionController.updateBatchTransactions.bind(
191179
transactionController,
192180
),
193-
updateEditableParams: transactionController.updateEditableParams.bind(
194-
transactionController,
195-
),
196-
updatePreviousGasParams: transactionController.updatePreviousGasParams.bind(
197-
transactionController,
198-
),
199-
updateSelectedGasFeeToken:
200-
transactionController.updateSelectedGasFeeToken.bind(
201-
transactionController,
202-
),
203-
updateTransactionGasFees:
204-
transactionController.updateTransactionGasFees.bind(
205-
transactionController,
206-
),
207181
checkFirstTimeInteraction,
208182
};
209183
}

‎ui/pages/confirmations/hooks/transactions/useMoneyAccountWithdrawConfirm.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ describe('useMoneyAccountWithdrawConfirm', () => {
152152
await prepareWithdrawTransaction(buildTransaction(FUNDED_NESTED));
153153

154154
expect(mockSubmitRequestToBackground).toHaveBeenCalledWith(
155-
'updateTransaction',
156-
[expect.objectContaining({ id: TRANSACTION_ID })],
155+
'TransactionController:updateTransaction',
156+
[
157+
expect.objectContaining({ id: TRANSACTION_ID }),
158+
'Prepared Money Account withdrawal for approval',
159+
],
157160
);
158161
});
159162

‎ui/pages/confirmations/hooks/transactions/useMoneyAccountWithdrawConfirm.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import { useTransactionAccountOverride } from './useTransactionAccountOverride';
2525
async function persistWithdrawTransaction(
2626
transaction: TransactionMeta,
2727
): Promise<void> {
28-
await submitRequestToBackground('updateTransaction', [transaction]);
28+
await submitRequestToBackground('TransactionController:updateTransaction', [
29+
transaction,
30+
'Prepared Money Account withdrawal for approval',
31+
]);
2932
}
3033

3134
async function finalizePreparedWithdraw(

‎ui/store/actions/update-transaction-gas-fees.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ export function updateTransactionGasFees(
1919
return async () => {
2020
let updatedTransaction: TransactionMeta;
2121
try {
22-
// @ts-expect-error TODO: The type of `userEditedGasLimit` in `TxGasFees`
23-
// is a string, but `updateTransactionGasFees` wants a boolean.
2422
updatedTransaction = await submitRequestToBackground(
2523
'TransactionController:updateTransactionGasFees',
26-
[txId, txGasFees],
24+
[
25+
txId,
26+
// TODO: `userEditedGasLimit` in `TxGasFees` is a string, but the same
27+
// argument in `TransactionController.updateTransactionGasFees` wants
28+
// a boolean.
29+
txGasFees as Omit<Partial<TxGasFees>, 'userEditedGasLimit'> & {
30+
userEditedGasLimit?: boolean;
31+
},
32+
],
2733
);
2834
} catch (error) {
2935
logErrorWithMessage(error);

0 commit comments

Comments
 (0)