Skip to content

Commit d7e2167

Browse files
authored
Update snap_getPreferences (#3093)
Updating `snap_getPreferences` return type to include additional properties. Closes #3076
1 parent f17d19d commit d7e2167

File tree

8 files changed

+144
-2
lines changed

8 files changed

+144
-2
lines changed

packages/snaps-rpc-methods/src/restricted/getPreferences.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ describe('snap_getPreferences', () => {
3030
locale: 'en',
3131
currency: 'usd',
3232
hideBalances: false,
33+
useSecurityAlerts: true,
34+
simulateOnChainActions: true,
35+
useTokenDetection: true,
36+
batchCheckBalances: true,
37+
displayNftMedia: false,
38+
useNftDetection: false,
39+
useExternalPricingData: true,
3340
}),
3441
};
3542

@@ -42,7 +49,18 @@ describe('snap_getPreferences', () => {
4249
},
4350
method: 'snap_getPreferences',
4451
}),
45-
).toStrictEqual({ locale: 'en', currency: 'usd', hideBalances: false });
52+
).toStrictEqual({
53+
locale: 'en',
54+
currency: 'usd',
55+
hideBalances: false,
56+
useSecurityAlerts: true,
57+
simulateOnChainActions: true,
58+
useTokenDetection: true,
59+
batchCheckBalances: true,
60+
displayNftMedia: false,
61+
useNftDetection: false,
62+
useExternalPricingData: true,
63+
});
4664
});
4765
});
4866
});

packages/snaps-sdk/src/types/methods/get-preferences.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ export type GetPreferencesParams = never;
1313
* @property locale - The user's selected locale.
1414
* @property currency - The user's selected currency.
1515
* @property hideBalances - Whether the user has chosen to hide balances.
16+
* @property useSecurityAlerts - Whether to run transactions and signatures through security providers.
17+
* @property simulateOnChainActions - Whether to simulate transactions and signatures.
18+
* @property useTokenDetection - Whether to auto-detect tokens.
19+
* @property batchCheckBalances - Whether to fetch balances in an aggregated manner.
20+
* @property displayNftMedia - Whether to display NFT media.
21+
* @property useNftDetection - Whether to auto-detect NFTs.
22+
* @property useExternalPricingData - Whether to get token price data from an external source.
1623
*/
1724
export type GetPreferencesResult = {
1825
locale: string;
1926
currency: string;
2027
hideBalances: boolean;
28+
useSecurityAlerts: boolean;
29+
simulateOnChainActions: boolean;
30+
useTokenDetection: boolean;
31+
batchCheckBalances: boolean;
32+
displayNftMedia: boolean;
33+
useNftDetection: boolean;
34+
useExternalPricingData: boolean;
2135
};

packages/snaps-simulation/src/methods/hooks/get-preferences.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ describe('getGetPreferencesMethodImplementation', () => {
1313
currency: 'usd',
1414
locale: 'en',
1515
hideBalances: false,
16+
useSecurityAlerts: true,
17+
simulateOnChainActions: true,
18+
useTokenDetection: true,
19+
batchCheckBalances: true,
20+
displayNftMedia: true,
21+
useNftDetection: true,
22+
useExternalPricingData: true,
1623
});
1724
});
1825

@@ -27,6 +34,13 @@ describe('getGetPreferencesMethodImplementation', () => {
2734
currency: 'usd',
2835
locale: 'nl',
2936
hideBalances: false,
37+
useSecurityAlerts: true,
38+
simulateOnChainActions: true,
39+
useTokenDetection: true,
40+
batchCheckBalances: true,
41+
displayNftMedia: true,
42+
useNftDetection: true,
43+
useExternalPricingData: true,
3044
});
3145
});
3246

