Skip to content
Open
4 changes: 4 additions & 0 deletions packages/eip-5792-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Id of JSON RPC request is passed to functions to create batched transaction, id is thus added to transaction meta ([#7415](https://github.com/MetaMask/core/pull/7415))

### Changed

- Bump `@metamask/transaction-controller` from `^61.3.0` to `^62.5.0` ([#7007](https://github.com/MetaMask/core/pull/7007), [#7126](https://github.com/MetaMask/core/pull/7126), [#7153](https://github.com/MetaMask/core/pull/7153), [#7202](https://github.com/MetaMask/core/pull/7202), [#7215](https://github.com/MetaMask/core/pull/7202), [#7220](https://github.com/MetaMask/core/pull/7220), [#7236](https://github.com/MetaMask/core/pull/7236), [#7257](https://github.com/MetaMask/core/pull/7257), [#7289](https://github.com/MetaMask/core/pull/7289), [#7325](https://github.com/MetaMask/core/pull/7325))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ describe('EIP-5792', () => {
from: SEND_CALLS_MOCK.from,
networkClientId: NETWORK_CLIENT_ID_MOCK,
origin: ORIGIN_MOCK,
requestId: '1',
securityAlertId: expect.any(String),
transactions: [
{ params: SEND_CALLS_MOCK.calls[0] },
Expand Down Expand Up @@ -237,6 +238,7 @@ describe('EIP-5792', () => {
batchId: expect.any(String),
networkClientId: 'test-client',
origin: 'test.com',
requestId: '1',
securityAlertResponse: {
securityAlertId: expect.any(String),
},
Expand Down
12 changes: 12 additions & 0 deletions packages/eip-5792-middleware/src/hooks/processSendCalls.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to note additions in changelog on this package and transaction-controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, let me do that.

Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export async function processSendCalls(
const securityAlertId = uuid();
const validateSecurity = validateSecurityHook.bind(null, securityAlertId);

const requestId = req.id ? String(req.id) : '';

let batchId: Hex;
if (Object.keys(transactions).length === 1) {
batchId = await processSingleTransaction({
Expand All @@ -110,6 +112,7 @@ export async function processSendCalls(
messenger,
networkClientId,
origin,
requestId,
securityAlertId,
sendCalls: params,
transactions,
Expand All @@ -126,6 +129,7 @@ export async function processSendCalls(
messenger,
networkClientId,
origin,
requestId,
sendCalls: params,
securityAlertId,
transactions,
Expand All @@ -147,6 +151,7 @@ export async function processSendCalls(
* @param params.messenger - Messenger instance for controller communication.
* @param params.networkClientId - The network client ID.
* @param params.origin - The origin of the request (optional).
* @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.
* @param params.securityAlertId - The security alert ID for this transaction.
* @param params.sendCalls - The original sendCalls request.
* @param params.transactions - Array containing the single transaction.
Expand All @@ -161,6 +166,7 @@ async function processSingleTransaction({
messenger,
networkClientId,
origin,
requestId,
securityAlertId,
sendCalls,
transactions,
Expand All @@ -173,6 +179,7 @@ async function processSingleTransaction({
messenger: EIP5792Messenger;
networkClientId: string;
origin?: string;
requestId?: string;
securityAlertId: string;
sendCalls: SendCallsPayload;
transactions: { params: BatchTransactionParams }[];
Expand Down Expand Up @@ -209,6 +216,7 @@ async function processSingleTransaction({
const batchId = generateBatchId();

await addTransaction(txParams, {
requestId,
networkClientId,
origin,
securityAlertResponse: { securityAlertId } as SecurityAlertResponse,
Expand All @@ -229,6 +237,7 @@ async function processSingleTransaction({
* @param params.networkClientId - The network client ID.
* @param params.messenger - Messenger instance for controller communication.
* @param params.origin - The origin of the request (optional).
* @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.
* @param params.sendCalls - The original sendCalls request.
* @param params.securityAlertId - The security alert ID for this batch.
* @param params.transactions - Array of transactions to process.
Expand All @@ -245,6 +254,7 @@ async function processMultipleTransaction({
networkClientId,
messenger,
origin,
requestId,
sendCalls,
securityAlertId,
transactions,
Expand All @@ -259,6 +269,7 @@ async function processMultipleTransaction({
messenger: EIP5792Messenger;
networkClientId: string;
origin?: string;
requestId?: string;
sendCalls: SendCallsPayload;
securityAlertId: string;
transactions: { params: BatchTransactionParams }[];
Expand Down Expand Up @@ -295,6 +306,7 @@ async function processMultipleTransaction({
from,
networkClientId,
origin,
requestId,
securityAlertId,
transactions,
validateSecurity,
Expand Down
1 change: 1 addition & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add optional `isTimeoutEnabled` callback to disable for specific transactions.
- Ignores transactions with future nonce.
- Threshold determined by feature flag.
- Adding a new transaction meta property `requestId`. It is supported for both simple and batched transactions ([#7415](https://github.com/MetaMask/core/pull/7415))

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,7 @@ describe('TransactionController', () => {
nestedTransactions: undefined,
networkClientId: NETWORK_CLIENT_ID_MOCK,
origin: undefined,
requestId: undefined,
securityAlertResponse: undefined,
selectedGasFeeToken: undefined,
sendFlowHistory: expect.any(Array),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ export class TransactionController extends BaseController<
networkClientId,
origin,
publishHook,
requestId,
requireApproval,
securityAlertResponse,
sendFlowHistory,
Expand Down Expand Up @@ -1377,6 +1378,7 @@ export class TransactionController extends BaseController<
nestedTransactions,
networkClientId,
origin,
requestId,
securityAlertResponse,
selectedGasFeeToken: gasFeeToken,
status: TransactionStatus.unapproved as const,
Expand Down
16 changes: 16 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ export type TransactionMeta = {
*/
replacedById?: string;

/**
* ID of JSON-RPC request from DAPP.
*/
requestId?: string;

/**
* IDs of any transactions that must be confirmed before this one is submitted.
* Unlike a transaction batch, these transactions can be on alternate chains.
Expand Down Expand Up @@ -592,6 +597,11 @@ export type TransactionBatchMeta = {
*/
origin?: string;

/**
* ID of the JSON-RPC request from DAPP.
*/
requestId?: string;

/** Current status of the transaction. */
status: TransactionStatus;

Expand Down Expand Up @@ -1762,6 +1772,9 @@ export type TransactionBatchRequest = {
/** Whether to overwrite existing EIP-7702 delegation with MetaMask contract. */
overwriteUpgrade?: boolean;

/** ID of the JSON-RPC request from DAPP. */
requestId?: string;

/** Whether an approval request should be created to require confirmation from the user. */
requireApproval?: boolean;

Expand Down Expand Up @@ -2115,6 +2128,9 @@ export type AddTransactionOptions = {
/** Custom logic to publish the transaction. */
publishHook?: PublishHook;

/** ID of JSON-RPC request from DAPP. */
requestId?: string;

/** Whether the transaction requires approval by the user, defaults to true unless explicitly disabled. */
requireApproval?: boolean | undefined;

Expand Down
5 changes: 5 additions & 0 deletions packages/transaction-controller/src/utils/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type AddTransactionBatchRequest = {
) => Promise<Hex>;
publicKeyEIP7702?: Hex;
request: TransactionBatchRequest;
requestId?: string;
signTransaction: (
transactionMeta: TransactionMeta,
) => Promise<string | undefined>;
Expand Down Expand Up @@ -301,6 +302,7 @@ async function addTransactionBatchWith7702(
networkClientId,
origin,
overwriteUpgrade,
requestId,
requireApproval,
securityAlertId,
skipInitialGasEstimate,
Expand Down Expand Up @@ -432,6 +434,7 @@ async function addTransactionBatchWith7702(
nestedTransactions,
networkClientId,
origin,
requestId,
requireApproval,
securityAlertResponse,
skipInitialGasEstimate,
Expand Down Expand Up @@ -856,6 +859,7 @@ async function prepareApprovalData({
origin,
networkClientId,
transactions: nestedTransactions,
requestId,
} = userRequest;

const ethQuery = getEthQuery(networkClientId);
Expand Down Expand Up @@ -883,6 +887,7 @@ async function prepareApprovalData({
networkClientId,
origin,
transactions: nestedTransactions,
requestId,
});

const defaultGasFeeFlow = new DefaultGasFeeFlow();
Expand Down