@metamask/snaps-simulation 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/constants.cjs +35 -1
  3. package/dist/constants.cjs.map +1 -1
  4. package/dist/constants.d.cts +12 -0
  5. package/dist/constants.d.cts.map +1 -1
  6. package/dist/constants.d.mts +12 -0
  7. package/dist/constants.d.mts.map +1 -1
  8. package/dist/constants.mjs +34 -0
  9. package/dist/constants.mjs.map +1 -1
  10. package/dist/controllers.cjs +4 -0
  11. package/dist/controllers.cjs.map +1 -1
  12. package/dist/controllers.d.cts.map +1 -1
  13. package/dist/controllers.d.mts.map +1 -1
  14. package/dist/controllers.mjs +4 -0
  15. package/dist/controllers.mjs.map +1 -1
  16. package/dist/helpers.cjs +30 -0
  17. package/dist/helpers.cjs.map +1 -1
  18. package/dist/helpers.d.cts +6 -0
  19. package/dist/helpers.d.cts.map +1 -1
  20. package/dist/helpers.d.mts +6 -0
  21. package/dist/helpers.d.mts.map +1 -1
  22. package/dist/helpers.mjs +30 -0
  23. package/dist/helpers.mjs.map +1 -1
  24. package/dist/interface.cjs +65 -16
  25. package/dist/interface.cjs.map +1 -1
  26. package/dist/interface.d.cts +34 -7
  27. package/dist/interface.d.cts.map +1 -1
  28. package/dist/interface.d.mts +34 -7
  29. package/dist/interface.d.mts.map +1 -1
  30. package/dist/interface.mjs +65 -17
  31. package/dist/interface.mjs.map +1 -1
  32. package/dist/options.cjs +13 -0
  33. package/dist/options.cjs.map +1 -1
  34. package/dist/options.d.cts +62 -0
  35. package/dist/options.d.cts.map +1 -1
  36. package/dist/options.d.mts +62 -0
  37. package/dist/options.d.mts.map +1 -1
  38. package/dist/options.mjs +16 -3
  39. package/dist/options.mjs.map +1 -1
  40. package/dist/request.cjs +7 -5
  41. package/dist/request.cjs.map +1 -1
  42. package/dist/request.d.cts +6 -2
  43. package/dist/request.d.cts.map +1 -1
  44. package/dist/request.d.mts +6 -2
  45. package/dist/request.d.mts.map +1 -1
  46. package/dist/request.mjs +7 -5
  47. package/dist/request.mjs.map +1 -1
  48. package/dist/simulation.cjs +24 -2
  49. package/dist/simulation.cjs.map +1 -1
  50. package/dist/simulation.d.cts +3 -2
  51. package/dist/simulation.d.cts.map +1 -1
  52. package/dist/simulation.d.mts +3 -2
  53. package/dist/simulation.d.mts.map +1 -1
  54. package/dist/simulation.mjs +24 -2
  55. package/dist/simulation.mjs.map +1 -1
  56. package/dist/structs.d.cts +14 -14
  57. package/dist/structs.d.mts +14 -14
  58. package/dist/types.cjs.map +1 -1
  59. package/dist/types.d.cts +8 -2
  60. package/dist/types.d.cts.map +1 -1
  61. package/dist/types.d.mts +8 -2
  62. package/dist/types.d.mts.map +1 -1
  63. package/dist/types.mjs.map +1 -1
  64. package/package.json +8 -8
package/dist/helpers.mjs CHANGED
@@ -28,6 +28,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
28
28
  executionService,
29
29
  runSaga,
30
30
  controllerMessenger,
31
+ simulationOptions: options,
31
32
  handler: HandlerType.OnTransaction,
32
33
  request: {
33
34
  method: '',
@@ -50,6 +51,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
50
51
  store,
51
52
  executionService,
52
53
  controllerMessenger,
54
+ simulationOptions: options,
53
55
  runSaga,
54
56
  handler: HandlerType.OnCronjob,
55
57
  request,
@@ -65,6 +67,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
65
67
  executionService,
66
68
  runSaga,
67
69
  controllerMessenger,
70
+ simulationOptions: options,
68
71
  handler: HandlerType.OnKeyringRequest,
69
72
  request,
70
73
  });
@@ -79,6 +82,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
79
82
  store,
80
83
  executionService,
81
84
  controllerMessenger,
85
+ simulationOptions: options,
82
86
  runSaga,
83
87
  handler: HandlerType.OnRpcRequest,
84
88
  request,
@@ -96,6 +100,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
96
100
  store,
97
101
  executionService,
98
102
  controllerMessenger,
103
+ simulationOptions: options,
99
104
  runSaga,
100
105
  handler: HandlerType.OnInstall,
101
106
  request: {
@@ -113,6 +118,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
113
118
  store,
114
119
  executionService,
115
120
  controllerMessenger,
121
+ simulationOptions: options,
116
122
  runSaga,
117
123
  handler: HandlerType.OnUpdate,
118
124
  request: {
@@ -121,6 +127,24 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
121
127
  },
122
128
  });
123
129
  },