@@ -41,6 +55,13 @@ describe('getGetPreferencesMethodImplementation', () => {
4155
currency: 'dkk',
4256
locale: 'en',
4357
hideBalances: false,
58+
useSecurityAlerts: true,
59+
simulateOnChainActions: true,
60+
useTokenDetection: true,
61+
batchCheckBalances: true,
62+
displayNftMedia: true,
63+
useNftDetection: true,
64+
useExternalPricingData: true,
4465
});
4566
});
4667

@@ -55,6 +76,13 @@ describe('getGetPreferencesMethodImplementation', () => {
5576
currency: 'usd',
5677
locale: 'en',
5778
hideBalances: true,
79+
useSecurityAlerts: true,
80+
simulateOnChainActions: true,
81+
useTokenDetection: true,
82+
batchCheckBalances: true,
83+
displayNftMedia: true,
84+
useNftDetection: true,
85+
useExternalPricingData: true,
5886
});
5987
});
6088
});

packages/snaps-simulation/src/methods/hooks/get-preferences.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,39 @@ import type { SimulationOptions } from '../../options';
77
* @param options.currency - The currency to use.
88
* @param options.locale - The locale to use.
99
* @param options.hideBalances - Whether to hide balances.
10+
* @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers.
11+
* @param options.simulateOnChainActions - Whether to simulate transactions and signatures.
12+
* @param options.useTokenDetection - Whether to auto-detect tokens.
13+
* @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner.
14+
* @param options.displayNftMedia - Whether to display NFT media.
15+
* @param options.useNftDetection - Whether to auto-detect NFTs.
16+
* @param options.useExternalPricingData - Whether to get token price data from an external source.
1017
* @returns The implementation of the `getPreferences` hook.
1118
*/
1219
export function getGetPreferencesMethodImplementation({
1320
currency,
1421
locale,
1522
hideBalances,
23+
useSecurityAlerts,
24+
simulateOnChainActions,
25+
useTokenDetection,
26+
batchCheckBalances,
27+
displayNftMedia,
28+
useNftDetection,
29+
useExternalPricingData,
1630
}: SimulationOptions) {
1731
return () => {
18-
return { currency, locale, hideBalances };
32+
return {
33+
currency,
34+
locale,
35+
hideBalances,
36+
useSecurityAlerts,
37+
simulateOnChainActions,
38+
useTokenDetection,
39+
batchCheckBalances,
40+
displayNftMedia,
41+
useNftDetection,
42+
useExternalPricingData,
43+
};
1944
};
2045
}

packages/snaps-simulation/src/options.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ describe('getOptions', () => {
66

77
expect(options).toMatchInlineSnapshot(`
88
{
9+
"batchCheckBalances": true,
910
"currency": "usd",
11+
"displayNftMedia": true,
1012
"hideBalances": false,
1113
"locale": "en",
1214
"secretRecoveryPhrase": "test test test test test test test test test test test ball",
15+
"simulateOnChainActions": true,
1316
"state": null,
1417
"unencryptedState": null,
18+
"useExternalPricingData": true,
19+
"useNftDetection": true,
20+
"useSecurityAlerts": true,
21+
"useTokenDetection": true,
1522
}
1623
`);
1724
});
@@ -24,12 +31,19 @@ describe('getOptions', () => {
2431

2532
expect(options).toMatchInlineSnapshot(`
2633
{
34+
"batchCheckBalances": true,
2735
"currency": "eur",
36+
"displayNftMedia": true,
2837
"hideBalances": false,
2938
"locale": "nl",
3039
"secretRecoveryPhrase": "test test test test test test test test test test test ball",
40+
"simulateOnChainActions": true,
3141
"state": null,
3242
"unencryptedState": null,
43+
"useExternalPricingData": true,
44+
"useNftDetection": true,
45+
"useSecurityAlerts": true,
46+
"useTokenDetection": true,
3347
}
3448
`);
3549
});

