@worldcoin/idkit 4.0.9 → 4.0.10
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.cjs +60 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +62 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IDKitErrorCodes, IDKit } from '@worldcoin/idkit-core';
|
|
1
|
+
import { IDKitErrorCodes, isInWorldApp, IDKit } from '@worldcoin/idkit-core';
|
|
2
2
|
export { IDKit, IDKitErrorCodes, deviceLegacy, documentLegacy, orbLegacy, secureDocumentLegacy, selfieCheckLegacy, signRequest } from '@worldcoin/idkit-core';
|
|
3
|
-
import { memo, useMemo, useState, useRef,
|
|
3
|
+
import { memo, useMemo, useState, useRef, useCallback, useEffect } from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
6
|
import QRCodeUtil from 'qrcode/lib/core/qrcode.js';
|
|
@@ -62,6 +62,7 @@ function toErrorCode(error) {
|
|
|
62
62
|
// src/hooks/useIDKitFlow.ts
|
|
63
63
|
var isDebug = () => typeof window !== "undefined" && window.IDKIT_DEBUG;
|
|
64
64
|
function useIDKitFlow(createFlowHandle, config) {
|
|
65
|
+
const isInWorldApp$1 = useMemo(() => isInWorldApp(), []);
|
|
65
66
|
const [state, setState] = useState(
|
|
66
67
|
createInitialHookState
|
|
67
68
|
);
|
|
@@ -119,11 +120,12 @@ function useIDKitFlow(createFlowHandle, config) {
|
|
|
119
120
|
connectorURI: request.connectorURI,
|
|
120
121
|
requestId: request.requestId
|
|
121
122
|
});
|
|
123
|
+
const connectorURI = isInWorldApp$1 ? null : request.connectorURI;
|
|
122
124
|
setState((prev) => {
|
|
123
|
-
if (prev.connectorURI ===
|
|
125
|
+
if (prev.connectorURI === connectorURI) {
|
|
124
126
|
return prev;
|
|
125
127
|
}
|
|
126
|
-
return { ...prev, connectorURI
|
|
128
|
+
return { ...prev, connectorURI };
|
|
127
129
|
});
|
|
128
130
|
const pollInterval = configRef.current.polling?.interval ?? 1e3;
|
|
129
131
|
const timeout = configRef.current.polling?.timeout ?? 3e5;
|
|
@@ -179,7 +181,7 @@ function useIDKitFlow(createFlowHandle, config) {
|
|
|
179
181
|
abortRef.current = null;
|
|
180
182
|
}
|
|
181
183
|
};
|
|
182
|
-
}, [state.isOpen, runId]);
|
|
184
|
+
}, [state.isOpen, runId, isInWorldApp$1]);
|
|
183
185
|
return {
|
|
184
186
|
open,
|
|
185
187
|
reset,
|
|
@@ -190,7 +192,8 @@ function useIDKitFlow(createFlowHandle, config) {
|
|
|
190
192
|
connectorURI: state.connectorURI,
|
|
191
193
|
result: state.result,
|
|
192
194
|
errorCode: state.errorCode,
|
|
193
|
-
isOpen: state.isOpen
|
|
195
|
+
isOpen: state.isOpen,
|
|
196
|
+
isInWorldApp: isInWorldApp$1
|
|
194
197
|
};
|
|
195
198
|
}
|
|
196
199
|
|
|
@@ -1635,7 +1638,8 @@ function getVisualStage(isSuccess, isError, isHostVerifying) {
|
|
|
1635
1638
|
if (isSuccess) return "success";
|
|
1636
1639
|
return "worldid";
|
|
1637
1640
|
}
|
|
1638
|
-
function
|
|
1641
|
+
function IDKitWidgetBase({
|
|
1642
|
+
flow,
|
|
1639
1643
|
open,
|
|
1640
1644
|
onOpenChange,
|
|
1641
1645
|
handleVerify,
|
|
@@ -1643,12 +1647,8 @@ function IDKitRequestWidget({
|
|
|
1643
1647
|
onError,
|
|
1644
1648
|
autoClose = true,
|
|
1645
1649
|
language,
|
|
1646
|
-
|
|
1650
|
+
showSimulatorCallout
|
|
1647
1651
|
}) {
|
|
1648
|
-
if (typeof onSuccess !== "function") {
|
|
1649
|
-
throw new Error("IDKitRequestWidget requires an onSuccess callback.");
|
|
1650
|
-
}
|
|
1651
|
-
const flow = useIDKitRequest(config);
|
|
1652
1652
|
const { open: openFlow, reset: resetFlow } = flow;
|
|
1653
1653
|
const [hostVerifyResult, setHostVerifyResult] = useState(null);
|
|
1654
1654
|
const lastResultRef = useRef(null);
|
|
@@ -1690,13 +1690,31 @@ function IDKitRequestWidget({
|
|
|
1690
1690
|
});
|
|
1691
1691
|
}, [effectiveErrorCode, onError]);
|
|
1692
1692
|
useEffect(() => {
|
|
1693
|
-
if (
|
|
1693
|
+
if (!flow.isInWorldApp || !isHostVerifying || !flow.result || !handleVerify) {
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
let cancelled = false;
|
|
1697
|
+
void Promise.resolve(handleVerify(flow.result)).then(() => {
|
|
1698
|
+
if (!cancelled) setHostVerifyResult("passed");
|
|
1699
|
+
}).catch(() => {
|
|
1700
|
+
if (!cancelled) setHostVerifyResult("failed");
|
|
1701
|
+
});
|
|
1702
|
+
return () => {
|
|
1703
|
+
cancelled = true;
|
|
1704
|
+
};
|
|
1705
|
+
}, [flow.isInWorldApp, isHostVerifying, flow.result, handleVerify]);
|
|
1706
|
+
useEffect(() => {
|
|
1707
|
+
if (flow.isInWorldApp && (isSuccess || isError)) {
|
|
1708
|
+
onOpenChange(false);
|
|
1709
|
+
} else if (isSuccess && autoClose) {
|
|
1694
1710
|
const timer = setTimeout(() => onOpenChange(false), 2500);
|
|
1695
1711
|
return () => clearTimeout(timer);
|
|
1696
1712
|
}
|
|
1697
|
-
}, [isSuccess, autoClose, onOpenChange]);
|
|
1713
|
+
}, [isSuccess, isError, autoClose, onOpenChange, flow.isInWorldApp]);
|
|
1714
|
+
if (flow.isInWorldApp) {
|
|
1715
|
+
return null;
|
|
1716
|
+
}
|
|
1698
1717
|
const stage = getVisualStage(isSuccess, isError, isHostVerifying);
|
|
1699
|
-
const showSimulatorCallout = config.environment === "staging";
|
|
1700
1718
|
return /* @__PURE__ */ jsxs(IDKitModal, { open, onOpenChange, children: [
|
|
1701
1719
|
stage === "worldid" && /* @__PURE__ */ jsx(
|
|
1702
1720
|
WorldIDState,
|
|
@@ -1730,6 +1748,35 @@ function IDKitRequestWidget({
|
|
|
1730
1748
|
)
|
|
1731
1749
|
] });
|
|
1732
1750
|
}
|
|
1751
|
+
function IDKitRequestWidget({
|
|
1752
|
+
open,
|
|
1753
|
+
onOpenChange,
|
|
1754
|
+
handleVerify,
|
|
1755
|
+
onSuccess,
|
|
1756
|
+
onError,
|
|
1757
|
+
autoClose,
|
|
1758
|
+
language,
|
|
1759
|
+
...config
|
|
1760
|
+
}) {
|
|
1761
|
+
if (typeof onSuccess !== "function") {
|
|
1762
|
+
throw new Error("IDKitRequestWidget requires an onSuccess callback.");
|
|
1763
|
+
}
|
|
1764
|
+
const flow = useIDKitRequest(config);
|
|
1765
|
+
return /* @__PURE__ */ jsx(
|
|
1766
|
+
IDKitWidgetBase,
|
|
1767
|
+
{
|
|
1768
|
+
flow,
|
|
1769
|
+
open,
|
|
1770
|
+
onOpenChange,
|
|
1771
|
+
handleVerify,
|
|
1772
|
+
onSuccess,
|
|
1773
|
+
onError,
|
|
1774
|
+
autoClose,
|
|
1775
|
+
language,
|
|
1776
|
+
showSimulatorCallout: config.environment === "staging"
|
|
1777
|
+
}
|
|
1778
|
+
);
|
|
1779
|
+
}
|
|
1733
1780
|
|
|
1734
1781
|
export { IDKitRequestWidget, useIDKitRequest };
|
|
1735
1782
|
//# sourceMappingURL=index.js.map
|