diff --git a/packages/snaps-rpc-methods/src/restricted/getPreferences.test.ts b/packages/snaps-rpc-methods/src/restricted/getPreferences.test.ts index 3966b4aec4..d809c57179 100644 --- a/packages/snaps-rpc-methods/src/restricted/getPreferences.test.ts +++ b/packages/snaps-rpc-methods/src/restricted/getPreferences.test.ts @@ -30,6 +30,13 @@ describe('snap_getPreferences', () => { locale: 'en', currency: 'usd', hideBalances: false, + useSecurityAlerts: true, + simulateOnChainActions: true, + useTokenDetection: true, + batchCheckBalances: true, + displayNftMedia: false, + useNftDetection: false, + useExternalPricingData: true, }), }; @@ -42,7 +49,18 @@ describe('snap_getPreferences', () => { }, method: 'snap_getPreferences', }), - ).toStrictEqual({ locale: 'en', currency: 'usd', hideBalances: false }); + ).toStrictEqual({ + locale: 'en', + currency: 'usd', + hideBalances: false, + useSecurityAlerts: true, + simulateOnChainActions: true, + useTokenDetection: true, + batchCheckBalances: true, + displayNftMedia: false, + useNftDetection: false, + useExternalPricingData: true, + }); }); }); }); diff --git a/packages/snaps-sdk/src/types/methods/get-preferences.ts b/packages/snaps-sdk/src/types/methods/get-preferences.ts index f0a3e16af2..d56ce3061e 100644 --- a/packages/snaps-sdk/src/types/methods/get-preferences.ts +++ b/packages/snaps-sdk/src/types/methods/get-preferences.ts @@ -13,9 +13,23 @@ export type GetPreferencesParams = never; * @property locale - The user's selected locale. * @property currency - The user's selected currency. * @property hideBalances - Whether the user has chosen to hide balances. + * @property useSecurityAlerts - Whether to run transactions and signatures through security providers. + * @property simulateOnChainActions - Whether to simulate transactions and signatures. + * @property useTokenDetection - Whether to auto-detect tokens. + * @property batchCheckBalances - Whether to fetch balances in an aggregated manner. + * @property displayNftMedia - Whether to display NFT media. + * @property useNftDetection - Whether to auto-detect NFTs. + * @property useExternalPricingData - Whether to get token price data from an external source. */ export type GetPreferencesResult = { locale: string; currency: string; hideBalances: boolean; + useSecurityAlerts: boolean; + simulateOnChainActions: boolean; + useTokenDetection: boolean; + batchCheckBalances: boolean; + displayNftMedia: boolean; + useNftDetection: boolean; + useExternalPricingData: boolean; }; diff --git a/packages/snaps-simulation/src/methods/hooks/get-preferences.test.ts b/packages/snaps-simulation/src/methods/hooks/get-preferences.test.ts index 3132a75027..0993566c01 100644 --- a/packages/snaps-simulation/src/methods/hooks/get-preferences.test.ts +++ b/packages/snaps-simulation/src/methods/hooks/get-preferences.test.ts @@ -13,6 +13,13 @@ describe('getGetPreferencesMethodImplementation', () => { currency: 'usd', locale: 'en', hideBalances: false, + useSecurityAlerts: true, + simulateOnChainActions: true, + useTokenDetection: true, + batchCheckBalances: true, + displayNftMedia: true, + useNftDetection: true, + useExternalPricingData: true, }); }); @@ -27,6 +34,13 @@ describe('getGetPreferencesMethodImplementation', () => { currency: 'usd', locale: 'nl', hideBalances: false, + useSecurityAlerts: true, + simulateOnChainActions: true, + useTokenDetection: true, + batchCheckBalances: true, + displayNftMedia: true, + useNftDetection: true, + useExternalPricingData: true, }); }); @@ -41,6 +55,13 @@ describe('getGetPreferencesMethodImplementation', () => { currency: 'dkk', locale: 'en', hideBalances: false, + useSecurityAlerts: true, + simulateOnChainActions: true, + useTokenDetection: true, + batchCheckBalances: true, + displayNftMedia: true, + useNftDetection: true, + useExternalPricingData: true, }); }); @@ -55,6 +76,13 @@ describe('getGetPreferencesMethodImplementation', () => { currency: 'usd', locale: 'en', hideBalances: true, + useSecurityAlerts: true, + simulateOnChainActions: true, + useTokenDetection: true, + batchCheckBalances: true, + displayNftMedia: true, + useNftDetection: true, + useExternalPricingData: true, }); }); }); diff --git a/packages/snaps-simulation/src/methods/hooks/get-preferences.ts b/packages/snaps-simulation/src/methods/hooks/get-preferences.ts index c6ffb4b180..f97b7db933 100644 --- a/packages/snaps-simulation/src/methods/hooks/get-preferences.ts +++ b/packages/snaps-simulation/src/methods/hooks/get-preferences.ts @@ -7,14 +7,39 @@ import type { SimulationOptions } from '../../options'; * @param options.currency - The currency to use. * @param options.locale - The locale to use. * @param options.hideBalances - Whether to hide balances. + * @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers. + * @param options.simulateOnChainActions - Whether to simulate transactions and signatures. + * @param options.useTokenDetection - Whether to auto-detect tokens. + * @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner. + * @param options.displayNftMedia - Whether to display NFT media. + * @param options.useNftDetection - Whether to auto-detect NFTs. + * @param options.useExternalPricingData - Whether to get token price data from an external source. * @returns The implementation of the `getPreferences` hook. */ export function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, + useSecurityAlerts, + simulateOnChainActions, + useTokenDetection, + batchCheckBalances, + displayNftMedia, + useNftDetection, + useExternalPricingData, }: SimulationOptions) { return () => { - return { currency, locale, hideBalances }; + return { + currency, + locale, + hideBalances, + useSecurityAlerts, + simulateOnChainActions, + useTokenDetection, + batchCheckBalances, + displayNftMedia, + useNftDetection, + useExternalPricingData, + }; }; } diff --git a/packages/snaps-simulation/src/options.test.ts b/packages/snaps-simulation/src/options.test.ts index 30e98adf0b..9864b5ab7e 100644 --- a/packages/snaps-simulation/src/options.test.ts +++ b/packages/snaps-simulation/src/options.test.ts @@ -6,12 +6,19 @@ describe('getOptions', () => { expect(options).toMatchInlineSnapshot(` { + "batchCheckBalances": true, "currency": "usd", + "displayNftMedia": true, "hideBalances": false, "locale": "en", "secretRecoveryPhrase": "test test test test test test test test test test test ball", + "simulateOnChainActions": true, "state": null, "unencryptedState": null, + "useExternalPricingData": true, + "useNftDetection": true, + "useSecurityAlerts": true, + "useTokenDetection": true, } `); }); @@ -24,12 +31,19 @@ describe('getOptions', () => { expect(options).toMatchInlineSnapshot(` { + "batchCheckBalances": true, "currency": "eur", + "displayNftMedia": true, "hideBalances": false, "locale": "nl", "secretRecoveryPhrase": "test test test test test test test test test test test ball", + "simulateOnChainActions": true, "state": null, "unencryptedState": null, + "useExternalPricingData": true, + "useNftDetection": true, + "useSecurityAlerts": true, + "useTokenDetection": true, } `); }); diff --git a/packages/snaps-simulation/src/options.ts b/packages/snaps-simulation/src/options.ts index baf322d7d3..17cf711cca 100644 --- a/packages/snaps-simulation/src/options.ts +++ b/packages/snaps-simulation/src/options.ts @@ -23,16 +23,31 @@ const SimulationOptionsStruct = object({ null, ), hideBalances: defaulted(optional(boolean()), false), + useSecurityAlerts: defaulted(optional(boolean()), true), + simulateOnChainActions: defaulted(optional(boolean()), true), + useTokenDetection: defaulted(optional(boolean()), true), + batchCheckBalances: defaulted(optional(boolean()), true), + displayNftMedia: defaulted(optional(boolean()), true), + useNftDetection: defaulted(optional(boolean()), true), + useExternalPricingData: defaulted(optional(boolean()), true), }); /** * Options for the simulation. * + * @property currency - The currency to use. Defaults to `usd`. * @property secretRecoveryPhrase - The secret recovery phrase to use. This is * used to derive addresses and private keys. Defaults to a test recovery * phrase. * @property locale - The locale to use. Defaults to `en`. * @property state - The initial state of the Snap, if any. Defaults to `null`. + * @property useSecurityAlerts - Whether to run transactions and signatures through security providers. + * @property simulateOnChainActions - Whether to simulate transactions and signatures. + * @property useTokenDetection - Whether to auto-detect tokens. + * @property batchCheckBalances - Whether to fetch balances in an aggregated manner. + * @property displayNftMedia - Whether to display NFT media. + * @property useNftDetection - Whether to auto-detect NFTs. + * @property useExternalPricingData - Whether to get token price data from an external source. */ export type SimulationUserOptions = Infer; diff --git a/packages/snaps-simulation/src/test-utils/options.ts b/packages/snaps-simulation/src/test-utils/options.ts index bd680eb633..ad2f5fb56f 100644 --- a/packages/snaps-simulation/src/test-utils/options.ts +++ b/packages/snaps-simulation/src/test-utils/options.ts @@ -11,6 +11,13 @@ import type { SimulationOptions } from '../options'; * @param options.state - The state to use. * @param options.unencryptedState - The unencrypted state to use. * @param options.hideBalances - Whether to hide balances. + * @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers. + * @param options.simulateOnChainActions - Whether to simulate transactions and signatures. + * @param options.useTokenDetection - Whether to auto-detect tokens. + * @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner. + * @param options.displayNftMedia - Whether to display NFT media. + * @param options.useNftDetection - Whether to auto-detect NFTs. + * @param options.useExternalPricingData - Whether to get token price data from an external source. * @returns The options for the simulation. */ export function getMockOptions({ @@ -20,6 +27,13 @@ export function getMockOptions({ secretRecoveryPhrase = DEFAULT_SRP, state = null, unencryptedState = null, + useSecurityAlerts = true, + simulateOnChainActions = true, + useTokenDetection = true, + batchCheckBalances = true, + displayNftMedia = true, + useNftDetection = true, + useExternalPricingData = true, }: Partial = {}): SimulationOptions { return { currency, @@ -28,5 +42,12 @@ export function getMockOptions({ state, unencryptedState, hideBalances, + useSecurityAlerts, + simulateOnChainActions, + useTokenDetection, + batchCheckBalances, + displayNftMedia, + useNftDetection, + useExternalPricingData, }; } diff --git a/packages/snaps-simulator/src/features/simulation/sagas.ts b/packages/snaps-simulator/src/features/simulation/sagas.ts index bac4b699a3..a81e95b95b 100644 --- a/packages/snaps-simulator/src/features/simulation/sagas.ts +++ b/packages/snaps-simulator/src/features/simulation/sagas.ts @@ -131,6 +131,13 @@ export function* initSaga({ payload }: PayloadAction) { locale: 'en', currency: 'usd', hideBalances: false, + useSecurityAlerts: true, + simulateOnChainActions: true, + useTokenDetection: true, + batchCheckBalances: true, + displayNftMedia: true, + useNftDetection: true, + useExternalPricingData: true, }), getUnlockPromise: async () => Promise.resolve(true), showDialog: async (...args: Parameters) =>