packages/snaps-simulation/src/options.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,31 @@ const SimulationOptionsStruct = object({
2323
null,
2424
),
2525
hideBalances: defaulted(optional(boolean()), false),
26+
useSecurityAlerts: defaulted(optional(boolean()), true),
27+
simulateOnChainActions: defaulted(optional(boolean()), true),
28+
useTokenDetection: defaulted(optional(boolean()), true),
29+
batchCheckBalances: defaulted(optional(boolean()), true),
30+
displayNftMedia: defaulted(optional(boolean()), true),
31+
useNftDetection: defaulted(optional(boolean()), true),
32+
useExternalPricingData: defaulted(optional(boolean()), true),
2633
});
2734

2835
/**
2936
* Options for the simulation.
3037
*
38+
* @property currency - The currency to use. Defaults to `usd`.
3139
* @property secretRecoveryPhrase - The secret recovery phrase to use. This is
3240
* used to derive addresses and private keys. Defaults to a test recovery
3341
* phrase.
3442
* @property locale - The locale to use. Defaults to `en`.
3543
* @property state - The initial state of the Snap, if any. Defaults to `null`.
44+
* @property useSecurityAlerts - Whether to run transactions and signatures through security providers.
45+
* @property simulateOnChainActions - Whether to simulate transactions and signatures.
46+
* @property useTokenDetection - Whether to auto-detect tokens.
47+
* @property batchCheckBalances - Whether to fetch balances in an aggregated manner.
48+
* @property displayNftMedia - Whether to display NFT media.
49+
* @property useNftDetection - Whether to auto-detect NFTs.
50+
* @property useExternalPricingData - Whether to get token price data from an external source.
3651
*/
3752
export type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;
3853

packages/snaps-simulation/src/test-utils/options.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import type { SimulationOptions } from '../options';
1111
* @param options.state - The state to use.
1212
* @param options.unencryptedState - The unencrypted state to use.
1313
* @param options.hideBalances - Whether to hide balances.
14+
* @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers.
15+
* @param options.simulateOnChainActions - Whether to simulate transactions and signatures.
16+
* @param options.useTokenDetection - Whether to auto-detect tokens.
17+
* @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner.
18+
* @param options.displayNftMedia - Whether to display NFT media.
19+
* @param options.useNftDetection - Whether to auto-detect NFTs.
20+
* @param options.useExternalPricingData - Whether to get token price data from an external source.
1421
* @returns The options for the simulation.
1522
*/
1623
export function getMockOptions({
@@ -20,6 +27,13 @@ export function getMockOptions({
2027
secretRecoveryPhrase = DEFAULT_SRP,
2128
state = null,
2229
unencryptedState = null,
30+
useSecurityAlerts = true,
31+
simulateOnChainActions = true,
32+
useTokenDetection = true,
33+
batchCheckBalances = true,
34+
displayNftMedia = true,
35+
useNftDetection = true,
36+
useExternalPricingData = true,
2337
}: Partial<SimulationOptions> = {}): SimulationOptions {
2438
return {
2539
currency,
@@ -28,5 +42,12 @@ export function getMockOptions({
2842
state,
2943
unencryptedState,
3044
hideBalances,
45+
useSecurityAlerts,
46+
simulateOnChainActions,
47+
useTokenDetection,
48+
batchCheckBalances,
49+
displayNftMedia,
50+
useNftDetection,
51+
useExternalPricingData,
3152
};
3253
}

packages/snaps-simulator/src/features/simulation/sagas.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ export function* initSaga({ payload }: PayloadAction<string>) {
131131
locale: 'en',
132132
currency: 'usd',
133133
hideBalances: false,
134+
useSecurityAlerts: true,
135+
simulateOnChainActions: true,
136+
useTokenDetection: true,
137+
batchCheckBalances: true,
138+
displayNftMedia: true,
139+
useNftDetection: true,
140+
useExternalPricingData: true,
134141
}),
135142
getUnlockPromise: async () => Promise.resolve(true),
136143
showDialog: async (...args: Parameters<typeof showDialog>) =>

0 commit comments

Comments
 (0)