@metamask/snaps-jest 8.1.3 → 8.3.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 +19 -1
- package/README.md +2 -2
- package/dist/chunk-24CGIQLL.mjs +30 -0
- package/dist/chunk-24CGIQLL.mjs.map +1 -0
- package/dist/{chunk-T2PHS5FY.js → chunk-2RJYSYUB.js} +2 -2
- package/dist/chunk-2RJYSYUB.js.map +1 -0
- package/dist/{chunk-KNJNL723.mjs → chunk-3J2IBWXV.mjs} +2 -2
- package/dist/{chunk-EDFQDZNY.js → chunk-3NP6BDGK.js} +50 -17
- package/dist/chunk-3NP6BDGK.js.map +1 -0
- package/dist/{chunk-AFA4KKWW.mjs → chunk-6JPBXAHM.mjs} +250 -47
- package/dist/chunk-6JPBXAHM.mjs.map +1 -0
- package/dist/{chunk-VXPCUDBI.js → chunk-6V6MFT67.js} +8 -6
- package/dist/chunk-6V6MFT67.js.map +1 -0
- package/dist/{chunk-6V5GEUDO.mjs → chunk-7PCHIR6O.mjs} +7 -37
- package/dist/chunk-7PCHIR6O.mjs.map +1 -0
- package/dist/{chunk-2OHD2VKS.js → chunk-AMAL4SJH.js} +11 -37
- package/dist/chunk-AMAL4SJH.js.map +1 -0
- package/dist/{chunk-HOI6FPLR.mjs → chunk-C26TYXXD.mjs} +9 -9
- package/dist/chunk-C26TYXXD.mjs.map +1 -0
- package/dist/{chunk-K55LIE3W.mjs → chunk-CACRY3TX.mjs} +3 -3
- package/dist/{chunk-PZDTZGSI.js → chunk-D653LBAY.js} +1 -1
- package/dist/chunk-D653LBAY.js.map +1 -0
- package/dist/chunk-DUVKGPX5.js +509 -0
- package/dist/chunk-DUVKGPX5.js.map +1 -0
- package/dist/{chunk-IH7UNS5A.mjs → chunk-G333FBBL.mjs} +6 -4
- package/dist/chunk-G333FBBL.mjs.map +1 -0
- package/dist/{chunk-YNUVT3HC.js → chunk-GLPGOEVE.js} +4 -4
- package/dist/chunk-GLPGOEVE.js.map +1 -0
- package/dist/chunk-IWJ4HKDR.mjs +50 -0
- package/dist/chunk-IWJ4HKDR.mjs.map +1 -0
- package/dist/{chunk-WMLSD6B5.js → chunk-K7MK6LQU.js} +3 -3
- package/dist/{chunk-B73P64TE.mjs → chunk-KOPPL55J.mjs} +2 -2
- package/dist/chunk-KOPPL55J.mjs.map +1 -0
- package/dist/{chunk-XKJHFUHE.js → chunk-KPRLFCKD.js} +4 -2
- package/dist/chunk-KPRLFCKD.js.map +1 -0
- package/dist/{chunk-3FDEYMQU.js → chunk-LPMHPAZK.js} +54 -14
- package/dist/chunk-LPMHPAZK.js.map +1 -0
- package/dist/{chunk-GG2BCPQH.mjs → chunk-LSKT2AUS.mjs} +5 -3
- package/dist/chunk-LSKT2AUS.mjs.map +1 -0
- package/dist/{chunk-6KXCBUNZ.mjs → chunk-LVNNGMJ2.mjs} +3 -1
- package/dist/{chunk-6KXCBUNZ.mjs.map → chunk-LVNNGMJ2.mjs.map} +1 -1
- package/dist/{chunk-TMAWGVZP.mjs → chunk-OHRFO2BL.mjs} +7 -7
- package/dist/chunk-OHRFO2BL.mjs.map +1 -0
- package/dist/{chunk-JXAJWUVZ.js → chunk-OO6IVUCV.js} +5 -5
- package/dist/{chunk-3M4GRUMH.mjs → chunk-ORR7AE5X.mjs} +2 -2
- package/dist/{chunk-UPR3PTSA.mjs → chunk-PDOVVC74.mjs} +10 -36
- package/dist/chunk-PDOVVC74.mjs.map +1 -0
- package/dist/{chunk-E2BYTLOT.mjs → chunk-Q3I6P2ZF.mjs} +43 -10
- package/dist/chunk-Q3I6P2ZF.mjs.map +1 -0
- package/dist/chunk-QRVFWATH.mjs +14 -0
- package/dist/chunk-QRVFWATH.mjs.map +1 -0
- package/dist/{chunk-MBQHVBLA.js → chunk-QYHQ2WWX.js} +5 -5
- package/dist/chunk-QYHQ2WWX.js.map +1 -0
- package/dist/{chunk-XWGECIXI.js → chunk-RJNNNCZJ.js} +3 -3
- package/dist/{chunk-U3DVRTS2.mjs → chunk-ROCGQYSK.mjs} +46 -6
- package/dist/chunk-ROCGQYSK.mjs.map +1 -0
- package/dist/chunk-SNXRXX2O.js +30 -0
- package/dist/chunk-SNXRXX2O.js.map +1 -0
- package/dist/chunk-SW65QYFV.js +50 -0
- package/dist/chunk-SW65QYFV.js.map +1 -0
- package/dist/{chunk-44ARQBXS.js → chunk-WZ57PU2K.js} +6 -4
- package/dist/chunk-WZ57PU2K.js.map +1 -0
- package/dist/chunk-XP4YGQJA.js +14 -0
- package/dist/chunk-XP4YGQJA.js.map +1 -0
- package/dist/{chunk-KQBJQLZG.js → chunk-Y2U3ZPCK.js} +15 -45
- package/dist/chunk-Y2U3ZPCK.js.map +1 -0
- package/dist/{chunk-74TIKA2T.mjs → chunk-ZJQSGRNK.mjs} +1 -1
- package/dist/chunk-ZJQSGRNK.mjs.map +1 -0
- package/dist/environment.js +17 -17
- package/dist/environment.mjs +16 -16
- package/dist/helpers.js +30 -16
- package/dist/helpers.mjs +29 -15
- package/dist/index.js +32 -18
- package/dist/index.mjs +31 -17
- package/dist/internals/index.js +33 -21
- package/dist/internals/index.mjs +35 -23
- package/dist/internals/request.js +15 -15
- package/dist/internals/request.mjs +14 -14
- package/dist/internals/simulation/constants.js +4 -2
- package/dist/internals/simulation/constants.mjs +3 -1
- package/dist/internals/simulation/controllers.js +7 -7
- package/dist/internals/simulation/controllers.mjs +6 -6
- package/dist/internals/simulation/files.js +8 -2
- package/dist/internals/simulation/files.mjs +7 -1
- package/dist/internals/simulation/index.js +31 -19
- package/dist/internals/simulation/index.mjs +33 -21
- package/dist/internals/simulation/interface.js +15 -4
- package/dist/internals/simulation/interface.mjs +16 -5
- package/dist/internals/simulation/methods/hooks/get-preferences.js +8 -0
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs +8 -0
- package/dist/internals/simulation/methods/hooks/index.js +5 -5
- package/dist/internals/simulation/methods/hooks/index.mjs +8 -8
- package/dist/internals/simulation/methods/hooks/notifications.js +2 -2
- package/dist/internals/simulation/methods/hooks/notifications.mjs +2 -2
- package/dist/internals/simulation/methods/hooks/request-user-approval.js +14 -0
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +14 -0
- package/dist/internals/simulation/methods/hooks/state.js +2 -2
- package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
- package/dist/internals/simulation/methods/index.js +6 -6
- package/dist/internals/simulation/methods/index.mjs +5 -5
- package/dist/internals/simulation/methods/specifications.js +6 -6
- package/dist/internals/simulation/methods/specifications.mjs +5 -5
- package/dist/internals/simulation/middleware/engine.js +3 -3
- package/dist/internals/simulation/middleware/engine.mjs +2 -2
- package/dist/internals/simulation/middleware/index.js +3 -3
- package/dist/internals/simulation/middleware/index.mjs +2 -2
- package/dist/internals/simulation/options.js +3 -3
- package/dist/internals/simulation/options.mjs +2 -2
- package/dist/internals/simulation/simulation.js +13 -12
- package/dist/internals/simulation/simulation.mjs +12 -11
- package/dist/internals/simulation/store/index.js +3 -3
- package/dist/internals/simulation/store/index.mjs +2 -2
- package/dist/internals/simulation/store/store.js +3 -3
- package/dist/internals/simulation/store/store.mjs +2 -2
- package/dist/internals/simulation/store/ui.js +2 -2
- package/dist/internals/simulation/store/ui.mjs +1 -1
- package/dist/internals/structs.js +2 -2
- package/dist/internals/structs.mjs +1 -1
- package/dist/matchers.js +16 -18
- package/dist/matchers.mjs +15 -17
- package/dist/options.js +2 -2
- package/dist/options.mjs +1 -1
- package/dist/setup.js +15 -15
- package/dist/setup.mjs +15 -15
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/helpers.d.ts +43 -1
- package/dist/types/internals/request.d.ts +3 -2
- package/dist/types/internals/server.d.ts +1 -1
- package/dist/types/internals/simulation/constants.d.ts +4 -0
- package/dist/types/internals/simulation/controllers.d.ts +4 -4
- package/dist/types/internals/simulation/files.d.ts +36 -0
- package/dist/types/internals/simulation/interface.d.ts +70 -8
- package/dist/types/internals/simulation/methods/hooks/get-preferences.d.ts +13 -0
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +2 -2
- package/dist/types/internals/simulation/methods/hooks/request-user-approval.d.ts +15 -0
- package/dist/types/internals/simulation/methods/specifications.d.ts +2 -2
- package/dist/types/internals/simulation/middleware/engine.d.ts +1 -1
- package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +1 -1
- package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +1 -1
- package/dist/types/internals/simulation/options.d.ts +10 -8
- package/dist/types/internals/simulation/simulation.d.ts +8 -5
- package/dist/types/internals/simulation/store/mocks.d.ts +2 -2
- package/dist/types/internals/simulation/store/notifications.d.ts +2 -2
- package/dist/types/internals/simulation/store/state.d.ts +1 -1
- package/dist/types/internals/simulation/store/store.d.ts +4 -4
- package/dist/types/internals/simulation/store/ui.d.ts +4 -3
- package/dist/types/internals/structs.d.ts +41 -41
- package/dist/types/matchers.d.ts +0 -10
- package/dist/types/options.d.ts +7 -7
- package/dist/types/types.d.ts +91 -20
- package/package.json +18 -16
- package/dist/chunk-265BMFM5.js +0 -13
- package/dist/chunk-265BMFM5.js.map +0 -1
- package/dist/chunk-2OHD2VKS.js.map +0 -1
- package/dist/chunk-3FDEYMQU.js.map +0 -1
- package/dist/chunk-44ARQBXS.js.map +0 -1
- package/dist/chunk-6V5GEUDO.mjs.map +0 -1
- package/dist/chunk-74TIKA2T.mjs.map +0 -1
- package/dist/chunk-AFA4KKWW.mjs.map +0 -1
- package/dist/chunk-B73P64TE.mjs.map +0 -1
- package/dist/chunk-E2BYTLOT.mjs.map +0 -1
- package/dist/chunk-EDFQDZNY.js.map +0 -1
- package/dist/chunk-GG2BCPQH.mjs.map +0 -1
- package/dist/chunk-HOI6FPLR.mjs.map +0 -1
- package/dist/chunk-IH7UNS5A.mjs.map +0 -1
- package/dist/chunk-KQBJQLZG.js.map +0 -1
- package/dist/chunk-KSIBNOB2.mjs +0 -13
- package/dist/chunk-KSIBNOB2.mjs.map +0 -1
- package/dist/chunk-MBQHVBLA.js.map +0 -1
- package/dist/chunk-ORO3T6BU.mjs +0 -24
- package/dist/chunk-ORO3T6BU.mjs.map +0 -1
- package/dist/chunk-PZDTZGSI.js.map +0 -1
- package/dist/chunk-R55KAAM4.js +0 -306
- package/dist/chunk-R55KAAM4.js.map +0 -1
- package/dist/chunk-RAMAN5RM.js +0 -24
- package/dist/chunk-RAMAN5RM.js.map +0 -1
- package/dist/chunk-T2PHS5FY.js.map +0 -1
- package/dist/chunk-TBDYQSRT.mjs +0 -16
- package/dist/chunk-TBDYQSRT.mjs.map +0 -1
- package/dist/chunk-TMAWGVZP.mjs.map +0 -1
- package/dist/chunk-TVD4SWH7.js +0 -16
- package/dist/chunk-TVD4SWH7.js.map +0 -1
- package/dist/chunk-U3DVRTS2.mjs.map +0 -1
- package/dist/chunk-UPR3PTSA.mjs.map +0 -1
- package/dist/chunk-VXPCUDBI.js.map +0 -1
- package/dist/chunk-XKJHFUHE.js.map +0 -1
- package/dist/chunk-YNUVT3HC.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-locale.js +0 -8
- package/dist/internals/simulation/methods/hooks/get-locale.mjs +0 -8
- package/dist/internals/simulation/methods/hooks/show-dialog.js +0 -14
- package/dist/internals/simulation/methods/hooks/show-dialog.mjs +0 -14
- package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +0 -9
- package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +0 -9
- /package/dist/{chunk-KNJNL723.mjs.map → chunk-3J2IBWXV.mjs.map} +0 -0
- /package/dist/{chunk-K55LIE3W.mjs.map → chunk-CACRY3TX.mjs.map} +0 -0
- /package/dist/{chunk-WMLSD6B5.js.map → chunk-K7MK6LQU.js.map} +0 -0
- /package/dist/{chunk-JXAJWUVZ.js.map → chunk-OO6IVUCV.js.map} +0 -0
- /package/dist/{chunk-3M4GRUMH.mjs.map → chunk-ORR7AE5X.mjs.map} +0 -0
- /package/dist/{chunk-XWGECIXI.js.map → chunk-RJNNNCZJ.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{get-locale.js.map → get-preferences.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{get-locale.mjs.map → get-preferences.mjs.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{show-dialog.js.map → request-user-approval.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{show-dialog.mjs.map → request-user-approval.mjs.map} +0 -0
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getFileSize,
|
|
3
|
+
getFileToUpload
|
|
4
|
+
} from "./chunk-IWJ4HKDR.mjs";
|
|
1
5
|
import {
|
|
2
6
|
getCurrentInterface,
|
|
3
7
|
resolveInterface,
|
|
4
8
|
setInterface
|
|
5
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ZJQSGRNK.mjs";
|
|
6
10
|
|
|
7
11
|
// src/internals/simulation/interface.ts
|
|
12
|
+
import { DIALOG_APPROVAL_TYPES } from "@metamask/snaps-rpc-methods";
|
|
8
13
|
import { DialogType, UserInputEventType, assert } from "@metamask/snaps-sdk";
|
|
9
14
|
import {
|
|
10
15
|
HandlerType,
|
|
@@ -12,49 +17,69 @@ import {
|
|
|
12
17
|
unwrapError,
|
|
13
18
|
walkJsx
|
|
14
19
|
} from "@metamask/snaps-utils";
|
|
15
|
-
import { hasProperty } from "@metamask/utils";
|
|
20
|
+
import { assertExhaustive, hasProperty } from "@metamask/utils";
|
|
16
21
|
import { call, put, select, take } from "redux-saga/effects";
|
|
22
|
+
var MAX_FILE_SIZE = 1e7;
|
|
17
23
|
function getInterfaceResponse(runSaga, type, content, interfaceActions) {
|
|
18
24
|
switch (type) {
|
|
19
|
-
case DialogType.Alert:
|
|
25
|
+
case DIALOG_APPROVAL_TYPES[DialogType.Alert]:
|
|
20
26
|
return {
|
|
21
27
|
...interfaceActions,
|
|
22
|
-
type,
|
|
28
|
+
type: DialogType.Alert,
|
|
23
29
|
content,
|
|
24
30
|
ok: resolveWith(runSaga, null)
|
|
25
31
|
};
|
|
26
|
-
case DialogType.Confirmation:
|
|
32
|
+
case DIALOG_APPROVAL_TYPES[DialogType.Confirmation]:
|
|
27
33
|
return {
|
|
28
34
|
...interfaceActions,
|
|
29
|
-
type,
|
|
35
|
+
type: DialogType.Confirmation,
|
|
30
36
|
content,
|
|
31
37
|
ok: resolveWith(runSaga, true),
|
|
32
38
|
cancel: resolveWith(runSaga, false)
|
|
33
39
|
};
|
|
34
|
-
case DialogType.Prompt:
|
|
40
|
+
case DIALOG_APPROVAL_TYPES[DialogType.Prompt]:
|
|
35
41
|
return {
|
|
36
42
|
...interfaceActions,
|
|
37
|
-
type,
|
|
43
|
+
type: DialogType.Prompt,
|
|
38
44
|
content,
|
|
39
45
|
ok: resolveWithInput(runSaga),
|
|
40
46
|
cancel: resolveWith(runSaga, null)
|
|
41
47
|
};
|
|
48
|
+
case DIALOG_APPROVAL_TYPES.default: {
|
|
49
|
+
const footer = getElementByType(content, "Footer");
|
|
50
|
+
if (!footer) {
|
|
51
|
+
return {
|
|
52
|
+
...interfaceActions,
|
|
53
|
+
content,
|
|
54
|
+
ok: resolveWith(runSaga, null),
|
|
55
|
+
cancel: resolveWith(runSaga, null)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (getJsxChildren(footer).length === 1) {
|
|
59
|
+
return {
|
|
60
|
+
...interfaceActions,
|
|
61
|
+
content,
|
|
62
|
+
cancel: resolveWith(runSaga, null)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...interfaceActions,
|
|
67
|
+
content
|
|
68
|
+
};
|
|
69
|
+
}
|
|
42
70
|
default:
|
|
43
71
|
throw new Error(`Unknown or unsupported dialog type: "${String(type)}".`);
|
|
44
72
|
}
|
|
45
73
|
}
|
|
74
|
+
function* resolveWithSaga(value) {
|
|
75
|
+
yield put(resolveInterface(value));
|
|
76
|
+
}
|
|
46
77
|
function resolveWith(runSaga, value) {
|
|
47
|
-
function* resolveWithSaga() {
|
|
48
|
-
yield put(resolveInterface(value));
|
|
49
|
-
}
|
|
50
78
|
return async () => {
|
|
51
|
-
await runSaga(resolveWithSaga).toPromise();
|
|
79
|
+
await runSaga(resolveWithSaga, value).toPromise();
|
|
52
80
|
};
|
|
53
81
|
}
|
|
54
82
|
function resolveWithInput(runSaga) {
|
|
55
|
-
function* resolveWithSaga(value) {
|
|
56
|
-
yield put(resolveInterface(value));
|
|
57
|
-
}
|
|
58
83
|
return async (value = "") => {
|
|
59
84
|
await runSaga(resolveWithSaga, value).toPromise();
|
|
60
85
|
};
|
|
@@ -106,6 +131,14 @@ function getElement(content, name) {
|
|
|
106
131
|
return void 0;
|
|
107
132
|
});
|
|
108
133
|
}
|
|
134
|
+
function getElementByType(content, type) {
|
|
135
|
+
return walkJsx(content, (element) => {
|
|
136
|
+
if (element.type === type) {
|
|
137
|
+
return element;
|
|
138
|
+
}
|
|
139
|
+
return void 0;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
109
142
|
async function handleEvent(controllerMessenger, snapId, id, event, context) {
|
|
110
143
|
try {
|
|
111
144
|
await controllerMessenger.call(
|
|
@@ -137,36 +170,68 @@ async function clickElement(controllerMessenger, id, content, snapId, name) {
|
|
|
137
170
|
`Could not find an element in the interface with the name "${name}".`
|
|
138
171
|
);
|
|
139
172
|
assert(
|
|
140
|
-
result.element.type === "Button",
|
|
141
|
-
`Expected an element of type "Button", but found "${result.element.type}".`
|
|
173
|
+
result.element.type === "Button" || result.element.type === "Checkbox",
|
|
174
|
+
`Expected an element of type "Button" or "Checkbox", but found "${result.element.type}".`
|
|
142
175
|
);
|
|
143
176
|
const { state, context } = controllerMessenger.call(
|
|
144
177
|
"SnapInterfaceController:getInterface",
|
|
145
178
|
snapId,
|
|
146
179
|
id
|
|
147
180
|
);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
181
|
+
const { type } = result.element;
|
|
182
|
+
const elementName = result.element.props.name;
|
|
183
|
+
const formState = result.form ? state[result.form] : state;
|
|
184
|
+
const currentValue = formState[elementName];
|
|
185
|
+
switch (type) {
|
|
186
|
+
case "Button": {
|
|
187
|
+
await handleEvent(
|
|
188
|
+
controllerMessenger,
|
|
189
|
+
snapId,
|
|
190
|
+
id,
|
|
191
|
+
{
|
|
192
|
+
type: UserInputEventType.ButtonClickEvent,
|
|
193
|
+
name: elementName
|
|
194
|
+
},
|
|
195
|
+
context
|
|
196
|
+
);
|
|
197
|
+
if (result.form && result.element.props.type === "submit") {
|
|
198
|
+
await handleEvent(
|
|
199
|
+
controllerMessenger,
|
|
200
|
+
snapId,
|
|
201
|
+
id,
|
|
202
|
+
{
|
|
203
|
+
type: UserInputEventType.FormSubmitEvent,
|
|
204
|
+
name: result.form,
|
|
205
|
+
value: state[result.form]
|
|
206
|
+
},
|
|
207
|
+
context
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case "Checkbox": {
|
|
213
|
+
const newValue = !currentValue;
|
|
214
|
+
const newState = mergeValue(state, name, newValue, result.form);
|
|
215
|
+
controllerMessenger.call(
|
|
216
|
+
"SnapInterfaceController:updateInterfaceState",
|
|
217
|
+
id,
|
|
218
|
+
newState
|
|
219
|
+
);
|
|
220
|
+
await handleEvent(
|
|
221
|
+
controllerMessenger,
|
|
222
|
+
snapId,
|
|
223
|
+
id,
|
|
224
|
+
{
|
|
225
|
+
type: UserInputEventType.InputChangeEvent,
|
|
226
|
+
name: elementName,
|
|
227
|
+
value: newValue
|
|
228
|
+
},
|
|
229
|
+
context
|
|
230
|
+
);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
default:
|
|
234
|
+
assertExhaustive(type);
|
|
170
235
|
}
|
|
171
236
|
}
|
|
172
237
|
function mergeValue(state, name, value, form) {
|
|
@@ -267,13 +332,108 @@ async function selectInDropdown(controllerMessenger, id, content, snapId, name,
|
|
|
267
332
|
}
|
|
268
333
|
});
|
|
269
334
|
}
|
|
270
|
-
function
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
335
|
+
async function selectFromRadioGroup(controllerMessenger, id, content, snapId, name, value) {
|
|
336
|
+
const result = getElement(content, name);
|
|
337
|
+
assert(
|
|
338
|
+
result !== void 0,
|
|
339
|
+
`Could not find an element in the interface with the name "${name}".`
|
|
340
|
+
);
|
|
341
|
+
assert(
|
|
342
|
+
result.element.type === "RadioGroup",
|
|
343
|
+
`Expected an element of type "RadioGroup", but found "${result.element.type}".`
|
|
344
|
+
);
|
|
345
|
+
const options = getJsxChildren(result.element);
|
|
346
|
+
const selectedOption = options.find(
|
|
347
|
+
(option) => hasProperty(option.props, "value") && option.props.value === value
|
|
348
|
+
);
|
|
349
|
+
assert(
|
|
350
|
+
selectedOption !== void 0,
|
|
351
|
+
`The RadioGroup with the name "${name}" does not contain "${value}".`
|
|
352
|
+
);
|
|
353
|
+
const { state, context } = controllerMessenger.call(
|
|
354
|
+
"SnapInterfaceController:getInterface",
|
|
355
|
+
snapId,
|
|
356
|
+
id
|
|
275
357
|
);
|
|
276
|
-
const
|
|
358
|
+
const newState = mergeValue(state, name, value, result.form);
|
|
359
|
+
controllerMessenger.call(
|
|
360
|
+
"SnapInterfaceController:updateInterfaceState",
|
|
361
|
+
id,
|
|
362
|
+
newState
|
|
363
|
+
);
|
|
364
|
+
await controllerMessenger.call("ExecutionService:handleRpcRequest", snapId, {
|
|
365
|
+
origin: "",
|
|
366
|
+
handler: HandlerType.OnUserInput,
|
|
367
|
+
request: {
|
|
368
|
+
jsonrpc: "2.0",
|
|
369
|
+
method: " ",
|
|
370
|
+
params: {
|
|
371
|
+
event: {
|
|
372
|
+
type: UserInputEventType.InputChangeEvent,
|
|
373
|
+
name: result.element.props.name,
|
|
374
|
+
value
|
|
375
|
+
},
|
|
376
|
+
id,
|
|
377
|
+
context
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
function getFormattedFileSize(size) {
|
|
383
|
+
return `${(size / 1e6).toFixed(2)} MB`;
|
|
384
|
+
}
|
|
385
|
+
async function uploadFile(controllerMessenger, id, content, snapId, name, file, options) {
|
|
386
|
+
const result = getElement(content, name);
|
|
387
|
+
assert(
|
|
388
|
+
result !== void 0,
|
|
389
|
+
`Could not find an element in the interface with the name "${name}".`
|
|
390
|
+
);
|
|
391
|
+
assert(
|
|
392
|
+
result.element.type === "FileInput",
|
|
393
|
+
`Expected an element of type "FileInput", but found "${result.element.type}".`
|
|
394
|
+
);
|
|
395
|
+
const { state, context } = controllerMessenger.call(
|
|
396
|
+
"SnapInterfaceController:getInterface",
|
|
397
|
+
snapId,
|
|
398
|
+
id
|
|
399
|
+
);
|
|
400
|
+
const fileSize = await getFileSize(file);
|
|
401
|
+
if (fileSize > MAX_FILE_SIZE) {
|
|
402
|
+
throw new Error(
|
|
403
|
+
`The file size (${getFormattedFileSize(
|
|
404
|
+
fileSize
|
|
405
|
+
)}) exceeds the maximum allowed size of ${getFormattedFileSize(
|
|
406
|
+
MAX_FILE_SIZE
|
|
407
|
+
)}.`
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
const fileObject = await getFileToUpload(file, options);
|
|
411
|
+
const newState = mergeValue(state, name, fileObject, result.form);
|
|
412
|
+
controllerMessenger.call(
|
|
413
|
+
"SnapInterfaceController:updateInterfaceState",
|
|
414
|
+
id,
|
|
415
|
+
newState
|
|
416
|
+
);
|
|
417
|
+
await controllerMessenger.call("ExecutionService:handleRpcRequest", snapId, {
|
|
418
|
+
origin: "",
|
|
419
|
+
handler: HandlerType.OnUserInput,
|
|
420
|
+
request: {
|
|
421
|
+
jsonrpc: "2.0",
|
|
422
|
+
method: " ",
|
|
423
|
+
params: {
|
|
424
|
+
event: {
|
|
425
|
+
type: UserInputEventType.FileUploadEvent,
|
|
426
|
+
name: result.element.props.name,
|
|
427
|
+
file: fileObject
|
|
428
|
+
},
|
|
429
|
+
id,
|
|
430
|
+
context
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
function getInterfaceActions(snapId, controllerMessenger, { content, id }) {
|
|
436
|
+
return {
|
|
277
437
|
clickElement: async (name) => {
|
|
278
438
|
await clickElement(controllerMessenger, id, content, snapId, name);
|
|
279
439
|
},
|
|
@@ -289,18 +449,61 @@ function* getInterface(runSaga, snapId, controllerMessenger) {
|
|
|
289
449
|
name,
|
|
290
450
|
value
|
|
291
451
|
);
|
|
452
|
+
},
|
|
453
|
+
selectFromRadioGroup: async (name, value) => {
|
|
454
|
+
await selectFromRadioGroup(
|
|
455
|
+
controllerMessenger,
|
|
456
|
+
id,
|
|
457
|
+
content,
|
|
458
|
+
snapId,
|
|
459
|
+
name,
|
|
460
|
+
value
|
|
461
|
+
);
|
|
462
|
+
},
|
|
463
|
+
uploadFile: async (name, file, options) => {
|
|
464
|
+
await uploadFile(
|
|
465
|
+
controllerMessenger,
|
|
466
|
+
id,
|
|
467
|
+
content,
|
|
468
|
+
snapId,
|
|
469
|
+
name,
|
|
470
|
+
file,
|
|
471
|
+
options
|
|
472
|
+
);
|
|
292
473
|
}
|
|
293
474
|
};
|
|
294
|
-
|
|
475
|
+
}
|
|
476
|
+
function* getInterface(runSaga, snapId, controllerMessenger) {
|
|
477
|
+
const storedInterface = yield call(
|
|
478
|
+
getStoredInterface,
|
|
479
|
+
controllerMessenger,
|
|
480
|
+
snapId
|
|
481
|
+
);
|
|
482
|
+
const interfaceActions = getInterfaceActions(
|
|
483
|
+
snapId,
|
|
484
|
+
controllerMessenger,
|
|
485
|
+
storedInterface
|
|
486
|
+
);
|
|
487
|
+
return getInterfaceResponse(
|
|
488
|
+
runSaga,
|
|
489
|
+
storedInterface.type,
|
|
490
|
+
storedInterface.content,
|
|
491
|
+
interfaceActions
|
|
492
|
+
);
|
|
295
493
|
}
|
|
296
494
|
|
|
297
495
|
export {
|
|
298
496
|
getInterfaceResponse,
|
|
497
|
+
resolveWithSaga,
|
|
299
498
|
getElement,
|
|
499
|
+
getElementByType,
|
|
300
500
|
clickElement,
|
|
301
501
|
mergeValue,
|
|
302
502
|
typeInField,
|
|
303
503
|
selectInDropdown,
|
|
504
|
+
selectFromRadioGroup,
|
|
505
|
+
uploadFile,
|
|
506
|
+
getInterfaceActions,
|
|
304
507
|
getInterface
|
|
305
508
|
};
|
|
306
|
-
//# sourceMappingURL=chunk-
|
|
509
|
+
//# sourceMappingURL=chunk-6JPBXAHM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/interface.ts"],"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 {\n FileOptions,\n SnapInterface,\n SnapInterfaceActions,\n} from '../../types';\nimport type { RootControllerMessenger } from './controllers';\nimport { getFileSize, getFileToUpload } from './files';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\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 * 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 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"],"mappings":";;;;;;;;;;;AACA,SAAS,6BAA6B;AAStC,SAAS,YAAY,oBAAoB,cAAc;AAGvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,mBAAmB;AAG9C,SAAS,MAAM,KAAK,QAAQ,YAAY;AAexC,IAAM,gBAAgB;AAWf,SAAS,qBACd,SACA,MACA,SACA,kBACe;AACf,UAAQ,MAAM;AAAA,IACZ,KAAK,sBAAsB,WAAW,KAAK;AACzC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM,WAAW;AAAA,QACjB;AAAA,QACA,IAAI,YAAY,SAAS,IAAI;AAAA,MAC/B;AAAA,IAEF,KAAK,sBAAsB,WAAW,YAAY;AAChD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM,WAAW;AAAA,QACjB;AAAA,QAEA,IAAI,YAAY,SAAS,IAAI;AAAA,QAC7B,QAAQ,YAAY,SAAS,KAAK;AAAA,MACpC;AAAA,IAEF,KAAK,sBAAsB,WAAW,MAAM;AAC1C,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM,WAAW;AAAA,QACjB;AAAA,QAEA,IAAI,iBAAiB,OAAO;AAAA,QAC5B,QAAQ,YAAY,SAAS,IAAI;AAAA,MACnC;AAAA,IAEF,KAAK,sBAAsB,SAAS;AAClC,YAAM,SAAS,iBAAgC,SAAS,QAAQ;AAGhE,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,UACL,GAAG;AAAA,UACH;AAAA,UAEA,IAAI,YAAY,SAAS,IAAI;AAAA,UAC7B,QAAQ,YAAY,SAAS,IAAI;AAAA,QACnC;AAAA,MACF;AAGA,UAAI,eAAe,MAAM,EAAE,WAAW,GAAG;AACvC,eAAO;AAAA,UACL,GAAG;AAAA,UACH;AAAA,UAEA,QAAQ,YAAY,SAA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ports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
var _chunkKPRLFCKDjs = require('./chunk-KPRLFCKD.js');
|
|
5
6
|
|
|
6
7
|
// src/internals/simulation/options.ts
|
|
7
|
-
var _utils = require('@metamask/utils');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -13,10 +13,12 @@ var _utils = require('@metamask/utils');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var _superstruct = require('superstruct');
|
|
16
|
+
var _superstruct = require('@metamask/superstruct');
|
|
17
|
+
var _utils = require('@metamask/utils');
|
|
17
18
|
var SimulationOptionsStruct = _superstruct.object.call(void 0, {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
currency: _superstruct.defaulted.call(void 0, _superstruct.optional.call(void 0, _superstruct.string.call(void 0, )), _chunkKPRLFCKDjs.DEFAULT_CURRENCY),
|
|
20
|
+
secretRecoveryPhrase: _superstruct.defaulted.call(void 0, _superstruct.optional.call(void 0, _superstruct.string.call(void 0, )), _chunkKPRLFCKDjs.DEFAULT_SRP),
|
|
21
|
+
locale: _superstruct.defaulted.call(void 0, _superstruct.optional.call(void 0, _superstruct.string.call(void 0, )), _chunkKPRLFCKDjs.DEFAULT_LOCALE),
|
|
20
22
|
state: _superstruct.defaulted.call(void 0, _superstruct.optional.call(void 0, _superstruct.nullable.call(void 0, _superstruct.record.call(void 0, _superstruct.string.call(void 0, ), _utils.JsonStruct))), null),
|
|
21
23
|
unencryptedState: _superstruct.defaulted.call(void 0,
|
|
22
24
|
_superstruct.optional.call(void 0, _superstruct.nullable.call(void 0, _superstruct.record.call(void 0, _superstruct.string.call(void 0, ), _utils.JsonStruct))),
|
|
@@ -33,4 +35,4 @@ function getOptions(options) {
|
|
|
33
35
|
|
|
34
36
|
|
|
35
37
|
exports.getOptions = getOptions;
|
|
36
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-6V6MFT67.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/options.ts"],"names":[],"mappings":";;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAI3B,IAAM,0BAA0B,OAAO;AAAA,EACrC,UAAU,UAAU,SAAS,OAAO,CAAC,GAAG,gBAAgB;AAAA,EACxD,sBAAsB,UAAU,SAAS,OAAO,CAAC,GAAG,WAAW;AAAA,EAC/D,QAAQ,UAAU,SAAS,OAAO,CAAC,GAAG,cAAc;AAAA,EACpD,OAAO,UAAU,SAAS,SAAS,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI;AAAA,EACvE,kBAAkB;AAAA,IAChB,SAAS,SAAS,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC;AAAA,IAC/C;AAAA,EACF;AACF,CAAC;AA2BM,SAAS,WAAW,SAAmD;AAC5E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { DEFAULT_CURRENCY, DEFAULT_LOCALE, DEFAULT_SRP } from './constants';\n\nconst SimulationOptionsStruct = object({\n currency: defaulted(optional(string()), DEFAULT_CURRENCY),\n secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),\n locale: defaulted(optional(string()), DEFAULT_LOCALE),\n state: defaulted(optional(nullable(record(string(), JsonStruct))), null),\n unencryptedState: defaulted(\n optional(nullable(record(string(), JsonStruct))),\n null,\n ),\n});\n\n/**\n * Options for the simulation.\n *\n * @property secretRecoveryPhrase - The secret recovery phrase to use. This is\n * used to derive addresses and private keys. Defaults to a test recovery\n * phrase.\n * @property locale - The locale to use. Defaults to `en`.\n * @property state - The initial state of the Snap, if any. Defaults to `null`.\n */\nexport type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;\n\n/**\n * Options for the simulation, with defaults filled in.\n *\n * See {@link SimulationUserOptions} for documentation.\n */\nexport type SimulationOptions = Required<SimulationUserOptions>;\n\n/**\n * Get the options for the simulation.\n *\n * @param options - The user options. Any options not specified will be filled\n * in with default values.\n * @returns The simulation options.\n */\nexport function getOptions(options: SimulationUserOptions): SimulationOptions {\n return create(\n options,\n SimulationOptionsStruct,\n ) as Required<SimulationUserOptions>;\n}\n"]}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InterfaceStruct,
|
|
3
3
|
SnapResponseStruct
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-C26TYXXD.mjs";
|
|
5
5
|
|
|
6
6
|
// src/matchers.ts
|
|
7
7
|
import { expect } from "@jest/globals";
|
|
8
8
|
import { isJSXElementUnsafe } from "@metamask/snaps-sdk/jsx";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getJsxElementFromComponent,
|
|
11
|
+
serialiseJsx
|
|
12
|
+
} from "@metamask/snaps-utils";
|
|
13
|
+
import { is } from "@metamask/superstruct";
|
|
10
14
|
import { hasProperty } from "@metamask/utils";
|
|
11
15
|
import {
|
|
12
16
|
EXPECTED_COLOR,
|
|
@@ -17,7 +21,6 @@ import {
|
|
|
17
21
|
printWithType,
|
|
18
22
|
RECEIVED_COLOR
|
|
19
23
|
} from "jest-matcher-utils";
|
|
20
|
-
import { is } from "superstruct";
|
|
21
24
|
function assertActualIsSnapResponse(actual, matcherName, options) {
|
|
22
25
|
if (!is(actual, SnapResponseStruct)) {
|
|
23
26
|
throw new Error(
|
|
@@ -99,38 +102,6 @@ Expected type: ${this.utils.printExpected(type)}
|
|
|
99
102
|
Received: ${this.utils.printReceived(notifications)}`;
|
|
100
103
|
return { message, pass };
|
|
101
104
|
};
|
|
102
|
-
function serialiseProp(prop) {
|
|
103
|
-
if (typeof prop === "string") {
|
|
104
|
-
return `"${prop}"`;
|
|
105
|
-
}
|
|
106
|
-
return `{${JSON.stringify(prop)}}`;
|
|
107
|
-
}
|
|
108
|
-
function serialiseProps(props) {
|
|
109
|
-
return Object.entries(props).filter(([key]) => key !== "children").sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => ` ${key}=${serialiseProp(value)}`).join("");
|
|
110
|
-
}
|
|
111
|
-
function serialiseJsx(node, indentation = 0) {
|
|
112
|
-
if (Array.isArray(node)) {
|
|
113
|
-
return node.map((child) => serialiseJsx(child, indentation)).join("");
|
|
114
|
-
}
|
|
115
|
-
const indent = " ".repeat(indentation);
|
|
116
|
-
if (typeof node === "string") {
|
|
117
|
-
return `${indent}${node}
|
|
118
|
-
`;
|
|
119
|
-
}
|
|
120
|
-
if (!node) {
|
|
121
|
-
return "";
|
|
122
|
-
}
|
|
123
|
-
const { type, props } = node;
|
|
124
|
-
const trailingNewline = indentation > 0 ? "\n" : "";
|
|
125
|
-
if (hasProperty(props, "children")) {
|
|
126
|
-
const children = serialiseJsx(props.children, indentation + 1);
|
|
127
|
-
return `${indent}<${type}${serialiseProps(
|
|
128
|
-
props
|
|
129
|
-
)}>
|
|
130
|
-
${children}${indent}</${type}>${trailingNewline}`;
|
|
131
|
-
}
|
|
132
|
-
return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;
|
|
133
|
-
}
|
|
134
105
|
var toRenderLegacy = function(actual, expected) {
|
|
135
106
|
assertHasInterface(actual, "toRender");
|
|
136
107
|
const { content } = actual;
|
|
@@ -205,7 +176,6 @@ export {
|
|
|
205
176
|
toRespondWith,
|
|
206
177
|
toRespondWithError,
|
|
207
178
|
toSendNotification,
|
|
208
|
-
serialiseJsx,
|
|
209
179
|
toRender
|
|
210
180
|
};
|
|
211
|
-
//# sourceMappingURL=chunk-
|
|
181
|
+
//# sourceMappingURL=chunk-7PCHIR6O.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"mappings":";;;;;;AAMA,SAAS,cAAc;AAQvB,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU;AAEnB,SAAS,mBAAmB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAYP,SAAS,2BACP,QACA,aACA,SACgC;AAChC,MAAI,CAAC,GAAG,QAAQ,kBAAkB,GAAG;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,QACE,YAAY,aAAa,QAAW,QAAW,OAAO;AAAA,QACtD,GAAG;AAAA,UACD;AAAA,QACF,CAAC;AAAA,QACD,cAAc,YAAY,QAAQ,aAAa;AAAA,MACjD;A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