diff --git a/examples/with-html/index.html b/examples/with-html/index.html index 29b790b8..fc9088bf 100644 --- a/examples/with-html/index.html +++ b/examples/with-html/index.html @@ -53,6 +53,7 @@

idkit-js

}) document.getElementById('open-idkit').addEventListener('click', async () => { + console.log(IDKit.isInitialized) await IDKit.open() }) diff --git a/packages/react/package.json b/packages/react/package.json index 52e236bb..6a5ce7a3 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -78,6 +78,7 @@ "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", "autoprefixer": "^10.4.19", + "clsx": "^2.1.1", "eslint": "8.54.0", "eslint-config-prettier": "^8.10.0", "eslint-plugin-compat": "^4.2.0", diff --git a/packages/react/src/components/IDKitWidget/BaseWidget.tsx b/packages/react/src/components/IDKitWidget/BaseWidget.tsx index 8dc9b982..89cdd8d0 100644 --- a/packages/react/src/components/IDKitWidget/BaseWidget.tsx +++ b/packages/react/src/components/IDKitWidget/BaseWidget.tsx @@ -97,7 +97,7 @@ const IDKitWidget: FC = ({ children, ...config }) => {
- +
diff --git a/packages/react/src/components/IDKitWidget/States/WorldID/QRState.tsx b/packages/react/src/components/IDKitWidget/States/WorldID/QRState.tsx index 32b4bd2e..2042fcc4 100644 --- a/packages/react/src/components/IDKitWidget/States/WorldID/QRState.tsx +++ b/packages/react/src/components/IDKitWidget/States/WorldID/QRState.tsx @@ -8,6 +8,7 @@ import { useCallback, useState } from 'react' import { AnimatePresence, motion } from 'framer-motion' import WorldcoinIcon from '@/components/Icons/WorldcoinIcon' import QRPlaceholderIcon from '@/components/Icons/QRPlaceholderIcon' +import clsx from 'clsx' type Props = { qrData: string | null @@ -28,19 +29,19 @@ const QRState: FC = ({ qrData, showQR, setShowQR }) => { return ( <> -
+
- + = ({ qrData, showQR, setShowQR }) => { {__('Open Worldcoin App')} -
-
+
+

or
@@ -114,8 +115,8 @@ const QRState: FC = ({ qrData, showQR, setShowQR }) => {
) : ( -
- +
+
)}
diff --git a/packages/react/src/components/IDKitWidget/States/WorldIDState.tsx b/packages/react/src/components/IDKitWidget/States/WorldIDState.tsx index 5dc9a453..d6ffe71f 100644 --- a/packages/react/src/components/IDKitWidget/States/WorldIDState.tsx +++ b/packages/react/src/components/IDKitWidget/States/WorldIDState.tsx @@ -9,6 +9,7 @@ import { useWorldBridge } from '@/services/wld-bridge' import LoadingIcon from '@/components/Icons/LoadingIcon' import WorldcoinIcon from '@/components/Icons/WorldcoinIcon' import { AppErrorCodes, VerificationState, VerificationLevel } from '@worldcoin/idkit-core' +import clsx from 'clsx' const getOptions = (store: IDKitStore) => ({ signal: store.signal, @@ -67,7 +68,7 @@ const WorldIDState = () => { }, [result, handleVerify, verificationState, setStage, errorCode, setErrorState, verification_level]) return ( -
+
@@ -82,7 +83,7 @@ const WorldIDState = () => {
{verificationState == VerificationState.WaitingForApp && (
- +

Verifying

Please continue in app

diff --git a/packages/standalone/src/index.tsx b/packages/standalone/src/index.tsx index bd1d7ad9..603c718a 100644 --- a/packages/standalone/src/index.tsx +++ b/packages/standalone/src/index.tsx @@ -54,6 +54,13 @@ const open = () => { }) } +const close = () => { + return new Promise((_, reject) => { + if (!isInitialized) return reject(__('IDKitWidget is not initialized')) + useIDKitStore.setState({ open: false }) + }) +} + /** * Reset internal state. Useful for unit-testing */ @@ -65,7 +72,16 @@ const reset = () => { useIDKitStore.destroy() } -const IDKit = { init, update, open, reset } +const IDKit = { + init, + update, + open, + close, + reset, + get isInitialized() { + return isInitialized + }, +} window.IDKit = IDKit declare global { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9df9cbc8..9838df39 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -141,6 +141,9 @@ importers: autoprefixer: specifier: ^10.4.19 version: 10.4.19(postcss@8.4.39) + clsx: + specifier: ^2.1.1 + version: 2.1.1 eslint: specifier: 8.54.0 version: 8.54.0 @@ -1506,6 +1509,10 @@ packages: resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} engines: {node: '>=12'} + clsx@2.1.1: + resolution: {integrity: sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==} + engines: {node: '>=6'} + color-convert@1.9.3: resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} @@ -5007,6 +5014,8 @@ snapshots: strip-ansi: 6.0.1 wrap-ansi: 7.0.0 + clsx@2.1.1: {} + color-convert@1.9.3: dependencies: color-name: 1.1.3