@metamask/snaps-simulation 1.1.0 → 1.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.
- package/CHANGELOG.md +23 -1
- package/dist/helpers.cjs +14 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +8 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +8 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +14 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/interface.cjs +15 -2
- package/dist/interface.cjs.map +1 -1
- package/dist/interface.d.cts.map +1 -1
- package/dist/interface.d.mts.map +1 -1
- package/dist/interface.mjs +15 -2
- package/dist/interface.mjs.map +1 -1
- package/dist/methods/constants.cjs +0 -1
- package/dist/methods/constants.cjs.map +1 -1
- package/dist/methods/constants.d.cts.map +1 -1
- package/dist/methods/constants.d.mts.map +1 -1
- package/dist/methods/constants.mjs +0 -1
- package/dist/methods/constants.mjs.map +1 -1
- package/dist/structs.cjs +0 -1
- package/dist/structs.cjs.map +1 -1
- package/dist/structs.d.cts +2 -2
- package/dist/structs.d.cts.map +1 -1
- package/dist/structs.d.mts +2 -2
- package/dist/structs.d.mts.map +1 -1
- package/dist/structs.mjs +0 -1
- package/dist/structs.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +11 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +11 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add support for button `form` property ([#2830](https://github.com/MetaMask/snaps/pull/2830))
|
|
15
|
+
- Add function to test `onKeyringRequest` ([#2777](https://github.com/MetaMask/snaps/pull/2777))
|
|
16
|
+
- The `onKeyringRequest` function can be used to test keyring requests.
|
|
17
|
+
|
|
18
|
+
## [1.1.1]
|
|
19
|
+
|
|
20
|
+
### Removed
|
|
21
|
+
|
|
22
|
+
- Remove `eth_sign` ([#2772](https://github.com/MetaMask/snaps/pull/2772))
|
|
23
|
+
- This method was removed from the MetaMask extension, so any references to it
|
|
24
|
+
in Snaps can be removed.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Add missing dependency on `@metamask/snaps-execution-environments` ([#2791](https://github.com/MetaMask/snaps/pull/2791))
|
|
29
|
+
|
|
10
30
|
## [1.1.0]
|
|
11
31
|
|
|
12
32
|
### Changed
|
|
@@ -25,7 +45,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
25
45
|
|
|
26
46
|
- Initial release of `@metamask/snaps-simulation` package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
|
|
27
47
|
|
|
28
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@1.
|
|
48
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@1.2.0...HEAD
|
|
49
|
+
[1.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@1.1.1...@metamask/snaps-simulation@1.2.0
|
|
50
|
+
[1.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@1.1.0...@metamask/snaps-simulation@1.1.1
|
|
29
51
|
[1.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@1.0.1...@metamask/snaps-simulation@1.1.0
|
|
30
52
|
[1.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@1.0.0...@metamask/snaps-simulation@1.0.1
|
|
31
53
|
[1.0.0]: https://github.com/MetaMask/snaps/releases/tag/@metamask/snaps-simulation@1.0.0
|
package/dist/helpers.cjs
CHANGED
|
@@ -56,6 +56,19 @@ function getHelpers({ snapId, store, executionService, runSaga, controllerMessen
|
|
|
56
56
|
request,
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
|
+
const onKeyringRequest = async (request) => {
|
|
60
|
+
log('Sending keyring request %o.', request);
|
|
61
|
+
const response = await (0, request_1.handleRequest)({
|
|
62
|
+
snapId,
|
|
63
|
+
store,
|
|
64
|
+
executionService,
|
|
65
|
+
runSaga,
|
|
66
|
+
controllerMessenger,
|
|
67
|
+
handler: snaps_utils_1.HandlerType.OnKeyringRequest,
|
|
68
|
+
request,
|
|
69
|
+
});
|
|
70
|
+
return response;
|
|
71
|
+
};
|
|
59
72
|
return {
|
|
60
73
|
request: (request) => {
|
|
61
74
|
log('Sending request %o.', request);
|
|
@@ -71,6 +84,7 @@ function getHelpers({ snapId, store, executionService, runSaga, controllerMessen
|
|
|
71
84
|
},
|
|
72
85
|
onTransaction,
|
|
73
86
|
sendTransaction: onTransaction,
|
|
87
|
+
onKeyringRequest,
|
|
74
88
|
onSignature: async (request) => {
|
|
75
89
|
log('Requesting signature %o.', request);
|
|
76
90
|
const { origin: signatureOrigin, ...signature } = (0, superstruct_1.create)(request, structs_1.SignatureOptionsStruct);
|
package/dist/helpers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,uDAA+C;AAC/C,2CAAqD;AAErD,yCAAsC;AAEtC,2CAA0C;AAE1C,6CAA4D;AAC5D,2CAKmB;AAWnB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,mBAAU,EAAE,SAAS,CAAC,CAAC;AA8HtD;;;;;;;;;;;GAWG;AACH,SAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACwC;IAC/C,MAAM,aAAa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,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,IAAA,yBAAiB,EAAC,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;AAnJD,gCAmJC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\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 SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\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 * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\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 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 return {\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 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\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 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.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,uDAA+C;AAC/C,2CAAqD;AAErD,yCAAsC;AAEtC,2CAA0C;AAE1C,6CAA4D;AAC5D,2CAKmB;AAanB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,mBAAU,EAAE,SAAS,CAAC,CAAC;AAwItD;;;;;;;;;;;GAWG;AACH,SAAgB,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;Q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AAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,oBAAM,EAAC,IAAI,EAAE,kCAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,IAAA,sBAAc,EAAC,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,IAAA,yBAAiB,EAAC,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;AAvKD,gCAuKC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\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 SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\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 * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): 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(\n keyringRequest: KeyringOptions,\n ): Promise<SnapResponseWithoutInterface>;\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 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 const onKeyringRequest = async (\n request: KeyringOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Sending keyring request %o.', request);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n\n return response;\n };\n\n return {\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 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\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 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"]}
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SimulationOptions } from "./options.cjs";
|
|
2
2
|
import type { InstalledSnap } from "./simulation.cjs";
|
|
3
|
-
import type { CronjobOptions, JsonRpcMockOptions, RequestOptions, SignatureOptions, SnapRequest, SnapResponseWithInterface, TransactionOptions } from "./types.cjs";
|
|
3
|
+
import type { CronjobOptions, JsonRpcMockOptions, KeyringOptions, RequestOptions, SignatureOptions, SnapRequest, SnapResponseWithInterface, SnapResponseWithoutInterface, TransactionOptions } from "./types.cjs";
|
|
4
4
|
/**
|
|
5
5
|
* This is the main entry point to interact with the snap. It is returned by
|
|
6
6
|
* {@link installSnap}, and has methods to send requests to the snap.
|
|
@@ -77,6 +77,13 @@ export type SnapHelpers = {
|
|
|
77
77
|
* @returns The response.
|
|
78
78
|
*/
|
|
79
79
|
onHomePage(): Promise<SnapResponseWithInterface>;
|
|
80
|
+
/**
|
|
81
|
+
* Send a keyring request to the Snap.
|
|
82
|
+
*
|
|
83
|
+
* @param keyringRequest - Keyring request.
|
|
84
|
+
* @returns The response.
|
|
85
|
+
*/
|
|
86
|
+
onKeyringRequest(keyringRequest: KeyringOptions): Promise<SnapResponseWithoutInterface>;
|
|
80
87
|
/**
|
|
81
88
|
* Mock a JSON-RPC request. This will cause the snap to respond with the
|
|
82
89
|
* specified response when a request with the specified method is sent.
|
package/dist/helpers.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAqB;AAQlD,OAAO,KAAK,EACV,cAA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AI,IAAI,CAAC;KAChB,CAAC;IAEF;;;;;OAKG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACR,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,GAAG,WAAW,CAgK9D"}
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SimulationOptions } from "./options.mjs";
|
|
2
2
|
import type { InstalledSnap } from "./simulation.mjs";
|
|
3
|
-
import type { CronjobOptions, JsonRpcMockOptions, RequestOptions, SignatureOptions, SnapRequest, SnapResponseWithInterface, TransactionOptions } from "./types.mjs";
|
|
3
|
+
import type { CronjobOptions, JsonRpcMockOptions, KeyringOptions, RequestOptions, SignatureOptions, SnapRequest, SnapResponseWithInterface, SnapResponseWithoutInterface, TransactionOptions } from "./types.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* This is the main entry point to interact with the snap. It is returned by
|
|
6
6
|
* {@link installSnap}, and has methods to send requests to the snap.
|
|
@@ -77,6 +77,13 @@ export type SnapHelpers = {
|
|
|
77
77
|
* @returns The response.
|
|
78
78
|
*/
|
|
79
79
|
onHomePage(): Promise<SnapResponseWithInterface>;
|
|
80
|
+
/**
|
|
81
|
+
* Send a keyring request to the Snap.
|
|
82
|
+
*
|
|
83
|
+
* @param keyringRequest - Keyring request.
|
|
84
|
+
* @returns The response.
|
|
85
|
+
*/
|
|
86
|
+
onKeyringRequest(keyringRequest: KeyringOptions): Promise<SnapResponseWithoutInterface>;
|
|
80
87
|
/**
|
|
81
88
|
* Mock a JSON-RPC request. This will cause the snap to respond with the
|
|
82
89
|
* specified response when a request with the specified method is sent.
|
package/dist/helpers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
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AKG;IACH,gBAAgB,CACd,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAEzC;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG;QACrC;;WAEG;QACH,MAAM,IAAI,IAAI,CAAC;KAChB,CAAC;IAEF;;;;;OAKG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACR,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,GAAG,WAAW,CAgK9D"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -53,6 +53,19 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
|
|
|
53
53
|
request,
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
+
const onKeyringRequest = async (request) => {
|
|
57
|
+
log('Sending keyring request %o.', request);
|
|
58
|
+
const response = await handleRequest({
|
|
59
|
+
snapId,
|
|
60
|
+
store,
|
|
61
|
+
executionService,
|
|
62
|
+
runSaga,
|
|
63
|
+
controllerMessenger,
|
|
64
|
+
handler: HandlerType.OnKeyringRequest,
|
|
65
|
+
request,
|
|
66
|
+
});
|
|
67
|
+
return response;
|
|
68
|
+
};
|
|
56
69
|
return {
|
|
57
70
|
request: (request) => {
|
|
58
71
|
log('Sending request %o.', request);
|
|
@@ -68,6 +81,7 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
|
|
|
68
81
|
},
|
|
69
82
|
onTransaction,
|
|
70
83
|
sendTransaction: onTransaction,
|
|
84
|
+
onKeyringRequest,
|
|
71
85
|
onSignature: async (request) => {
|
|
72
86
|
log('Requesting signature %o.', request);
|
|
73
87
|
const { origin: signatureOrigin, ...signature } = create(request, SignatureOptionsStruct);
|
package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AAsB,CAAC,CAAC;YAE5B,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC;gBACnC,MAAM;gBACN,KAAK;gBACL,gBAAgB;gBAChB,mBAAmB;gBACnB,OAAO;gBACP,OAAO,EAAE,WAAW,CAAC,UAAU;gBAC/B,OAAO,EAAE;oBACP,MAAM,EAAE,EAAE;iBACX;aACF,CAAC,CAAC;YAEH,6BAA6B,CAAC,QAAQ,CAAC,CAAC;YAExC,OAAO,QAAQ,CAAC;QAClB,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 { 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 SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\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 * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\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 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 return {\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 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\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 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;AAC/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,sBAAsB,EACtB,wBAAwB,EACzB,sBAAkB;AAanB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAwItD;;;;;;;;;;;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,OAAO,EAAE,WAAW,CAAC,aAAa;YAClC,OAAO,EAAE;gBACP,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE;oBACN,OAAO;oBACP,WAAW;oBACX,iBAAiB;iBAClB;aACF;SACF,CAAC,CAAC;QAEH,6BAA6B,CAAC,QAAQ,CAAC,CAAC;QAExC,O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B,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\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 SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\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 * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): 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(\n keyringRequest: KeyringOptions,\n ): Promise<SnapResponseWithoutInterface>;\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 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 const onKeyringRequest = async (\n request: KeyringOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Sending keyring request %o.', request);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n\n return response;\n };\n\n return {\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 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\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 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"]}
|
package/dist/interface.cjs
CHANGED
|
@@ -160,6 +160,19 @@ function getFormElement(form, name) {
|
|
|
160
160
|
}
|
|
161
161
|
return { element, form: form.props.name };
|
|
162
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Get an object containing the element, and optional form that's associated
|
|
165
|
+
* with the element if any.
|
|
166
|
+
*
|
|
167
|
+
* @param element - The JSX element.
|
|
168
|
+
* @returns An object containing the element and optional form.
|
|
169
|
+
*/
|
|
170
|
+
function getElementWithOptionalForm(element) {
|
|
171
|
+
if (element.type !== 'Button' || !element.props.form) {
|
|
172
|
+
return { element };
|
|
173
|
+
}
|
|
174
|
+
return { element, form: element.props.form };
|
|
175
|
+
}
|
|
163
176
|
/**
|
|
164
177
|
* Get an element from a JSX tree with the given name.
|
|
165
178
|
*
|
|
@@ -170,14 +183,14 @@ function getFormElement(form, name) {
|
|
|
170
183
|
*/
|
|
171
184
|
function getElement(content, name) {
|
|
172
185
|
if (isJSXElementWithName(content, name)) {
|
|
173
|
-
return
|
|
186
|
+
return getElementWithOptionalForm(content);
|
|
174
187
|
}
|
|
175
188
|
return (0, snaps_utils_1.walkJsx)(content, (element) => {
|
|
176
189
|
if (element.type === 'Form') {
|
|
177
190
|
return getFormElement(element, name);
|
|
178
191
|
}
|
|
179
192
|
if (isJSXElementWithName(element, name)) {
|
|
180
|
-
return
|
|
193
|
+
return getElementWithOptionalForm(element);
|
|
181
194
|
}
|
|
182
195
|
return undefined;
|
|
183
196
|
});
|
package/dist/interface.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.cjs","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;AACA,mEAAoE;AASpE,mDAA6E;AAG7E,uDAK+B;AAC/B,2CAAgE;AAGhE,gDAA6D;AAG7D,uCAAuD;AAEvD,6CAA8E;AAG9E;;GAEG;AACH,MAAM,aAAa,GAAG,QAAU,CAAC,CAAC,QAAQ;AAE1C;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAClC,OAAwB,EACxB,IAAiD,EACjD,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,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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,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,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;KACF,CAAC;AACJ,CAAC;AA/DD,kDA+DC;AAED;;;;;;;;GAQG;AACH,QAAe,CAAC,CAAC,YAAY,CAC3B,OAAwB,EACxB,MAAc,EACd,mBAA4C;IAE5C,MAAM,eAAe,GAAG,MAAM,IAAA,cAAI,EAChC,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,CACP,CAAC;IAEF,MAAM,gBAAgB,GAAG,mBAAmB,CAC1C,MAAM,EACN,mBAAmB,EACnB,eAAe,CAChB,CAAC;IAEF,OAAO,oBAAoB,CACzB,OAAO,EACP,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,OAAO,EACvB,gBAAgB,CACjB,CAAC;AACJ,CAAC;AAvBD,oCAuBC","sourcesContent":["import 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 { FooterElement } from '@metamask/snaps-sdk/jsx';\nimport { type FormElement, type JSXElement } 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 { type SagaIterator } from 'redux-saga';\nimport { call, put, select, take } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getFileSize, getFileToUpload } from './files';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\nimport type { FileOptions, SnapInterface, SnapInterfaceActions } from './types';\n\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 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'],\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 ok: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Confirmation]:\n return {\n ...interfaceActions,\n type: DialogType.Confirmation,\n content,\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\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\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\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 };\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 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 { element: 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 { 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: '',\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 * 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 result.element.type === 'Input',\n `Expected an element of type \"Input\", but found \"${result.element.type}\".`,\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: '',\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 * 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: '',\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: '',\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: '',\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 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: '',\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}\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.content,\n interfaceActions,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interface.cjs","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":";;;AACA,mEAAoE;AASpE,mDAA6E;AAG7E,uDAK+B;AAC/B,2CAAgE;AAGhE,gDAA6D;AAG7D,uCAAuD;AAEvD,6CAA8E;AAG9E;;GAEG;AACH,MAAM,aAAa,GAAG,QAAU,CAAC,CAAC,QAAQ;AAE1C;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAClC,OAAwB,EACxB,IAAiD,EACjD,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,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;gBAEP,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;gBAEP,EAAE,EAAE,gBAAgB,CAAC,OAAO,CAAC;gBAC7B,MAAM,EAAE,WAAW,CAAC,OAAO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AM,EACN,IAAI,EACJ,KAAK,CACN,CAAC;QACJ,CAAC;QAED,kBAAkB,EAAE,KAAK,EAAE,IAAY,EAAE,KAAa,EAAE,EAAE;YACxD,MAAM,kBAAkB,CACtB,mBAAmB,EACnB,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;KACF,CAAC;AACJ,CAAC;AA/DD,kDA+DC;AAED;;;;;;;;GAQG;AACH,QAAe,CAAC,CAAC,YAAY,CAC3B,OAAwB,EACxB,MAAc,EACd,mBAA4C;IAE5C,MAAM,eAAe,GAAG,MAAM,IAAA,cAAI,EAChC,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,CACP,CAAC;IAEF,MAAM,gBAAgB,GAAG,mBAAmB,CAC1C,MAAM,EACN,mBAAmB,EACnB,eAAe,CAChB,CAAC;IAEF,OAAO,oBAAoB,CACzB,OAAO,EACP,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,OAAO,EACvB,gBAAgB,CACjB,CAAC;AACJ,CAAC;AAvBD,oCAuBC","sourcesContent":["import 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 { FooterElement } from '@metamask/snaps-sdk/jsx';\nimport { type FormElement, type JSXElement } 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 { type SagaIterator } from 'redux-saga';\nimport { call, put, select, take } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getFileSize, getFileToUpload } from './files';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\nimport type { FileOptions, SnapInterface, SnapInterfaceActions } from './types';\n\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 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'],\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 ok: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Confirmation]:\n return {\n ...interfaceActions,\n type: DialogType.Confirmation,\n content,\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\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\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\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 };\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: '',\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 * 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 result.element.type === 'Input',\n `Expected an element of type \"Input\", but found \"${result.element.type}\".`,\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: '',\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 * 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: '',\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: '',\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: '',\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 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: '',\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}\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.content,\n interfaceActions,\n );\n}\n"]}
|
package/dist/interface.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.cts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AAEvE,OAAO,KAAK,EAGV,cAAc,EACd,MAAM,EAEN,IAAI,EACL,4BAA4B;AAC7B,OAAO,EAAE,UAAU,EAA8B,4BAA4B;AAE7E,OAAO,EAAoB,KAAK,UAAU,EAAE,gCAAgC;AAS5E,OAAO,EAAE,KAAK,YAAY,EAAE,mBAAmB;AAG/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,0BAAsB;AAE7D,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,0BAAgB;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,oBAAoB,EAAE,oBAAgB;AAOhF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,mBAAmB,CAAC,UAAU,GAAG,SAAS,CAAC,EACjD,OAAO,EAAE,UAAU,EACnB,gBAAgB,EAAE,oBAAoB,GACrC,aAAa,CAgEf;AAED;;;;;GAKG;AACH,wBAAiB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAE7D;AA+DD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG;IA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B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,iBAwDd;AAED;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,mBAAmB,EAAE,uBAAuB,EAC5C,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,iBAwDd;AAcD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,UAAU,CAC9B,mBAAmB,EAAE,uBAAuB,EAC5C,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,OAAO,CAAC,EAAE,WAAW,iBAyDtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,EAC5C,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG;IAAE,OAAO,EAAE,UAAU,CAAA;CAAE,GACjE,oBAAoB,CA2DtB;AAED;;;;;;;;GAQG;AACH,wBAAiB,YAAY,CAC3B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,GAC3C,YAAY,CAmBd"}
|
package/dist/interface.mjs
CHANGED
|
@@ -156,6 +156,19 @@ function getFormElement(form, name) {
|
|
|
156
156
|
}
|
|
157
157
|
return { element, form: form.props.name };
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Get an object containing the element, and optional form that's associated
|
|
161
|
+
* with the element if any.
|
|
162
|
+
*
|
|
163
|
+
* @param element - The JSX element.
|
|
164
|
+
* @returns An object containing the element and optional form.
|
|
165
|
+
*/
|
|
166
|
+
function getElementWithOptionalForm(element) {
|
|
167
|
+
if (element.type !== 'Button' || !element.props.form) {
|
|
168
|
+
return { element };
|
|
169
|
+
}
|
|
170
|
+
return { element, form: element.props.form };
|
|
171
|
+
}
|
|
159
172
|
/**
|
|
160
173
|
* Get an element from a JSX tree with the given name.
|
|
161
174
|
*
|
|
@@ -166,14 +179,14 @@ function getFormElement(form, name) {
|
|
|
166
179
|
*/
|
|
167
180
|
export function getElement(content, name) {
|
|
168
181
|
if (isJSXElementWithName(content, name)) {
|
|
169
|
-
return
|
|
182
|
+
return getElementWithOptionalForm(content);
|
|
170
183
|
}
|
|
171
184
|
return walkJsx(content, (element) => {
|
|
172
185
|
if (element.type === 'Form') {
|
|
173
186
|
return getFormElement(element, name);
|
|
174
187
|
}
|
|
175
188
|
if (isJSXElementWithName(element, name)) {
|
|
176
|
-
return
|
|
189
|
+
return getElementWithOptionalForm(element);
|
|
177
190
|
}
|
|
178
191
|
return undefined;
|
|
179
192
|
});
|