Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/transaction-controller/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

- Add `txMeta` property to `GetSimulationConfig` callback ([#6833](https://github.com/MetaMask/core/pull/6833))

## [60.6.1]

### Changed
Expand Down
1 change: 1 addition & 0 deletions packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@metamask/gas-fee-controller": "^24.1.0",
"@metamask/network-controller": "^24.2.1",
"@metamask/remote-feature-flag-controller": "^1.8.0",
"@ts-bridge/cli": "^0.6.1",
"@types/bn.js": "^5.1.5",
"@types/jest": "^27.4.1",
"@types/node": "^16.18.54",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2385,8 +2385,11 @@ describe('TransactionController', () => {

describe('updates simulation data', () => {
it('by default', async () => {
getBalanceChangesMock.mockResolvedValueOnce({
simulationData: SIMULATION_DATA_RESULT_MOCK,
getBalanceChangesMock.mockImplementationOnce(async (request) => {
await request.getSimulationConfig('https://testurl.com');
return {
simulationData: SIMULATION_DATA_RESULT_MOCK,
};
});

const { controller } = setupController();
Expand Down Expand Up @@ -2449,8 +2452,11 @@ describe('TransactionController', () => {
});

it('with getSimulationConfig', async () => {
getBalanceChangesMock.mockResolvedValueOnce({
simulationData: SIMULATION_DATA_RESULT_MOCK,
getBalanceChangesMock.mockImplementationOnce(async (request) => {
await request.getSimulationConfig('https://testurl.com');
return {
simulationData: SIMULATION_DATA_RESULT_MOCK,
};
});

const getSimulationConfigMock: GetSimulationConfig = jest
Expand Down Expand Up @@ -2478,10 +2484,23 @@ describe('TransactionController', () => {
expect(getBalanceChangesMock).toHaveBeenCalledTimes(1);
expect(getBalanceChangesMock).toHaveBeenCalledWith(
expect.objectContaining({
getSimulationConfig: getSimulationConfigMock,
getSimulationConfig: expect.any(Function),
}),
);

expect(getSimulationConfigMock).toHaveBeenCalledTimes(1);
expect(getSimulationConfigMock).toHaveBeenCalledWith(
'https://testurl.com',
{
txMeta: expect.objectContaining({
txParams: expect.objectContaining({
from: ACCOUNT_MOCK,
to: ACCOUNT_MOCK,
}),
}),
},
);

expect(controller.state.transactions[0].simulationData).toStrictEqual(
SIMULATION_DATA_RESULT_MOCK,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4164,7 +4164,12 @@ export class TransactionController extends BaseController<
blockTime,
chainId,
ethQuery: this.#getEthQuery({ networkClientId }),
getSimulationConfig: this.#getSimulationConfig,
getSimulationConfig: (url, opts) => {
return this.#getSimulationConfig(url, {
txMeta: transactionMeta,
...opts,
});
},
Copy link

Choose a reason for hiding this comment

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

Bug: Transaction Meta Override Issue

In the getSimulationConfig wrapper, the object spread order ({ txMeta: transactionMeta, ...opts }) allows opts.txMeta to override the controller's transactionMeta. This prevents the simulation from consistently using the current transaction's intended context.

Fix in Cursor Fix in Web

nestedTransactions,
txParams,
}),
Expand Down
7 changes: 6 additions & 1 deletion packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,12 @@ export type MetamaskPayMetadata = {
/**
* Parameters for the transaction simulation API.
*/
export type GetSimulationConfig = (url: string) => Promise<{
export type GetSimulationConfig = (
url: string,
opts?: {
txMeta?: TransactionMeta;
},
) => Promise<{
newUrl?: string;
authorization?: string;
}>;
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4986,6 +4986,7 @@ __metadata:
"@metamask/remote-feature-flag-controller": "npm:^1.8.0"
"@metamask/rpc-errors": "npm:^7.0.2"
"@metamask/utils": "npm:^11.8.1"
"@ts-bridge/cli": "npm:^0.6.1"
"@types/bn.js": "npm:^5.1.5"
"@types/jest": "npm:^27.4.1"
"@types/node": "npm:^16.18.54"
Expand Down
Loading