Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
};

Expand All @@ -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,
});
});
});
});
14 changes: 14 additions & 0 deletions packages/snaps-sdk/src/types/methods/get-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});

Expand All @@ -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,
});
});

Expand All @@ -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,
});
});

Expand All @@ -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,
});
});
});
27 changes: 26 additions & 1 deletion packages/snaps-simulation/src/methods/hooks/get-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
}
14 changes: 14 additions & 0 deletions packages/snaps-simulation/src/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
`);
});
Expand All @@ -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,
}
`);
});
Expand Down
15 changes: 15 additions & 0 deletions packages/snaps-simulation/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof SimulationOptionsStruct>;

Expand Down
21 changes: 21 additions & 0 deletions packages/snaps-simulation/src/test-utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -20,6 +27,13 @@ export function getMockOptions({
secretRecoveryPhrase = DEFAULT_SRP,
state = null,
unencryptedState = null,
useSecurityAlerts = true,
Copy link
Member

Choose a reason for hiding this comment

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

Now is the time I really wished we put these options somewhere else @Mrtenz 😅

simulateOnChainActions = true,
useTokenDetection = true,
batchCheckBalances = true,
displayNftMedia = true,
useNftDetection = true,
useExternalPricingData = true,
}: Partial<SimulationOptions> = {}): SimulationOptions {
return {
currency,
Expand All @@ -28,5 +42,12 @@ export function getMockOptions({
state,
unencryptedState,
hideBalances,
useSecurityAlerts,
simulateOnChainActions,
useTokenDetection,
batchCheckBalances,
displayNftMedia,
useNftDetection,
useExternalPricingData,
};
}
7 changes: 7 additions & 0 deletions packages/snaps-simulator/src/features/simulation/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ export function* initSaga({ payload }: PayloadAction<string>) {
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<typeof showDialog>) =>
Expand Down
Loading