Skip to content

Commit da3b931

Browse files
authored
Add useTransactionSimulations preference (#4283)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR goal is to add `useTransactionSimulations` to `PreferencesController` ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? For example: * Fixes #12345 * Related to #67890 --> * Fixing part of MetaMask/mobile-planning#1720 ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/preferences-controller` - **ADDED**: Add `useTransactionSimulations` preference ## Checklist - [X] I've updated the test suite for new or updated code as appropriate - [X] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [X] I've highlighted breaking changes using the "BREAKING" category above as appropriate
1 parent 0119015 commit da3b931

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/preferences-controller/src/PreferencesController.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('PreferencesController', () => {
3030
isMultiAccountBalancesEnabled: true,
3131
showTestNetworks: false,
3232
isIpfsGatewayEnabled: true,
33+
useTransactionSimulations: true,
3334
showIncomingTransactions: Object.values(
3435
ETHERSCAN_SUPPORTED_CHAIN_IDS,
3536
).reduce((acc, curr) => {
@@ -415,6 +416,12 @@ describe('PreferencesController', () => {
415416
controller.setEnableNetworkIncomingTransactions('0x1', false);
416417
expect(controller.state.showIncomingTransactions['0x1']).toBe(false);
417418
});
419+
420+
it('should set useTransactionSimulations', () => {
421+
const controller = setupPreferencesController();
422+
controller.setUseTransactionSimulations(false);
423+
expect(controller.state.useTransactionSimulations).toBe(false);
424+
});
418425
});
419426

420427
/**

packages/preferences-controller/src/PreferencesController.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export type PreferencesState = {
108108
* Controls whether token detection is enabled
109109
*/
110110
useTokenDetection: boolean;
111+
/**
112+
* Controls whether transaction simulations are enabled
113+
*/
114+
useTransactionSimulations: boolean;
111115
};
112116

113117
const metadata = {
@@ -125,6 +129,7 @@ const metadata = {
125129
showIncomingTransactions: { persist: true, anonymous: true },
126130
useNftDetection: { persist: true, anonymous: true },
127131
useTokenDetection: { persist: true, anonymous: true },
132+
useTransactionSimulations: { persist: true, anonymous: true },
128133
};
129134

130135
const name = 'PreferencesController';
@@ -197,6 +202,7 @@ export function getDefaultPreferencesState() {
197202
showTestNetworks: false,
198203
useNftDetection: false,
199204
useTokenDetection: true,
205+
useTransactionSimulations: true,
200206
};
201207
}
202208

@@ -497,6 +503,17 @@ export class PreferencesController extends BaseController<
497503
});
498504
}
499505
}
506+
507+
/**
508+
* A setter for the user preferences to enable/disable transaction simulations.
509+
*
510+
* @param useTransactionSimulations - true to enable transaction simulations, false to disable it.
511+
*/
512+
setUseTransactionSimulations(useTransactionSimulations: boolean) {
513+
this.update((state) => {
514+
state.useTransactionSimulations = useTransactionSimulations;
515+
});
516+
}
500517
}
501518

502519
export default PreferencesController;

0 commit comments

Comments
 (0)