zh-web-sdk 2.11.0 → 2.11.2
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/dist/index.js +43 -43
- package/dist/index.js.map +3 -3
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +50 -35
- package/src/types.ts +4 -1
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
import { useWindowSize } from "../hooks/use-window-size";
|
|
23
23
|
import { isInsideWorldApp } from "../utils/world-app-utils";
|
|
24
24
|
import {
|
|
25
|
-
MiniKit,
|
|
26
25
|
PayCommandInput,
|
|
27
26
|
Tokens,
|
|
28
27
|
tokenToDecimals,
|
|
@@ -186,11 +185,11 @@ const AppContainer = ({
|
|
|
186
185
|
iRef.current?.contentWindow?.postMessage(
|
|
187
186
|
{
|
|
188
187
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
189
|
-
key as AppIdentifier
|
|
188
|
+
key as AppIdentifier,
|
|
190
189
|
)}SEND_JWT_TOKEN`,
|
|
191
190
|
jwt: allAppsState[key as AppIdentifier].jwt,
|
|
192
191
|
},
|
|
193
|
-
zeroHashAppURL
|
|
192
|
+
zeroHashAppURL,
|
|
194
193
|
);
|
|
195
194
|
|
|
196
195
|
// If the zh-web-sdk is being run inside the WorldApp, we must send the WorldApp object
|
|
@@ -198,7 +197,7 @@ const AppContainer = ({
|
|
|
198
197
|
if (isInsideWorldApp()) {
|
|
199
198
|
iRef.current?.contentWindow?.postMessage(
|
|
200
199
|
{ type: `WORLD_APP_OBJECT`, WorldApp: window.WorldApp },
|
|
201
|
-
zeroHashAppURL
|
|
200
|
+
zeroHashAppURL,
|
|
202
201
|
);
|
|
203
202
|
}
|
|
204
203
|
|
|
@@ -207,11 +206,11 @@ const AppContainer = ({
|
|
|
207
206
|
iRef.current?.contentWindow?.postMessage(
|
|
208
207
|
{
|
|
209
208
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
210
|
-
key as AppIdentifier
|
|
209
|
+
key as AppIdentifier,
|
|
211
210
|
)}SEND_FILTERS`,
|
|
212
211
|
filters: allAppsState[key as AppIdentifier].filters,
|
|
213
212
|
},
|
|
214
|
-
zeroHashAppURL
|
|
213
|
+
zeroHashAppURL,
|
|
215
214
|
);
|
|
216
215
|
}
|
|
217
216
|
// Send navigate to Onboarding App
|
|
@@ -219,11 +218,11 @@ const AppContainer = ({
|
|
|
219
218
|
iRef.current?.contentWindow?.postMessage(
|
|
220
219
|
{
|
|
221
220
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
222
|
-
AppIdentifier.ONBOARDING
|
|
221
|
+
AppIdentifier.ONBOARDING,
|
|
223
222
|
)}NAVIGATE`,
|
|
224
223
|
navigate,
|
|
225
224
|
},
|
|
226
|
-
zeroHashAppURL
|
|
225
|
+
zeroHashAppURL,
|
|
227
226
|
);
|
|
228
227
|
}
|
|
229
228
|
});
|
|
@@ -258,24 +257,33 @@ const AppContainer = ({
|
|
|
258
257
|
|
|
259
258
|
const worldAppEventHandler = useCallback(
|
|
260
259
|
async (event: MessageEvent) => {
|
|
261
|
-
// Does nothing if not running inside the World App
|
|
262
|
-
if (!isInsideWorldApp()) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
260
|
const zhAppsURL = new URL(zeroHashAppURL);
|
|
267
|
-
|
|
268
|
-
|
|
261
|
+
iRef.current?.contentWindow?.postMessage(
|
|
262
|
+
{
|
|
263
|
+
type: "MINIKIT_PAY_COMMAND_RECEIVED",
|
|
264
|
+
payload: {
|
|
265
|
+
origin: event.origin,
|
|
266
|
+
zhAppsURLOrigin: zhAppsURL.origin,
|
|
267
|
+
data: event.data,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
zeroHashAppURL,
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
if (!window.MiniKit) {
|
|
274
|
+
iRef.current?.contentWindow?.postMessage(
|
|
275
|
+
{
|
|
276
|
+
type: "MINIKIT_PAY_COMMAND_CANCELED",
|
|
277
|
+
payload: { reason: "window.Minikit not found" },
|
|
278
|
+
},
|
|
279
|
+
zeroHashAppURL,
|
|
280
|
+
);
|
|
269
281
|
return;
|
|
270
282
|
}
|
|
271
283
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
if (event.data?.type === "MINIKIT_PAY_COMMAND") {
|
|
277
|
-
const payload = event.data.payload;
|
|
278
|
-
try {
|
|
284
|
+
try {
|
|
285
|
+
if (event.data?.type === "MINIKIT_PAY_COMMAND") {
|
|
286
|
+
const payload = event.data.payload;
|
|
279
287
|
const minikitPayload: PayCommandInput = {
|
|
280
288
|
reference: payload.reference,
|
|
281
289
|
to: payload.to,
|
|
@@ -284,31 +292,38 @@ const AppContainer = ({
|
|
|
284
292
|
symbol: payload.token as Tokens,
|
|
285
293
|
token_amount: tokenToDecimals(
|
|
286
294
|
Number(payload.amount),
|
|
287
|
-
payload.token
|
|
295
|
+
payload.token,
|
|
288
296
|
).toString(),
|
|
289
297
|
},
|
|
290
298
|
],
|
|
291
299
|
description: payload.description,
|
|
292
300
|
};
|
|
301
|
+
iRef.current?.contentWindow?.postMessage(
|
|
302
|
+
{
|
|
303
|
+
type: "MINIKIT_PAY_COMMAND_SUBMITTING_PAYMENT",
|
|
304
|
+
payload: { minikitPayload },
|
|
305
|
+
},
|
|
306
|
+
zeroHashAppURL,
|
|
307
|
+
);
|
|
293
308
|
const { finalPayload } =
|
|
294
|
-
await MiniKit.commandsAsync.pay(minikitPayload);
|
|
309
|
+
await window.MiniKit.commandsAsync.pay(minikitPayload);
|
|
295
310
|
|
|
296
311
|
iRef.current?.contentWindow?.postMessage(
|
|
297
312
|
{ type: "MINIKIT_PAY_COMMAND_RESULT", payload: { finalPayload } },
|
|
298
|
-
zeroHashAppURL
|
|
299
|
-
);
|
|
300
|
-
} catch (error) {
|
|
301
|
-
iRef.current?.contentWindow?.postMessage(
|
|
302
|
-
{
|
|
303
|
-
type: "MINIKIT_PAY_COMMAND_RESULT",
|
|
304
|
-
result: { error: String(error), status: "error" },
|
|
305
|
-
},
|
|
306
|
-
zeroHashAppURL
|
|
313
|
+
zeroHashAppURL,
|
|
307
314
|
);
|
|
308
315
|
}
|
|
316
|
+
} catch (error) {
|
|
317
|
+
iRef.current?.contentWindow?.postMessage(
|
|
318
|
+
{
|
|
319
|
+
type: "MINIKIT_PAY_COMMAND_ERROR",
|
|
320
|
+
payload: { error, status: "error" },
|
|
321
|
+
},
|
|
322
|
+
zeroHashAppURL,
|
|
323
|
+
);
|
|
309
324
|
}
|
|
310
325
|
},
|
|
311
|
-
[zeroHashAppURL]
|
|
326
|
+
[zeroHashAppURL],
|
|
312
327
|
);
|
|
313
328
|
|
|
314
329
|
useEffect(() => {
|
|
@@ -357,7 +372,7 @@ const AppContainer = ({
|
|
|
357
372
|
|
|
358
373
|
const mapStateToProps = (
|
|
359
374
|
state: AppContainerMappedProps,
|
|
360
|
-
ownProps: AppContainerProps
|
|
375
|
+
ownProps: AppContainerProps,
|
|
361
376
|
) => {
|
|
362
377
|
return {
|
|
363
378
|
isAppActive: state[ownProps.appIdentifier].isAppActive,
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {MiniKit} from "@worldcoin/minikit-js";
|
|
2
|
+
|
|
1
3
|
declare global {
|
|
2
4
|
interface Window {
|
|
3
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -6,7 +8,8 @@ declare global {
|
|
|
6
8
|
* WorldApp is a global object that is set if the zh-web-sdk is running
|
|
7
9
|
* inside the World App environment.
|
|
8
10
|
*/
|
|
9
|
-
WorldApp: unknown
|
|
11
|
+
WorldApp: unknown,
|
|
12
|
+
MiniKit: typeof MiniKit,
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
|