-
Notifications
You must be signed in to change notification settings - Fork 645
Expand file tree
/
Copy pathoptions.ts
More file actions
58 lines (53 loc) · 1.71 KB
/
options.ts
File metadata and controls
58 lines (53 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { Infer } from '@metamask/superstruct';
import {
boolean,
create,
defaulted,
nullable,
object,
optional,
record,
string,
} from '@metamask/superstruct';
import { JsonStruct } from '@metamask/utils';
import { DEFAULT_CURRENCY, DEFAULT_LOCALE, DEFAULT_SRP } from './constants';
const SimulationOptionsStruct = object({
currency: defaulted(optional(string()), DEFAULT_CURRENCY),
secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),
locale: defaulted(optional(string()), DEFAULT_LOCALE),
state: defaulted(optional(nullable(record(string(), JsonStruct))), null),
unencryptedState: defaulted(
optional(nullable(record(string(), JsonStruct))),
null,
),
hideBalances: defaulted(optional(boolean()), false),
});
/**
* Options for the simulation.
*
* @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`.
*/
export type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;
/**
* Options for the simulation, with defaults filled in.
*
* See {@link SimulationUserOptions} for documentation.
*/
export type SimulationOptions = Required<SimulationUserOptions>;
/**
* Get the options for the simulation.
*
* @param options - The user options. Any options not specified will be filled
* in with default values.
* @returns The simulation options.
*/
export function getOptions(options: SimulationUserOptions): SimulationOptions {
return create(
options,
SimulationOptionsStruct,
) as Required<SimulationUserOptions>;
}