Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ describe('snap_getPreferences', () => {
describe('getImplementation', () => {
it('returns the preferences', async () => {
const methodHooks = {
getPreferences: jest
.fn()
.mockReturnValue({ locale: 'en', currency: 'usd' }),
getPreferences: jest.fn().mockReturnValue({
locale: 'en',
currency: 'usd',
hideBalances: false,
}),
};

const implementation = getImplementation(methodHooks);
Expand All @@ -40,7 +42,7 @@ describe('snap_getPreferences', () => {
},
method: 'snap_getPreferences',
}),
).toStrictEqual({ locale: 'en', currency: 'usd' });
).toStrictEqual({ locale: 'en', currency: 'usd', hideBalances: false });
});
});
});
10 changes: 9 additions & 1 deletion packages/snaps-sdk/src/types/methods/get-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ export type GetPreferencesParams = never;
* The result returned by the `snap_getPreferences` method.
*
* It is the user selected preferences from the MetaMask extension.
*
* @property locale - The user's selected locale.
* @property currency - The user's selected currency.
* @property hideBalances - Whether the user has chosen to hide balances.
*/
export type GetPreferencesResult = { locale: string; currency: string };
export type GetPreferencesResult = {
locale: string;
currency: string;
hideBalances: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ describe('getGetPreferencesMethodImplementation', () => {
}),
);

expect(fn()).toStrictEqual({ currency: 'usd', locale: 'en' });
expect(fn()).toStrictEqual({
currency: 'usd',
locale: 'en',
hideBalances: false,
});
});

it('returns the implementation of the `getPreferences` hook for a different locale', async () => {
Expand All @@ -19,7 +23,11 @@ describe('getGetPreferencesMethodImplementation', () => {
}),
);

expect(fn()).toStrictEqual({ currency: 'usd', locale: 'nl' });
expect(fn()).toStrictEqual({
currency: 'usd',
locale: 'nl',
hideBalances: false,
});
});

it('returns the implementation of the `getPreferences` hook for a different currency', async () => {
Expand All @@ -29,6 +37,24 @@ describe('getGetPreferencesMethodImplementation', () => {
}),
);

expect(fn()).toStrictEqual({ currency: 'dkk', locale: 'en' });
expect(fn()).toStrictEqual({
currency: 'dkk',
locale: 'en',
hideBalances: false,
});
});

it('returns the implementation of the `getPreferences` hook for hidden balances', async () => {
const fn = getGetPreferencesMethodImplementation(
getMockOptions({
hideBalances: true,
}),
);

expect(fn()).toStrictEqual({
currency: 'usd',
locale: 'en',
hideBalances: true,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import type { SimulationOptions } from '../../options';
* @param options - The simulation options.
* @param options.currency - The currency to use.
* @param options.locale - The locale to use.
* @param options.hideBalances - Whether to hide balances.
* @returns The implementation of the `getPreferences` hook.
*/
export function getGetPreferencesMethodImplementation({
currency,
locale,
hideBalances,
}: SimulationOptions) {
return () => {
return { currency, locale };
return { currency, locale, hideBalances };
};
}
2 changes: 2 additions & 0 deletions packages/snaps-simulation/src/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('getOptions', () => {
expect(options).toMatchInlineSnapshot(`
{
"currency": "usd",
"hideBalances": false,
"locale": "en",
"secretRecoveryPhrase": "test test test test test test test test test test test ball",
"state": null,
Expand All @@ -24,6 +25,7 @@ describe('getOptions', () => {
expect(options).toMatchInlineSnapshot(`
{
"currency": "eur",
"hideBalances": false,
"locale": "nl",
"secretRecoveryPhrase": "test test test test test test test test test test test ball",
"state": null,
Expand Down
2 changes: 2 additions & 0 deletions packages/snaps-simulation/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Infer } from '@metamask/superstruct';
import {
boolean,
create,
defaulted,
nullable,
Expand All @@ -21,6 +22,7 @@ const SimulationOptionsStruct = object({
optional(nullable(record(string(), JsonStruct))),
null,
),
hideBalances: defaulted(optional(boolean()), false),
});

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/snaps-simulation/src/test-utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import type { SimulationOptions } from '../options';
* @param options.secretRecoveryPhrase - The secret recovery phrase to use.
* @param options.state - The state to use.
* @param options.unencryptedState - The unencrypted state to use.
* @param options.hideBalances - Whether to hide balances.
* @returns The options for the simulation.
*/
export function getMockOptions({
currency = 'usd',
locale = 'en',
hideBalances = false,
secretRecoveryPhrase = DEFAULT_SRP,
state = null,
unencryptedState = null,
Expand All @@ -25,5 +27,6 @@ export function getMockOptions({
secretRecoveryPhrase,
state,
unencryptedState,
hideBalances,
};
}
6 changes: 5 additions & 1 deletion packages/snaps-simulator/src/features/simulation/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ export function* initSaga({ payload }: PayloadAction<string>) {
...sharedHooks,
// TODO: Add all the hooks required
// TODO: Allow changing this?
getPreferences: () => ({ locale: 'en', currency: 'usd' }),
getPreferences: () => ({
locale: 'en',
currency: 'usd',
hideBalances: false,
}),
getUnlockPromise: async () => Promise.resolve(true),
showDialog: async (...args: Parameters<typeof showDialog>) =>
await runSaga(showDialog, ...args).toPromise(),
Expand Down
Loading