130
+ // This can't be async because it returns a `SnapRequest`.
131
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
132
+ onStart: (request) => {
133
+ log('Running onStart handler.');
134
+ return handleRequest({
135
+ snapId,
136
+ store,
137
+ executionService,
138
+ controllerMessenger,
139
+ simulationOptions: options,
140
+ runSaga,
141
+ handler: HandlerType.OnStart,
142
+ request: {
143
+ method: '',
144
+ ...request,
145
+ },
146
+ });
147
+ },
124
148
  onNameLookup: async (nameLookupOptions) => {
125
149
  log('Requesting name lookup %o.', nameLookupOptions);
126
150
  const params = create(nameLookupOptions, NameLookupOptionsStruct);
@@ -129,6 +153,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
129
153
  store,
130
154
  executionService,
131
155
  controllerMessenger,
156
+ simulationOptions: options,
132
157
  runSaga,
133
158
  handler: HandlerType.OnNameLookup,
134
159
  request: {
@@ -146,6 +171,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
146
171
  store,
147
172
  executionService,
148
173
  controllerMessenger,
174
+ simulationOptions: options,
149
175
  runSaga,
150
176
  handler: HandlerType.OnSignature,
151
177
  request: {
@@ -169,6 +195,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
169
195
  store,
170
196
  executionService,
171
197
  controllerMessenger,
198
+ simulationOptions: options,
172
199
  runSaga,
173
200
  handler: HandlerType.OnHomePage,
174
201
  request: {
@@ -185,6 +212,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
185
212
  store,
186
213
  executionService,
187
214
  controllerMessenger,
215
+ simulationOptions: options,
188
216
  runSaga,
189
217
  handler: HandlerType.OnSettingsPage,
190
218
  request: {
@@ -207,6 +235,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
207
235
  store,
208
236
  executionService,
209
237
  controllerMessenger,
238
+ simulationOptions: options,
210
239
  runSaga,
211
240
  handler: HandlerType.OnProtocolRequest,
212
241
  request: {
@@ -229,6 +258,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
229
258
  store,
230
259
  executionService,
231
260
  controllerMessenger,
261
+ simulationOptions: options,
232
262
  runSaga,
233
263
  handler: HandlerType.OnClientRequest,
234
264
  request,
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,8BAA8B;AACpD,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAEtC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,0BAAgB;AAC5D,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACzB,sBAAkB;AAcnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAmMtD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACwC;IAC/C,MAAM,aAAa,GAAG,KAAK,EACzB,OAA2B,EACS,EAAE;QACtC,GAAG,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;QAExC,MAAM,EACJ,M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,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAEnD,OAAO;gBACL,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport type { CaipChainId } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger } from './logger';\nimport type { SimulationOptions } from './options';\nimport { handleRequest } from './request';\nimport type { InstalledSnap } from './simulation';\nimport { addJsonRpcMock, removeJsonRpcMock } from './store';\nimport {\n assertIsResponseWithInterface,\n JsonRpcMockOptionsStruct,\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\n NameLookupOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type SnapHelpers = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The background event request. This is similar to a JSON-RPC\n * request, and is normally specified in the `request` param of the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring request to the Snap.\n *\n * @param keyringRequest - Keyring request.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n request: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC protocol request to the Snap.\n *\n * @param scope - A CAIP-2 scope.\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onProtocolRequest(\n scope: CaipChainId,\n request: RequestOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n close(): Promise<void>;\n};\n\n/**\n * Get the helper functions for the Snap.\n *\n * @param snap - The installed Snap.\n * @param snap.snapId - The ID of the Snap.\n * @param snap.store - The Redux store.\n * @param snap.executionService - The execution service.\n * @param snap.runSaga - The `runSaga` function.\n * @param snap.controllerMessenger - The controller messenger.\n * @param snap.options - The simulation options.\n * @returns The Snap helpers.\n */\nexport function getHelpers({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n options,\n}: InstalledSnap & { options: SimulationOptions }): SnapHelpers {\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onKeyringRequest = (request: KeyringOptions) => {\n log('Sending keyring request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n };\n\n return {\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onKeyringRequest,\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onInstall: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onInstall handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnInstall,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onUpdate: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onUpdate handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnUpdate,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n onNameLookup: async (\n nameLookupOptions: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Requesting name lookup %o.', nameLookupOptions);\n\n const params = create(nameLookupOptions, NameLookupOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnNameLookup,\n request: {\n method: '',\n params,\n },\n });\n\n return response;\n },\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n onBackgroundEvent: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onSettingsPage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering settings page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSettingsPage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onProtocolRequest: async (\n scope,\n rawRequest,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Sending protocol request.');\n\n const request = {\n jsonrpc: '2.0' as const,\n id: rawRequest.id ?? 1,\n method: rawRequest.method,\n ...(rawRequest.params ? { params: rawRequest.params } : {}),\n };\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnProtocolRequest,\n request: {\n origin: rawRequest.origin,\n method: '',\n params: {\n scope,\n request,\n },\n },\n });\n\n return response;\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onClientRequest: (request) => {\n log('Sending client request.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnClientRequest,\n request,\n });\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
1
+ {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,8BAA8B;AACpD,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAEtC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,0BAAgB;AAC5D,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACzB,sBAAkB;AAcnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AA0MtD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACwC;IAC/C,MAAM,aAAa,GAAG,KAAK,EACzB,OAA2B,EACS,EAAE;QACtC,GAAG,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;QAExC,MAAM,EACJ,MAAM,EAAE,iBAAiB,EACzB,OAAO,EACP,GAAG,WAAW,EACf,GAAG,MAAM,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC;QAE9C,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC;YACnC,MAAM;YACN,KAAK;YACL,gBAAgB;YAChB,OAAO;YACP,mBAAmB;YACnB,iBAAiB,EAAE,OAAO;YAC1B,OAAO,EAAE,WAAW,CAAC,aAAa;YAClC,OAAO,EAAE;gBACP,MAAM,EAAE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EH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,0DAA0D;QAC1D,qEAAqE;QACrE,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE;YAC3B,GAAG,CAAC,yBAAyB,CAAC,CAAC;YAE/B,OAAO,aAAa,CAAC;gBACnB,MAAM;gBACN,KAAK;gBACL,gBAAgB;gBAChB,mBAAmB;gBACnB,iBAAiB,EAAE,OAAO;gBAC1B,OAAO;gBACP,OAAO,EAAE,WAAW,CAAC,eAAe;gBACpC,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QAED,WAAW,CAAC,IAAwB;YAClC,GAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAEnD,OAAO;gBACL,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport type { CaipChainId } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger } from './logger';\nimport type { SimulationOptions } from './options';\nimport { handleRequest } from './request';\nimport type { InstalledSnap } from './simulation';\nimport { addJsonRpcMock, removeJsonRpcMock } from './store';\nimport {\n assertIsResponseWithInterface,\n JsonRpcMockOptionsStruct,\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\n NameLookupOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type SnapHelpers = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The background event request. This is similar to a JSON-RPC\n * request, and is normally specified in the `request` param of the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring request to the Snap.\n *\n * @param keyringRequest - Keyring request.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onStart` handler.\n *\n * @returns The response.\n */\n onStart(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n request: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC protocol request to the Snap.\n *\n * @param scope - A CAIP-2 scope.\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onProtocolRequest(\n scope: CaipChainId,\n request: RequestOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n close(): Promise<void>;\n};\n\n/**\n * Get the helper functions for the Snap.\n *\n * @param snap - The installed Snap.\n * @param snap.snapId - The ID of the Snap.\n * @param snap.store - The Redux store.\n * @param snap.executionService - The execution service.\n * @param snap.runSaga - The `runSaga` function.\n * @param snap.controllerMessenger - The controller messenger.\n * @param snap.options - The simulation options.\n * @returns The Snap helpers.\n */\nexport function getHelpers({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n options,\n}: InstalledSnap & { options: SimulationOptions }): SnapHelpers {\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n simulationOptions: options,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onKeyringRequest = (request: KeyringOptions) => {\n log('Sending keyring request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n simulationOptions: options,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n };\n\n return {\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onKeyringRequest,\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onInstall: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onInstall handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnInstall,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onUpdate: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onUpdate handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnUpdate,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onStart: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onStart handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnStart,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n onNameLookup: async (\n nameLookupOptions: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Requesting name lookup %o.', nameLookupOptions);\n\n const params = create(nameLookupOptions, NameLookupOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnNameLookup,\n request: {\n method: '',\n params,\n },\n });\n\n return response;\n },\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n onBackgroundEvent: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onSettingsPage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering settings page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnSettingsPage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onProtocolRequest: async (\n scope,\n rawRequest,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Sending protocol request.');\n\n const request = {\n jsonrpc: '2.0' as const,\n id: rawRequest.id ?? 1,\n method: rawRequest.method,\n ...(rawRequest.params ? { params: rawRequest.params } : {}),\n };\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnProtocolRequest,\n request: {\n origin: rawRequest.origin,\n method: '',\n params: {\n scope,\n request,\n },\n },\n });\n\n return response;\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onClientRequest: (request) => {\n log('Sending client request.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n simulationOptions: options,\n runSaga,\n handler: HandlerType.OnClientRequest,\n request,\n });\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getInterface = exports.getInterfaceActions = exports.uploadFile = exports.waitForUpdate = exports.selectFromSelector = exports.selectFromRadioGroup = exports.selectInDropdown = exports.typeInField = exports.mergeValue = exports.clickElement = exports.getElementByType = exports.getElement = exports.resolveWithSaga = exports.getInterfaceResponse = void 0;
6
+ exports.getInterface = exports.getInterfaceActions = exports.uploadFile = exports.waitForUpdate = exports.selectFromSelector = exports.getValueFromSelector = exports.selectFromRadioGroup = exports.selectInDropdown = exports.typeInField = exports.mergeValue = exports.clickElement = exports.getElementByType = exports.getElement = exports.resolveWithSaga = exports.getInterfaceResponse = void 0;
7
7
  const snaps_rpc_methods_1 = require("@metamask/snaps-rpc-methods");
8
8
  const snaps_sdk_1 = require("@metamask/snaps-sdk");
9
9
  const snaps_utils_1 = require("@metamask/snaps-utils");
@@ -18,6 +18,10 @@ const errors_1 = require("./utils/errors.cjs");
18
18
  * The maximum file size that can be uploaded.
19
19
  */
20
20
  const MAX_FILE_SIZE = 10000000; // 10 MB
21
+ /**
22
+ * The elements based on the Selector component.
23
+ */
24
+ const SELECTOR_ELEMENTS = ['Selector', 'AccountSelector', 'AssetSelector'];
21
25
  /**
22
26
  * Get a user interface object from a type and content object.
23
27
  *
@@ -465,24 +469,66 @@ async function selectFromRadioGroup(controllerMessenger, id, content, snapId, na
465
469
  }
466
470
  exports.selectFromRadioGroup = selectFromRadioGroup;
467
471
  /**
468
- * Choose an option with value from Selector interface element.
472
+ * Get the value from a Selector interface element.
473
+ *
474
+ * @param element - The Selector element to get the value from.
475
+ * @param options - The simulation options.
476
+ * @param value - The value to get from the Selector.
477
+ *
478
+ * @returns The value from the Selector element.
479
+ */
480
+ function getValueFromSelector(element, options, value) {
481
+ switch (element.type) {
482
+ case 'Selector': {
483
+ const selectorOptions = (0, snaps_utils_1.getJsxChildren)(element);
484
+ const selectedOption = selectorOptions.find((option) => (0, utils_1.hasProperty)(option.props, 'value') && option.props.value === value);
485
+ (0, snaps_sdk_1.assert)(selectedOption !== undefined, `The Selector with the name "${element.props.name}" does not contain "${value}".`);
486
+ return value;
487
+ }
488
+ case 'AccountSelector': {
489
+ const { accounts } = options;
490
+ const selectedAccount = accounts.find((account) => account.id === value);
491
+ (0, snaps_sdk_1.assert)(selectedAccount !== undefined, `The AccountSelector with the name "${element.props.name}" does not contain an account with ID "${value}".`);
492
+ return {
493
+ accountId: selectedAccount.id,
494
+ addresses: (0, snaps_utils_1.createAccountList)(selectedAccount.address, (0, snaps_utils_1.createChainIdList)(selectedAccount.scopes, element.props.chainIds)),
495
+ };
496
+ }
497
+ case 'AssetSelector': {
498
+ const { assets, accounts } = options;
499
+ const selectedAsset = assets[value];
500
+ const { address } = (0, utils_1.parseCaipAccountId)(element.props.addresses[0]);
501
+ const account = accounts.find((simulationAccount) => simulationAccount.address === address);
502
+ const accountHasAsset = account?.assets?.some((asset) => asset === value);
503
+ (0, snaps_sdk_1.assert)(selectedAsset !== undefined && accountHasAsset, `The AssetSelector with the name "${element.props.name}" does not contain an asset with ID "${value}".`);
504
+ return {
505
+ asset: value,
506
+ name: selectedAsset.name,
507
+ symbol: selectedAsset.symbol,
508
+ };
509
+ }
510
+ default:
511
+ throw new Error(`Expected an element of type ${(0, errors_1.formatTypeErrorMessage)(SELECTOR_ELEMENTS)}, but found "${element.type}".`);
512
+ }
513
+ }
514
+ exports.getValueFromSelector = getValueFromSelector;
515
+ /**
516
+ * Choose an option with value from a Selector interface element.
469
517
  *
470
518
  * @param controllerMessenger - The controller messenger used to call actions.
519
+ * @param options - The simulation options.
471
520
  * @param id - The interface ID.
472
521
  * @param content - The interface Components.
473
522
  * @param snapId - The Snap ID.
474
523
  * @param name - The element name.
475
524
  * @param value - The value to type in the element.
476
525
  */
477
- async function selectFromSelector(controllerMessenger, id, content, snapId, name, value) {
526
+ async function selectFromSelector(controllerMessenger, options, id, content, snapId, name, value) {
478
527
  const result = getElement(content, name);
479
528
  (0, snaps_sdk_1.assert)(result !== undefined, `Could not find an element in the interface with the name "${name}".`);
480
- (0, snaps_sdk_1.assert)(result.element.type === 'Selector', `Expected an element of type "Selector", but found "${result.element.type}".`);
481
- const options = (0, snaps_utils_1.getJsxChildren)(result.element);
482
- const selectedOption = options.find((option) => (0, utils_1.hasProperty)(option.props, 'value') && option.props.value === value);
483
- (0, snaps_sdk_1.assert)(selectedOption !== undefined, `The Selector with the name "${name}" does not contain "${value}".`);
529
+ const selectedValue = getValueFromSelector(result.element, options, value);
484
530
  const { state, context } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
485
- const newState = mergeValue(state, name, value, result.form);
531
+ const newState = mergeValue(state, name, selectedValue, result.form);
486
532
  controllerMessenger.call('SnapInterfaceController:updateInterfaceState', id, newState);
487
533
  await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {
488
534
  origin: 'metamask',
@@ -494,7 +540,7 @@ async function selectFromSelector(controllerMessenger, id, content, snapId, name
494
540
  event: {
495
541
  type: snaps_sdk_1.UserInputEventType.InputChangeEvent,
496
542
  name: result.element.props.name,
497
- value,
543
+ value: selectedValue,
498
544
  },
499
545
  id,
500
546
  context,
@@ -507,19 +553,20 @@ exports.selectFromSelector = selectFromSelector;
507
553
  * Wait for an interface to be updated.
508
554
  *
509
555
  * @param controllerMessenger - The controller messenger used to call actions.
556
+ * @param options - The simulation options.
510
557
  * @param snapId - The Snap ID.
511
558
  * @param id - The interface ID.
512
559
  * @param originalContent - The original interface content.
513
560
  * @returns A promise that resolves to the updated interface.
514
561
  */
515
- async function waitForUpdate(controllerMessenger, snapId, id, originalContent) {
562
+ async function waitForUpdate(controllerMessenger, options, snapId, id, originalContent) {
516
563
  return new Promise((resolve) => {
517
564
  const listener = (state) => {
518
565
  const currentInterface = state.interfaces[id];
519
566
  const newContent = currentInterface?.content;
520
567
  if (!(0, fast_deep_equal_1.default)(originalContent, newContent)) {
521
568
  controllerMessenger.unsubscribe('SnapInterfaceController:stateChange', listener);
522
- const actions = getInterfaceActions(snapId, controllerMessenger, {
569
+ const actions = getInterfaceActions(snapId, controllerMessenger, options, {
523
570
  content: newContent,
524
571
  id,
525
572
  });
@@ -598,12 +645,13 @@ exports.uploadFile = uploadFile;
598
645
  *
599
646
  * @param snapId - The Snap ID.
600
647
  * @param controllerMessenger - The controller messenger used to call actions.
648
+ * @param simulationOptions - The simulation options.
601
649
  * @param interface - The interface object.
602
650
  * @param interface.content - The interface content.
603
651
  * @param interface.id - The interface ID.
604
652
  * @returns The user interface actions.
605
653
  */
606
- function getInterfaceActions(snapId, controllerMessenger, { content, id }) {
654
+ function getInterfaceActions(snapId, controllerMessenger, simulationOptions, { content, id }) {
607
655
  return {
608
656
  clickElement: async (name) => {
609
657
  await clickElement(controllerMessenger, id, content, snapId, name);
@@ -618,12 +666,12 @@ function getInterfaceActions(snapId, controllerMessenger, { content, id }) {
618
666
  await selectFromRadioGroup(controllerMessenger, id, content, snapId, name, value);
619
667
  },
620
668
  selectFromSelector: async (name, value) => {
621
- await selectFromSelector(controllerMessenger, id, content, snapId, name, value);
669
+ await selectFromSelector(controllerMessenger, simulationOptions, id, content, snapId, name, value);
622
670
  },
623
671
  uploadFile: async (name, file, options) => {
624
672
  await uploadFile(controllerMessenger, id, content, snapId, name, file, options);
625
673
  },
626
- waitForUpdate: async () => waitForUpdate(controllerMessenger, snapId, id, content),
674
+ waitForUpdate: async () => waitForUpdate(controllerMessenger, simulationOptions, snapId, id, content),
627
675
  };
628
676
  }
629
677
  exports.getInterfaceActions = getInterfaceActions;
@@ -633,12 +681,13 @@ exports.getInterfaceActions = getInterfaceActions;
633
681
  * @param runSaga - A function to run a saga outside the usual Redux flow.
634
682
  * @param snapId - The Snap ID.
635
683
  * @param controllerMessenger - The controller messenger used to call actions.
684
+ * @param options - The simulation options.
636
685
  * @yields Takes the set interface action.
637
686
  * @returns The user interface object.
638
687
  */
639
- function* getInterface(runSaga, snapId, controllerMessenger) {
688
+ function* getInterface(runSaga, snapId, controllerMessenger, options) {
640
689
  const storedInterface = yield (0, effects_1.call)(getStoredInterface, controllerMessenger, snapId);
641
- const interfaceActions = getInterfaceActions(snapId, controllerMessenger, storedInterface);
690
+ const interfaceActions = getInterfaceActions(snapId, controllerMessenger, options, storedInterface);
642
691
  return getInterfaceResponse(runSaga, storedInterface.type, storedInterface.id, storedInterface.content, interfaceActions);
643
692
  }
644
693
  exports.getInterface = getInterface;
@@ -1 +1 @@
1
- {"version":3,"file":"interface.cjs","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;;;;AAEA,mEAAoE;AASpE,mDAA6E;AAM7E,uDAK+B;AAC/B,2CAAgE;AAEhE,sEAAwC;AAExC,gDAA6D;AAE7D,+CAA8C;AAE9C,uCAAuD;AAEvD,6CAA8E;AAO9E,+CAAwD;AACxD;;GAEG;AACH,MAAM,aAAa,GAAG,QAAU,CAAC,CAAC,QAAQ;AAE1C;;;;;;;;;GASG;AACH,SAAgB,oBAAoB,CAClC,OAAwB,EACxB,IAAkE,EAClE,EAAU,EACV,OAAmB,EACnB,gBAAsC;IAEtC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,yCAAqB,CAAC,sBAAU,CAAC,KAAK,CAAC;YAC1C,OAAO;gBACL,GAAG,gBAAgB;gBACnB,IAAI,EAAE,sBAAU,CAAC,KAAK;gBACtB,OAAO;gBACP,EAAE;gBAEF,EAAE,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC;aAC/B,CAAC;QAEJ,KAAK,yCAAqB,CAAC,sBAAU,CAAC,YAAY,CAAC;YACjD,OAAO;gBACL,GAAG,gBAAgB;gBACnB,IAAI,EAAE,sBAAU,CAAC,YAAY;gBAC7B,OAAO;gBACP,EAAE;gBAEF,EAAE,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC;gBAC9B,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC;aACpC,CAAC;QAEJ,KAAK,yCAAqB,CAAC,sBAAU,CAAC,MAAM,CAAC;YAC3C,OAAO;gBACL,GAAG,gBAAgB;gBACnB,IAAI,EAAE,sBAAU,CAAC,MAAM;gBACvB,OAAO;gBACP,EAAE;gBAE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AwBC","sourcesContent":["import type { SnapInterfaceControllerState } from '@metamask/snaps-controllers';\nimport type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n FormState,\n InterfaceContext,\n InterfaceState,\n SnapId,\n UserInputEvent,\n File,\n} from '@metamask/snaps-sdk';\nimport { DialogType, UserInputEventType, assert } from '@metamask/snaps-sdk';\nimport type {\n FooterElement,\n FormElement,\n JSXElement,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n HandlerType,\n getJsxChildren,\n unwrapError,\n walkJsx,\n} from '@metamask/snaps-utils';\nimport { assertExhaustive, hasProperty } from '@metamask/utils';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport deepEqual from 'fast-deep-equal';\nimport { type SagaIterator } from 'redux-saga';\nimport { call, put, select, take } from 'redux-saga/effects';\n\nimport { TYPEABLE_INPUTS } from './constants';\nimport type { RootControllerMessenger } from './controllers';\nimport { getFileSize, getFileToUpload } from './files';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\nimport type {\n FileOptions,\n SnapHandlerInterface,\n SnapInterface,\n SnapInterfaceActions,\n} from './types';\nimport { formatTypeErrorMessage } from './utils/errors';\n/**\n * The maximum file size that can be uploaded.\n */\nconst MAX_FILE_SIZE = 10_000_000; // 10 MB\n\n/**\n * Get a user interface object from a type and content object.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param type - The type of the interface.\n * @param id - The interface ID.\n * @param content - The content to show in the interface.\n * @param interfaceActions - The actions to interact with the interface.\n * @returns The user interface object.\n */\nexport function getInterfaceResponse(\n runSaga: RunSagaFunction,\n type: DialogApprovalTypes[DialogType | 'default'] | 'Notification',\n id: string,\n content: JSXElement,\n interfaceActions: SnapInterfaceActions,\n): SnapInterface {\n switch (type) {\n case DIALOG_APPROVAL_TYPES[DialogType.Alert]:\n return {\n ...interfaceActions,\n type: DialogType.Alert,\n content,\n id,\n\n ok: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Confirmation]:\n return {\n ...interfaceActions,\n type: DialogType.Confirmation,\n content,\n id,\n\n ok: resolveWith(runSaga, true),\n cancel: resolveWith(runSaga, false),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Prompt]:\n return {\n ...interfaceActions,\n type: DialogType.Prompt,\n content,\n id,\n\n ok: resolveWithInput(runSaga),\n cancel: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES.default: {\n const footer = getElementByType<FooterElement>(content, 'Footer');\n\n // No Footer defined so we apply a default footer.\n if (!footer) {\n return {\n ...interfaceActions,\n content,\n id,\n\n ok: resolveWith(runSaga, null),\n cancel: resolveWith(runSaga, null),\n };\n }\n\n // Only one button in footer so we apply a default cancel button.\n if (getJsxChildren(footer).length === 1) {\n return {\n ...interfaceActions,\n content,\n id,\n\n cancel: resolveWith(runSaga, null),\n };\n }\n\n // We have two buttons in the footer so we assume the snap handles the approval of the interface.\n return {\n ...interfaceActions,\n content,\n id,\n };\n }\n\n case 'Notification': {\n return {\n ...interfaceActions,\n content,\n id,\n };\n }\n\n default:\n throw new Error(`Unknown or unsupported dialog type: \"${String(type)}\".`);\n }\n}\n\n/**\n * Resolve the current user interface with the given value.\n *\n * @param value - The value to resolve the user interface with.\n * @yields Puts the resolve user interface action.\n */\nexport function* resolveWithSaga(value: unknown): SagaIterator {\n yield put(resolveInterface(value));\n}\n\n/**\n * Resolve the current user interface with the given value. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param value - The value to resolve the user interface with.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWith(runSaga: RunSagaFunction, value: unknown) {\n return async () => {\n await runSaga(resolveWithSaga, value).toPromise();\n };\n}\n\n/**\n * Resolve the current user interface with the provided input. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWithInput(runSaga: RunSagaFunction) {\n return async (value = '') => {\n await runSaga(resolveWithSaga, value).toPromise();\n };\n}\n\n/**\n * Get the stored user interface from the store.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param snapId - The Snap ID.\n * @yields Takes the set interface action.\n * @returns The user interface object.\n */\nfunction* getStoredInterface(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n): SagaIterator<Interface & { content: JSXElement }> {\n const currentInterface: Interface | null = yield select(getCurrentInterface);\n\n if (currentInterface) {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n currentInterface.id,\n );\n\n return { ...currentInterface, content };\n }\n\n const { payload }: PayloadAction<Interface> = yield take(setInterface.type);\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n payload.id,\n );\n\n return { ...payload, content };\n}\n\n/**\n * A JSX element with a name.\n */\nexport type NamedJSXElement = JSXElement & { props: { name: string } };\n\n/**\n * Check if a JSX element is a JSX element with a given name.\n *\n * @param element - The JSX element.\n * @param name - The element name.\n * @returns True if the element is a JSX element with the given name, otherwise\n * false.\n */\nfunction isJSXElementWithName<Element extends JSXElement, Name extends string>(\n element: Element,\n name: Name,\n): element is Element & { props: { name: Name } } {\n return hasProperty(element.props, 'name') && element.props.name === name;\n}\n\n/**\n * Find an element inside a form element in a JSX tree.\n *\n * @param form - The form element.\n * @param name - The element name.\n * @returns An object containing the element and the form name if it's contained\n * in a form, otherwise undefined.\n */\nfunction getFormElement(form: FormElement, name: string) {\n const element = walkJsx<NamedJSXElement>(form, (childElement) => {\n if (isJSXElementWithName(childElement, name)) {\n return childElement;\n }\n\n return undefined;\n });\n\n if (element === undefined) {\n return undefined;\n }\n\n return { element, form: form.props.name };\n}\n\n/**\n * Get an object containing the element, and optional form that's associated\n * with the element if any.\n *\n * @param element - The JSX element.\n * @returns An object containing the element and optional form.\n */\nfunction getElementWithOptionalForm(element: NamedJSXElement): {\n element: NamedJSXElement;\n form?: string;\n} {\n if (element.type !== 'Button' || !element.props.form) {\n return { element };\n }\n\n return { element, form: element.props.form };\n}\n\n/**\n * Get an element from a JSX tree with the given name.\n *\n * @param content - The interface content.\n * @param name - The element name.\n * @returns An object containing the element and the form name if it's contained\n * in a form, otherwise undefined.\n */\nexport function getElement(\n content: JSXElement,\n name: string,\n):\n | {\n element: NamedJSXElement;\n form?: string;\n }\n | undefined {\n if (isJSXElementWithName(content, name)) {\n return getElementWithOptionalForm(content);\n }\n\n return walkJsx(content, (element) => {\n if (element.type === 'Form') {\n return getFormElement(element, name);\n }\n\n if (isJSXElementWithName(element, name)) {\n return getElementWithOptionalForm(element);\n }\n\n return undefined;\n });\n}\n\n/**\n * Get an element from a JSX tree with the given type.\n *\n * @param content - The interface content.\n * @param type - The element type.\n * @returns The element with the given type.\n */\nexport function getElementByType<Element extends JSXElement>(\n content: JSXElement,\n type: string,\n) {\n return walkJsx(content, (element) => {\n if (element.type === type) {\n return element as Element;\n }\n\n return undefined;\n });\n}\n\n/**\n * Handle submitting event requests to OnUserInput including unwrapping potential errors.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param snapId - The Snap ID.\n * @param id - The interface ID.\n * @param event - The event to submit.\n * @param context - The interface context.\n */\nasync function handleEvent(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n id: string,\n event: UserInputEvent,\n context: InterfaceContext | null,\n) {\n try {\n await controllerMessenger.call(\n 'ExecutionService:handleRpcRequest',\n snapId,\n {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event,\n id,\n context,\n },\n },\n },\n );\n } catch (error) {\n const [unwrapped] = unwrapError(error);\n throw unwrapped;\n }\n}\n\n/**\n * Click on an element of the Snap interface.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface content.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n */\nexport async function clickElement(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n): Promise<void> {\n const result = getElement(content, name);\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Button' || result.element.type === 'Checkbox',\n `Expected an element of type \"Button\" or \"Checkbox\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const { type } = result.element;\n const elementName = result.element.props.name;\n\n const formState = (result.form ? state[result.form] : state) as FormState;\n const currentValue = formState[elementName];\n\n switch (type) {\n case 'Button': {\n // Button click events are always triggered.\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.ButtonClickEvent,\n name: elementName,\n },\n context,\n );\n\n if (result.form && result.element.props.type === 'submit') {\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.FormSubmitEvent,\n name: result.form,\n value: state[result.form] as FormState,\n },\n context,\n );\n }\n break;\n }\n\n case 'Checkbox': {\n const newValue = !currentValue;\n const newState = mergeValue(state, name, newValue, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.InputChangeEvent,\n name: elementName,\n value: newValue,\n },\n context,\n );\n break;\n }\n\n /* istanbul ignore next */\n default:\n assertExhaustive(type);\n }\n}\n\n/**\n * Merge a value in the interface state.\n *\n * @param state - The actual interface state.\n * @param name - The component name that changed value.\n * @param value - The new value.\n * @param form - The form name if the element is in one.\n * @returns The state with the merged value.\n */\nexport function mergeValue(\n state: InterfaceState,\n name: string,\n value: string | File | boolean | null,\n form?: string,\n): InterfaceState {\n if (form) {\n return {\n ...state,\n [form]: {\n ...(state[form] as FormState),\n [name]: value,\n },\n };\n }\n\n return { ...state, [name]: value };\n}\n\n/**\n * Process the input value for an input element based on the element type.\n *\n * @param value - The original input value.\n * @param element - The interface element.\n * @returns The processed value.\n */\nfunction processInputValue(value: string, element: NamedJSXElement): string {\n if (element.type === 'AddressInput') {\n const { chainId } = element.props;\n return `${chainId}:${value}`;\n }\n\n return value;\n}\n\n/**\n * Type a value in an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function typeInField(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n TYPEABLE_INPUTS.includes(result.element.type),\n `Expected an element of type ${formatTypeErrorMessage(TYPEABLE_INPUTS)}, but found \"${result.element.type}\".`,\n );\n\n const newValue = processInputValue(value, result.element);\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, newValue, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value: newValue,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Type a value in an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function selectInDropdown(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Dropdown',\n `Expected an element of type \"Dropdown\", but found \"${result.element.type}\".`,\n );\n\n const options = getJsxChildren(result.element) as JSXElement[];\n const selectedOption = options.find(\n (option) =>\n hasProperty(option.props, 'value') && option.props.value === value,\n );\n\n assert(\n selectedOption !== undefined,\n `The dropdown with the name \"${name}\" does not contain \"${value}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, value, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Choose an option with value from radio group interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function selectFromRadioGroup(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'RadioGroup',\n `Expected an element of type \"RadioGroup\", but found \"${result.element.type}\".`,\n );\n\n const options = getJsxChildren(result.element) as JSXElement[];\n const selectedOption = options.find(\n (option) =>\n hasProperty(option.props, 'value') && option.props.value === value,\n );\n\n assert(\n selectedOption !== undefined,\n `The RadioGroup with the name \"${name}\" does not contain \"${value}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, value, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Choose an option with value from Selector interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function selectFromSelector(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Selector',\n `Expected an element of type \"Selector\", but found \"${result.element.type}\".`,\n );\n\n const options = getJsxChildren(result.element) as JSXElement[];\n const selectedOption = options.find(\n (option) =>\n hasProperty(option.props, 'value') && option.props.value === value,\n );\n\n assert(\n selectedOption !== undefined,\n `The Selector with the name \"${name}\" does not contain \"${value}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, value, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Wait for an interface to be updated.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param snapId - The Snap ID.\n * @param id - The interface ID.\n * @param originalContent - The original interface content.\n * @returns A promise that resolves to the updated interface.\n */\nexport async function waitForUpdate(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n id: string,\n originalContent: JSXElement,\n) {\n return new Promise<SnapHandlerInterface>((resolve) => {\n const listener = (state: SnapInterfaceControllerState) => {\n const currentInterface = state.interfaces[id];\n const newContent = currentInterface?.content;\n\n if (!deepEqual(originalContent, newContent)) {\n controllerMessenger.unsubscribe(\n 'SnapInterfaceController:stateChange',\n listener,\n );\n\n const actions = getInterfaceActions(snapId, controllerMessenger, {\n content: newContent,\n id,\n });\n\n resolve({ ...actions, content: newContent });\n }\n };\n\n controllerMessenger.subscribe(\n 'SnapInterfaceController:stateChange',\n listener,\n );\n });\n}\n\n/**\n * Get a formatted file size.\n *\n * @param size - The file size in bytes.\n * @returns The formatted file size in MB, with two decimal places.\n * @example\n * getFormattedFileSize(1_000_000); // '1.00 MB'\n */\nfunction getFormattedFileSize(size: number) {\n return `${(size / 1_000_000).toFixed(2)} MB`;\n}\n\n/**\n * Upload a file to an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\nexport async function uploadFile(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'FileInput',\n `Expected an element of type \"FileInput\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const fileSize = await getFileSize(file);\n if (fileSize > MAX_FILE_SIZE) {\n throw new Error(\n `The file size (${getFormattedFileSize(\n fileSize,\n )}) exceeds the maximum allowed size of ${getFormattedFileSize(\n MAX_FILE_SIZE,\n )}.`,\n );\n }\n\n const fileObject = await getFileToUpload(file, options);\n const newState = mergeValue(state, name, fileObject, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.FileUploadEvent,\n name: result.element.props.name,\n file: fileObject,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Get the user interface actions for a Snap interface. These actions can be\n * used to interact with the interface.\n *\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param interface - The interface object.\n * @param interface.content - The interface content.\n * @param interface.id - The interface ID.\n * @returns The user interface actions.\n */\nexport function getInterfaceActions(\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n { content, id }: Omit<Interface, 'type'> & { content: JSXElement },\n): SnapInterfaceActions {\n return {\n clickElement: async (name: string) => {\n await clickElement(controllerMessenger, id, content, snapId, name);\n },\n\n typeInField: async (name: string, value: string) => {\n await typeInField(controllerMessenger, id, content, snapId, name, value);\n },\n\n selectInDropdown: async (name: string, value: string) => {\n await selectInDropdown(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n value,\n );\n },\n\n selectFromRadioGroup: async (name: string, value: string) => {\n await selectFromRadioGroup(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n value,\n );\n },\n\n selectFromSelector: async (name: string, value: string) => {\n await selectFromSelector(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n value,\n );\n },\n\n uploadFile: async (\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ) => {\n await uploadFile(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n file,\n options,\n );\n },\n\n waitForUpdate: async () =>\n waitForUpdate(controllerMessenger, snapId, id, content),\n };\n}\n\n/**\n * Get a user interface object from a Snap.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger used to call actions.\n * @yields Takes the set interface action.\n * @returns The user interface object.\n */\nexport function* getInterface(\n runSaga: RunSagaFunction,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): SagaIterator {\n const storedInterface = yield call(\n getStoredInterface,\n controllerMessenger,\n snapId,\n );\n\n const interfaceActions = getInterfaceActions(\n snapId,\n controllerMessenger,\n storedInterface,\n );\n\n return getInterfaceResponse(\n runSaga,\n storedInterface.type,\n storedInterface.id,\n storedInterface.content,\n interfaceActions,\n );\n}\n"]}
1
+ {"version":3,"file":"interface.cjs","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;;;;AAEA,mEAAoE;AAYpE,mDAA6E;AAM7E,uDAO+B;AAC/B,2CAIyB;AAEzB,sEAAwC;AAExC,gDAA6D;AAE7D,+CAA8C;AAE9C,uCAAuD;AAGvD,6CAA8E;AAO9E,+CAAwD;AACxD;;GAEG;AACH,MAAM,aAAa,GAAG,QAAU,CAAC,CAAC,QAAQ;AAE1C;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC;AAE3E;;;;;;;;;GASG;AACH,SAAgB,oBAAoB,CAClC,OAAwB,EACxB,IAAkE,EAClE,EAAU,EACV,OAAmB,EACnB,gBAAsC;IAEtC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,yCAAqB,CAAC,sBAAU,CAAC,KAAK,CAAC;YAC1C,OAAO;gBACL,GAAG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AY,EAAE,KAAa,EAAE,EAAE;YAC1D,MAAM,oBAAoB,CACxB,mBAAmB,EACnB,EAAE,EACF,OAAO,EACP,MAAM,EACN,IAAI,EACJ,KAAK,CACN,CAAC;QACJ,CAAC;QAED,kBAAkB,EAAE,KAAK,EAAE,IAAY,EAAE,KAAa,EAAE,EAAE;YACxD,MAAM,kBAAkB,CACtB,mBAAmB,EACnB,iBAAiB,EACjB,EAAE,EACF,OAAO,EACP,MAAM,EACN,IAAI,EACJ,KAAK,CACN,CAAC;QACJ,CAAC;QAED,UAAU,EAAE,KAAK,EACf,IAAY,EACZ,IAAyB,EACzB,OAAqB,EACrB,EAAE;YACF,MAAM,UAAU,CACd,mBAAmB,EACnB,EAAE,EACF,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,CACR,CAAC;QACJ,CAAC;QAED,aAAa,EAAE,KAAK,IAAI,EAAE,CACxB,aAAa,CACX,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,EACN,EAAE,EACF,OAAO,CACR;KACJ,CAAC;AACJ,CAAC;AA1ED,kDA0EC;AAED;;;;;;;;;GASG;AACH,QAAe,CAAC,CAAC,YAAY,CAC3B,OAAwB,EACxB,MAAc,EACd,mBAA4C,EAC5C,OAA0B;IAE1B,MAAM,eAAe,GAAG,MAAM,IAAA,cAAI,EAChC,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,CACP,CAAC;IAEF,MAAM,gBAAgB,GAAG,mBAAmB,CAC1C,MAAM,EACN,mBAAmB,EACnB,OAAO,EACP,eAAe,CAChB,CAAC;IAEF,OAAO,oBAAoB,CACzB,OAAO,EACP,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,EAAE,EAClB,eAAe,CAAC,OAAO,EACvB,gBAAgB,CACjB,CAAC;AACJ,CAAC;AA1BD,oCA0BC","sourcesContent":["import type { SnapInterfaceControllerState } from '@metamask/snaps-controllers';\nimport type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n FormState,\n InterfaceContext,\n InterfaceState,\n SnapId,\n UserInputEvent,\n File,\n AccountSelectorState,\n AssetSelectorState,\n CaipAssetType,\n} from '@metamask/snaps-sdk';\nimport { DialogType, UserInputEventType, assert } from '@metamask/snaps-sdk';\nimport type {\n FooterElement,\n FormElement,\n JSXElement,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n HandlerType,\n createAccountList,\n createChainIdList,\n getJsxChildren,\n unwrapError,\n walkJsx,\n} from '@metamask/snaps-utils';\nimport {\n assertExhaustive,\n hasProperty,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport deepEqual from 'fast-deep-equal';\nimport { type SagaIterator } from 'redux-saga';\nimport { call, put, select, take } from 'redux-saga/effects';\n\nimport { TYPEABLE_INPUTS } from './constants';\nimport type { RootControllerMessenger } from './controllers';\nimport { getFileSize, getFileToUpload } from './files';\nimport type { SimulationOptions } from './options';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\nimport type {\n FileOptions,\n SnapHandlerInterface,\n SnapInterface,\n SnapInterfaceActions,\n} from './types';\nimport { formatTypeErrorMessage } from './utils/errors';\n/**\n * The maximum file size that can be uploaded.\n */\nconst MAX_FILE_SIZE = 10_000_000; // 10 MB\n\n/**\n * The elements based on the Selector component.\n */\nconst SELECTOR_ELEMENTS = ['Selector', 'AccountSelector', 'AssetSelector'];\n\n/**\n * Get a user interface object from a type and content object.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param type - The type of the interface.\n * @param id - The interface ID.\n * @param content - The content to show in the interface.\n * @param interfaceActions - The actions to interact with the interface.\n * @returns The user interface object.\n */\nexport function getInterfaceResponse(\n runSaga: RunSagaFunction,\n type: DialogApprovalTypes[DialogType | 'default'] | 'Notification',\n id: string,\n content: JSXElement,\n interfaceActions: SnapInterfaceActions,\n): SnapInterface {\n switch (type) {\n case DIALOG_APPROVAL_TYPES[DialogType.Alert]:\n return {\n ...interfaceActions,\n type: DialogType.Alert,\n content,\n id,\n\n ok: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Confirmation]:\n return {\n ...interfaceActions,\n type: DialogType.Confirmation,\n content,\n id,\n\n ok: resolveWith(runSaga, true),\n cancel: resolveWith(runSaga, false),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Prompt]:\n return {\n ...interfaceActions,\n type: DialogType.Prompt,\n content,\n id,\n\n ok: resolveWithInput(runSaga),\n cancel: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES.default: {\n const footer = getElementByType<FooterElement>(content, 'Footer');\n\n // No Footer defined so we apply a default footer.\n if (!footer) {\n return {\n ...interfaceActions,\n content,\n id,\n\n ok: resolveWith(runSaga, null),\n cancel: resolveWith(runSaga, null),\n };\n }\n\n // Only one button in footer so we apply a default cancel button.\n if (getJsxChildren(footer).length === 1) {\n return {\n ...interfaceActions,\n content,\n id,\n\n cancel: resolveWith(runSaga, null),\n };\n }\n\n // We have two buttons in the footer so we assume the snap handles the approval of the interface.\n return {\n ...interfaceActions,\n content,\n id,\n };\n }\n\n case 'Notification': {\n return {\n ...interfaceActions,\n content,\n id,\n };\n }\n\n default:\n throw new Error(`Unknown or unsupported dialog type: \"${String(type)}\".`);\n }\n}\n\n/**\n * Resolve the current user interface with the given value.\n *\n * @param value - The value to resolve the user interface with.\n * @yields Puts the resolve user interface action.\n */\nexport function* resolveWithSaga(value: unknown): SagaIterator {\n yield put(resolveInterface(value));\n}\n\n/**\n * Resolve the current user interface with the given value. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param value - The value to resolve the user interface with.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWith(runSaga: RunSagaFunction, value: unknown) {\n return async () => {\n await runSaga(resolveWithSaga, value).toPromise();\n };\n}\n\n/**\n * Resolve the current user interface with the provided input. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWithInput(runSaga: RunSagaFunction) {\n return async (value = '') => {\n await runSaga(resolveWithSaga, value).toPromise();\n };\n}\n\n/**\n * Get the stored user interface from the store.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param snapId - The Snap ID.\n * @yields Takes the set interface action.\n * @returns The user interface object.\n */\nfunction* getStoredInterface(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n): SagaIterator<Interface & { content: JSXElement }> {\n const currentInterface: Interface | null = yield select(getCurrentInterface);\n\n if (currentInterface) {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n currentInterface.id,\n );\n\n return { ...currentInterface, content };\n }\n\n const { payload }: PayloadAction<Interface> = yield take(setInterface.type);\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n payload.id,\n );\n\n return { ...payload, content };\n}\n\n/**\n * A JSX element with a name.\n */\nexport type NamedJSXElement = JSXElement & { props: { name: string } };\n\n/**\n * Check if a JSX element is a JSX element with a given name.\n *\n * @param element - The JSX element.\n * @param name - The element name.\n * @returns True if the element is a JSX element with the given name, otherwise\n * false.\n */\nfunction isJSXElementWithName<Element extends JSXElement, Name extends string>(\n element: Element,\n name: Name,\n): element is Element & { props: { name: Name } } {\n return hasProperty(element.props, 'name') && element.props.name === name;\n}\n\n/**\n * Find an element inside a form element in a JSX tree.\n *\n * @param form - The form element.\n * @param name - The element name.\n * @returns An object containing the element and the form name if it's contained\n * in a form, otherwise undefined.\n */\nfunction getFormElement(form: FormElement, name: string) {\n const element = walkJsx<NamedJSXElement>(form, (childElement) => {\n if (isJSXElementWithName(childElement, name)) {\n return childElement;\n }\n\n return undefined;\n });\n\n if (element === undefined) {\n return undefined;\n }\n\n return { element, form: form.props.name };\n}\n\n/**\n * Get an object containing the element, and optional form that's associated\n * with the element if any.\n *\n * @param element - The JSX element.\n * @returns An object containing the element and optional form.\n */\nfunction getElementWithOptionalForm(element: NamedJSXElement): {\n element: NamedJSXElement;\n form?: string;\n} {\n if (element.type !== 'Button' || !element.props.form) {\n return { element };\n }\n\n return { element, form: element.props.form };\n}\n\n/**\n * Get an element from a JSX tree with the given name.\n *\n * @param content - The interface content.\n * @param name - The element name.\n * @returns An object containing the element and the form name if it's contained\n * in a form, otherwise undefined.\n */\nexport function getElement(\n content: JSXElement,\n name: string,\n):\n | {\n element: NamedJSXElement;\n form?: string;\n }\n | undefined {\n if (isJSXElementWithName(content, name)) {\n return getElementWithOptionalForm(content);\n }\n\n return walkJsx(content, (element) => {\n if (element.type === 'Form') {\n return getFormElement(element, name);\n }\n\n if (isJSXElementWithName(element, name)) {\n return getElementWithOptionalForm(element);\n }\n\n return undefined;\n });\n}\n\n/**\n * Get an element from a JSX tree with the given type.\n *\n * @param content - The interface content.\n * @param type - The element type.\n * @returns The element with the given type.\n */\nexport function getElementByType<Element extends JSXElement>(\n content: JSXElement,\n type: string,\n) {\n return walkJsx(content, (element) => {\n if (element.type === type) {\n return element as Element;\n }\n\n return undefined;\n });\n}\n\n/**\n * Handle submitting event requests to OnUserInput including unwrapping potential errors.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param snapId - The Snap ID.\n * @param id - The interface ID.\n * @param event - The event to submit.\n * @param context - The interface context.\n */\nasync function handleEvent(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n id: string,\n event: UserInputEvent,\n context: InterfaceContext | null,\n) {\n try {\n await controllerMessenger.call(\n 'ExecutionService:handleRpcRequest',\n snapId,\n {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event,\n id,\n context,\n },\n },\n },\n );\n } catch (error) {\n const [unwrapped] = unwrapError(error);\n throw unwrapped;\n }\n}\n\n/**\n * Click on an element of the Snap interface.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface content.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n */\nexport async function clickElement(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n): Promise<void> {\n const result = getElement(content, name);\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Button' || result.element.type === 'Checkbox',\n `Expected an element of type \"Button\" or \"Checkbox\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const { type } = result.element;\n const elementName = result.element.props.name;\n\n const formState = (result.form ? state[result.form] : state) as FormState;\n const currentValue = formState[elementName];\n\n switch (type) {\n case 'Button': {\n // Button click events are always triggered.\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.ButtonClickEvent,\n name: elementName,\n },\n context,\n );\n\n if (result.form && result.element.props.type === 'submit') {\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.FormSubmitEvent,\n name: result.form,\n value: state[result.form] as FormState,\n },\n context,\n );\n }\n break;\n }\n\n case 'Checkbox': {\n const newValue = !currentValue;\n const newState = mergeValue(state, name, newValue, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.InputChangeEvent,\n name: elementName,\n value: newValue,\n },\n context,\n );\n break;\n }\n\n /* istanbul ignore next */\n default:\n assertExhaustive(type);\n }\n}\n\n/**\n * Merge a value in the interface state.\n *\n * @param state - The actual interface state.\n * @param name - The component name that changed value.\n * @param value - The new value.\n * @param form - The form name if the element is in one.\n * @returns The state with the merged value.\n */\nexport function mergeValue(\n state: InterfaceState,\n name: string,\n value:\n | string\n | File\n | boolean\n | AccountSelectorState\n | AssetSelectorState\n | null,\n form?: string,\n): InterfaceState {\n if (form) {\n return {\n ...state,\n [form]: {\n ...(state[form] as FormState),\n [name]: value,\n },\n };\n }\n\n return { ...state, [name]: value };\n}\n\n/**\n * Process the input value for an input element based on the element type.\n *\n * @param value - The original input value.\n * @param element - The interface element.\n * @returns The processed value.\n */\nfunction processInputValue(value: string, element: NamedJSXElement): string {\n if (element.type === 'AddressInput') {\n const { chainId } = element.props;\n return `${chainId}:${value}`;\n }\n\n return value;\n}\n\n/**\n * Type a value in an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function typeInField(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n TYPEABLE_INPUTS.includes(result.element.type),\n `Expected an element of type ${formatTypeErrorMessage(TYPEABLE_INPUTS)}, but found \"${result.element.type}\".`,\n );\n\n const newValue = processInputValue(value, result.element);\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, newValue, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value: newValue,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Type a value in an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function selectInDropdown(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Dropdown',\n `Expected an element of type \"Dropdown\", but found \"${result.element.type}\".`,\n );\n\n const options = getJsxChildren(result.element) as JSXElement[];\n const selectedOption = options.find(\n (option) =>\n hasProperty(option.props, 'value') && option.props.value === value,\n );\n\n assert(\n selectedOption !== undefined,\n `The dropdown with the name \"${name}\" does not contain \"${value}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, value, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Choose an option with value from radio group interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function selectFromRadioGroup(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'RadioGroup',\n `Expected an element of type \"RadioGroup\", but found \"${result.element.type}\".`,\n );\n\n const options = getJsxChildren(result.element) as JSXElement[];\n const selectedOption = options.find(\n (option) =>\n hasProperty(option.props, 'value') && option.props.value === value,\n );\n\n assert(\n selectedOption !== undefined,\n `The RadioGroup with the name \"${name}\" does not contain \"${value}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, value, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Get the value from a Selector interface element.\n *\n * @param element - The Selector element to get the value from.\n * @param options - The simulation options.\n * @param value - The value to get from the Selector.\n *\n * @returns The value from the Selector element.\n */\nexport function getValueFromSelector(\n element: NamedJSXElement,\n options: SimulationOptions,\n value: string,\n) {\n switch (element.type) {\n case 'Selector': {\n const selectorOptions = getJsxChildren(element) as JSXElement[];\n const selectedOption = selectorOptions.find(\n (option) =>\n hasProperty(option.props, 'value') && option.props.value === value,\n );\n\n assert(\n selectedOption !== undefined,\n `The Selector with the name \"${element.props.name}\" does not contain \"${value}\".`,\n );\n\n return value;\n }\n\n case 'AccountSelector': {\n const { accounts } = options;\n\n const selectedAccount = accounts.find((account) => account.id === value);\n\n assert(\n selectedAccount !== undefined,\n `The AccountSelector with the name \"${element.props.name}\" does not contain an account with ID \"${value}\".`,\n );\n\n return {\n accountId: selectedAccount.id,\n addresses: createAccountList(\n selectedAccount.address,\n createChainIdList(selectedAccount.scopes, element.props.chainIds),\n ),\n };\n }\n\n case 'AssetSelector': {\n const { assets, accounts } = options;\n\n const selectedAsset = assets[value as CaipAssetType];\n\n const { address } = parseCaipAccountId(element.props.addresses[0]);\n\n const account = accounts.find(\n (simulationAccount) => simulationAccount.address === address,\n );\n\n const accountHasAsset = account?.assets?.some((asset) => asset === value);\n\n assert(\n selectedAsset !== undefined && accountHasAsset,\n `The AssetSelector with the name \"${element.props.name}\" does not contain an asset with ID \"${value}\".`,\n );\n\n return {\n asset: value as CaipAssetType,\n name: selectedAsset.name,\n symbol: selectedAsset.symbol,\n };\n }\n\n default:\n throw new Error(\n `Expected an element of type ${formatTypeErrorMessage(SELECTOR_ELEMENTS)}, but found \"${element.type}\".`,\n );\n }\n}\n\n/**\n * Choose an option with value from a Selector interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param options - The simulation options.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function selectFromSelector(\n controllerMessenger: RootControllerMessenger,\n options: SimulationOptions,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n const selectedValue = getValueFromSelector(result.element, options, value);\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, selectedValue, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value: selectedValue,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Wait for an interface to be updated.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param options - The simulation options.\n * @param snapId - The Snap ID.\n * @param id - The interface ID.\n * @param originalContent - The original interface content.\n * @returns A promise that resolves to the updated interface.\n */\nexport async function waitForUpdate(\n controllerMessenger: RootControllerMessenger,\n options: SimulationOptions,\n snapId: SnapId,\n id: string,\n originalContent: JSXElement,\n) {\n return new Promise<SnapHandlerInterface>((resolve) => {\n const listener = (state: SnapInterfaceControllerState) => {\n const currentInterface = state.interfaces[id];\n const newContent = currentInterface?.content;\n\n if (!deepEqual(originalContent, newContent)) {\n controllerMessenger.unsubscribe(\n 'SnapInterfaceController:stateChange',\n listener,\n );\n\n const actions = getInterfaceActions(\n snapId,\n controllerMessenger,\n options,\n {\n content: newContent,\n id,\n },\n );\n\n resolve({ ...actions, content: newContent });\n }\n };\n\n controllerMessenger.subscribe(\n 'SnapInterfaceController:stateChange',\n listener,\n );\n });\n}\n\n/**\n * Get a formatted file size.\n *\n * @param size - The file size in bytes.\n * @returns The formatted file size in MB, with two decimal places.\n * @example\n * getFormattedFileSize(1_000_000); // '1.00 MB'\n */\nfunction getFormattedFileSize(size: number) {\n return `${(size / 1_000_000).toFixed(2)} MB`;\n}\n\n/**\n * Upload a file to an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\nexport async function uploadFile(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'FileInput',\n `Expected an element of type \"FileInput\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const fileSize = await getFileSize(file);\n if (fileSize > MAX_FILE_SIZE) {\n throw new Error(\n `The file size (${getFormattedFileSize(\n fileSize,\n )}) exceeds the maximum allowed size of ${getFormattedFileSize(\n MAX_FILE_SIZE,\n )}.`,\n );\n }\n\n const fileObject = await getFileToUpload(file, options);\n const newState = mergeValue(state, name, fileObject, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: 'metamask',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.FileUploadEvent,\n name: result.element.props.name,\n file: fileObject,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Get the user interface actions for a Snap interface. These actions can be\n * used to interact with the interface.\n *\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param simulationOptions - The simulation options.\n * @param interface - The interface object.\n * @param interface.content - The interface content.\n * @param interface.id - The interface ID.\n * @returns The user interface actions.\n */\nexport function getInterfaceActions(\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n simulationOptions: SimulationOptions,\n { content, id }: Omit<Interface, 'type'> & { content: JSXElement },\n): SnapInterfaceActions {\n return {\n clickElement: async (name: string) => {\n await clickElement(controllerMessenger, id, content, snapId, name);\n },\n\n typeInField: async (name: string, value: string) => {\n await typeInField(controllerMessenger, id, content, snapId, name, value);\n },\n\n selectInDropdown: async (name: string, value: string) => {\n await selectInDropdown(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n value,\n );\n },\n\n selectFromRadioGroup: async (name: string, value: string) => {\n await selectFromRadioGroup(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n value,\n );\n },\n\n selectFromSelector: async (name: string, value: string) => {\n await selectFromSelector(\n controllerMessenger,\n simulationOptions,\n id,\n content,\n snapId,\n name,\n value,\n );\n },\n\n uploadFile: async (\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ) => {\n await uploadFile(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n file,\n options,\n );\n },\n\n waitForUpdate: async () =>\n waitForUpdate(\n controllerMessenger,\n simulationOptions,\n snapId,\n id,\n content,\n ),\n };\n}\n\n/**\n * Get a user interface object from a Snap.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param options - The simulation options.\n * @yields Takes the set interface action.\n * @returns The user interface object.\n */\nexport function* getInterface(\n runSaga: RunSagaFunction,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n options: SimulationOptions,\n): SagaIterator {\n const storedInterface = yield call(\n getStoredInterface,\n controllerMessenger,\n snapId,\n );\n\n const interfaceActions = getInterfaceActions(\n snapId,\n controllerMessenger,\n options,\n storedInterface,\n );\n\n return getInterfaceResponse(\n runSaga,\n storedInterface.type,\n storedInterface.id,\n storedInterface.content,\n interfaceActions,\n );\n}\n"]}