@worldcoin/idkit 2.3.0 → 2.4.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/README.md +33 -0
- package/build/chunk-PWFTYFSZ.js +373 -0
- package/build/{config-BRFx4nLT.d.cts → config-SH5TbLYj.d.cts} +13 -1
- package/build/{config-BRFx4nLT.d.ts → config-SH5TbLYj.d.ts} +13 -1
- package/build/index.cjs +194 -32
- package/build/index.d.cts +2 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +50 -24
- package/build/internal.cjs +154 -10
- package/build/internal.d.cts +23 -8
- package/build/internal.d.ts +23 -8
- package/build/internal.js +10 -2
- package/package.json +1 -1
- package/src/index.ts +15 -2
- package/build/chunk-3HCETHXP.js +0 -233
package/README.md
CHANGED
|
@@ -33,3 +33,36 @@ To develop locally and contribute to this package, you can simply follow these i
|
|
|
33
33
|
# runs in the /idkit folder
|
|
34
34
|
yarn build
|
|
35
35
|
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### Set Language Explicitly
|
|
40
|
+
```tsx
|
|
41
|
+
<IDKitWidget
|
|
42
|
+
app_id="your_app_id"
|
|
43
|
+
action="your_action"
|
|
44
|
+
onSuccess={handleSuccess}
|
|
45
|
+
language="es" // Spanish
|
|
46
|
+
>
|
|
47
|
+
{({ open }) => <button onClick={open}>Verify with World ID</button>}
|
|
48
|
+
</IDKitWidget>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Automatic Language Detection (Default)
|
|
52
|
+
```tsx
|
|
53
|
+
<IDKitWidget
|
|
54
|
+
app_id="your_app_id"
|
|
55
|
+
action="your_action"
|
|
56
|
+
onSuccess={handleSuccess}
|
|
57
|
+
// No language prop needed - will auto-detect
|
|
58
|
+
>
|
|
59
|
+
{({ open }) => <button onClick={open}>Verify with World ID</button>}
|
|
60
|
+
</IDKitWidget>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Supported Languages
|
|
64
|
+
|
|
65
|
+
Currently supported languages:
|
|
66
|
+
- `en` - English (default)
|
|
67
|
+
- `es` - Spanish
|
|
68
|
+
- `th` - Thai
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// src/lang/translations/en.ts
|
|
2
|
+
var en = {
|
|
3
|
+
"All set!": "All set!",
|
|
4
|
+
"Your World ID is now connected": "Your World ID is now connected",
|
|
5
|
+
"Transmitting verification to host app. Please wait...": "Transmitting verification to host app. Please wait...",
|
|
6
|
+
"Something went wrong": "Something went wrong",
|
|
7
|
+
"Verification Declined": "Verification Declined",
|
|
8
|
+
"Request cancelled": "Request cancelled",
|
|
9
|
+
"Connection to your wallet failed. Please try again.": "Connection to your wallet failed. Please try again.",
|
|
10
|
+
"You've cancelled the request in World App.": "You've cancelled the request in World App.",
|
|
11
|
+
"You have already verified the maximum number of times for this action.": "You have already verified the maximum number of times for this action.",
|
|
12
|
+
"It seems you do not have the verification level required by this app.": "It seems you do not have the verification level required by this app.",
|
|
13
|
+
"Invalid network. If you are the app owner, visit docs.world.org/test for details.": "Invalid network. If you are the app owner, visit docs.world.org/test for details.",
|
|
14
|
+
"Your identity is still being registered. Please wait a few minutes and try again.": "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
15
|
+
"We couldn't complete your request. Please try again.": "We couldn't complete your request. Please try again.",
|
|
16
|
+
"Try Again": "Try Again",
|
|
17
|
+
"Open World App": "Open World App",
|
|
18
|
+
"Hide QR Code": "Hide QR Code",
|
|
19
|
+
"Display QR Code": "Display QR Code",
|
|
20
|
+
"QR Code copied": "QR Code copied",
|
|
21
|
+
"Connect your World ID": "Connect your World ID",
|
|
22
|
+
"Use phone camera to scan the QR code": "Use phone camera to scan the QR code",
|
|
23
|
+
"Connecting...": "Connecting...",
|
|
24
|
+
"Please continue in app": "Please continue in app",
|
|
25
|
+
"You will be redirected to the app, please return to this page once you're done": "You will be redirected to the app, please return to this page once you're done",
|
|
26
|
+
"Action cannot be an empty string.": "Action cannot be an empty string.",
|
|
27
|
+
"Invalid IDKitStage :stage.": "Invalid IDKitStage :stage.",
|
|
28
|
+
"Terms & Privacy": "Terms & Privacy"
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/lang/translations/es.ts
|
|
32
|
+
var es = {
|
|
33
|
+
"All set!": "\xA1Todo listo!",
|
|
34
|
+
"Your World ID is now connected": "Tu World ID ahora est\xE1 conectado",
|
|
35
|
+
"Transmitting verification to host app. Please wait...": "Transmitiendo verificaci\xF3n a la aplicaci\xF3n host. Por favor espera...",
|
|
36
|
+
"Something went wrong": "Algo sali\xF3 mal",
|
|
37
|
+
"Verification Declined": "Verificaci\xF3n rechazada",
|
|
38
|
+
"Request cancelled": "Solicitud cancelada",
|
|
39
|
+
"Connection to your wallet failed. Please try again.": "La conexi\xF3n a tu billetera fall\xF3. Por favor intenta de nuevo.",
|
|
40
|
+
"You've cancelled the request in World App.": "Has cancelado la solicitud en World App.",
|
|
41
|
+
"You have already verified the maximum number of times for this action.": "Ya has verificado el n\xFAmero m\xE1ximo de veces para esta acci\xF3n.",
|
|
42
|
+
"It seems you do not have the verification level required by this app.": "Parece que no tienes el nivel de verificaci\xF3n requerido por esta aplicaci\xF3n.",
|
|
43
|
+
"Invalid network. If you are the app owner, visit docs.world.org/test for details.": "Red inv\xE1lida. Si eres el propietario de la aplicaci\xF3n, visita docs.world.org/test para m\xE1s detalles.",
|
|
44
|
+
"Your identity is still being registered. Please wait a few minutes and try again.": "Tu identidad a\xFAn se est\xE1 registrando. Por favor espera unos minutos e intenta de nuevo.",
|
|
45
|
+
"We couldn't complete your request. Please try again.": "No pudimos completar tu solicitud. Por favor intenta de nuevo.",
|
|
46
|
+
"Try Again": "Intentar de nuevo",
|
|
47
|
+
"Open World App": "Abrir World App",
|
|
48
|
+
"Hide QR Code": "Ocultar c\xF3digo QR",
|
|
49
|
+
"Display QR Code": "Mostrar c\xF3digo QR",
|
|
50
|
+
"QR Code copied": "C\xF3digo QR copiado",
|
|
51
|
+
"Connect your World ID": "Conecta tu World ID",
|
|
52
|
+
"Use phone camera to scan the QR code": "Usa la c\xE1mara del tel\xE9fono para escanear el c\xF3digo QR",
|
|
53
|
+
"Connecting...": "Conectando...",
|
|
54
|
+
"Please continue in app": "Por favor contin\xFAa en la aplicaci\xF3n",
|
|
55
|
+
"You will be redirected to the app, please return to this page once you're done": "Ser\xE1s redirigido a la aplicaci\xF3n, por favor regresa a esta p\xE1gina una vez que hayas terminado",
|
|
56
|
+
"Action cannot be an empty string.": "La acci\xF3n no puede ser una cadena vac\xEDa.",
|
|
57
|
+
"Invalid IDKitStage :stage.": "IDKitStage inv\xE1lido :stage.",
|
|
58
|
+
"Terms & Privacy": "T\xE9rminos y privacidad"
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/lang/translations/th.ts
|
|
62
|
+
var th = {
|
|
63
|
+
"All set!": "\u0E40\u0E23\u0E35\u0E22\u0E1A\u0E23\u0E49\u0E2D\u0E22!",
|
|
64
|
+
"Your World ID is now connected": "World ID \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E41\u0E25\u0E49\u0E27",
|
|
65
|
+
"Transmitting verification to host app. Please wait...": "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E48\u0E07\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E44\u0E1B\u0E22\u0E31\u0E07\u0E41\u0E2D\u0E1B\u0E42\u0E2E\u0E2A\u0E15\u0E4C \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E2D\u0E2A\u0E31\u0E01\u0E04\u0E23\u0E39\u0E48...",
|
|
66
|
+
"Something went wrong": "\u0E40\u0E01\u0E34\u0E14\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14",
|
|
67
|
+
"Verification Declined": "\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E16\u0E39\u0E01\u0E1B\u0E0F\u0E34\u0E40\u0E2A\u0E18",
|
|
68
|
+
"Request cancelled": "\u0E04\u0E33\u0E02\u0E2D\u0E16\u0E39\u0E01\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01",
|
|
69
|
+
"Connection to your wallet failed. Please try again.": "\u0E01\u0E32\u0E23\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E01\u0E31\u0E1A\u0E01\u0E23\u0E30\u0E40\u0E1B\u0E4B\u0E32\u0E40\u0E07\u0E34\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E25\u0E49\u0E21\u0E40\u0E2B\u0E25\u0E27 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
|
|
70
|
+
"You've cancelled the request in World App.": "\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E04\u0E33\u0E02\u0E2D\u0E43\u0E19 World App",
|
|
71
|
+
"You have already verified the maximum number of times for this action.": "\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E04\u0E23\u0E1A\u0E08\u0E33\u0E19\u0E27\u0E19\u0E04\u0E23\u0E31\u0E49\u0E07\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14\u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E01\u0E32\u0E23\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E19\u0E35\u0E49\u0E41\u0E25\u0E49\u0E27",
|
|
72
|
+
"It seems you do not have the verification level required by this app.": "\u0E14\u0E39\u0E40\u0E2B\u0E21\u0E37\u0E2D\u0E19\u0E27\u0E48\u0E32\u0E04\u0E38\u0E13\u0E44\u0E21\u0E48\u0E21\u0E35\u0E23\u0E30\u0E14\u0E31\u0E1A\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E17\u0E35\u0E48\u0E41\u0E2D\u0E1B\u0E19\u0E35\u0E49\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23",
|
|
73
|
+
"Invalid network. If you are the app owner, visit docs.world.org/test for details.": "\u0E40\u0E04\u0E23\u0E37\u0E2D\u0E02\u0E48\u0E32\u0E22\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 \u0E2B\u0E32\u0E01\u0E04\u0E38\u0E13\u0E40\u0E1B\u0E47\u0E19\u0E40\u0E08\u0E49\u0E32\u0E02\u0E2D\u0E07\u0E41\u0E2D\u0E1B \u0E42\u0E1B\u0E23\u0E14\u0E44\u0E1B\u0E17\u0E35\u0E48 docs.world.org/test \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E23\u0E32\u0E22\u0E25\u0E30\u0E40\u0E2D\u0E35\u0E22\u0E14",
|
|
74
|
+
"Your identity is still being registered. Please wait a few minutes and try again.": "\u0E15\u0E31\u0E27\u0E15\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E22\u0E31\u0E07\u0E2D\u0E22\u0E39\u0E48\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E01\u0E32\u0E23\u0E25\u0E07\u0E17\u0E30\u0E40\u0E1A\u0E35\u0E22\u0E19 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E2D\u0E2A\u0E31\u0E01\u0E04\u0E23\u0E39\u0E48\u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
|
|
75
|
+
"We couldn't complete your request. Please try again.": "\u0E40\u0E23\u0E32\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E15\u0E32\u0E21\u0E04\u0E33\u0E02\u0E2D\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
|
|
76
|
+
"Try Again": "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
|
|
77
|
+
"Open World App": "\u0E40\u0E1B\u0E34\u0E14 World App",
|
|
78
|
+
"Hide QR Code": "\u0E0B\u0E48\u0E2D\u0E19 QR Code",
|
|
79
|
+
"Display QR Code": "\u0E41\u0E2A\u0E14\u0E07 QR Code",
|
|
80
|
+
"QR Code copied": "\u0E04\u0E31\u0E14\u0E25\u0E2D\u0E01 QR Code \u0E41\u0E25\u0E49\u0E27",
|
|
81
|
+
"Connect your World ID": "\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D World ID \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13",
|
|
82
|
+
"Use phone camera to scan the QR code": "\u0E43\u0E0A\u0E49\u0E01\u0E25\u0E49\u0E2D\u0E07\u0E42\u0E17\u0E23\u0E28\u0E31\u0E1E\u0E17\u0E4C\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2A\u0E41\u0E01\u0E19 QR code",
|
|
83
|
+
"Connecting...": "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D...",
|
|
84
|
+
"Please continue in app": "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E15\u0E48\u0E2D\u0E43\u0E19\u0E41\u0E2D\u0E1B",
|
|
85
|
+
"You will be redirected to the app, please return to this page once you're done": "\u0E04\u0E38\u0E13\u0E08\u0E30\u0E16\u0E39\u0E01\u0E19\u0E33\u0E44\u0E1B\u0E22\u0E31\u0E07\u0E41\u0E2D\u0E1B \u0E01\u0E23\u0E38\u0E13\u0E32\u0E01\u0E25\u0E31\u0E1A\u0E21\u0E32\u0E17\u0E35\u0E48\u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49\u0E40\u0E21\u0E37\u0E48\u0E2D\u0E40\u0E2A\u0E23\u0E47\u0E08\u0E41\u0E25\u0E49\u0E27",
|
|
86
|
+
"Action cannot be an empty string.": "\u0E01\u0E32\u0E23\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E40\u0E1B\u0E47\u0E19\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E27\u0E48\u0E32\u0E07\u0E44\u0E14\u0E49",
|
|
87
|
+
"Invalid IDKitStage :stage.": "IDKitStage \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 :stage.",
|
|
88
|
+
"Terms & Privacy": "\u0E02\u0E49\u0E2D\u0E01\u0E33\u0E2B\u0E19\u0E14\u0E41\u0E25\u0E30\u0E04\u0E27\u0E32\u0E21\u0E40\u0E1B\u0E47\u0E19\u0E2A\u0E48\u0E27\u0E19\u0E15\u0E31\u0E27"
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/lang/translations/index.ts
|
|
92
|
+
var translations = {
|
|
93
|
+
en,
|
|
94
|
+
es,
|
|
95
|
+
th
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/lang/localization.ts
|
|
99
|
+
var currentConfig = {};
|
|
100
|
+
var setLocalizationConfig = (config) => {
|
|
101
|
+
currentConfig = config;
|
|
102
|
+
};
|
|
103
|
+
var getLocalizationConfig = () => currentConfig;
|
|
104
|
+
var detectBrowserLanguage = () => {
|
|
105
|
+
for (const lang of navigator.languages) {
|
|
106
|
+
const [language] = lang.split("-");
|
|
107
|
+
const normalizedLang = language.toLowerCase();
|
|
108
|
+
if (normalizedLang in translations) {
|
|
109
|
+
return normalizedLang;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return void 0;
|
|
113
|
+
};
|
|
114
|
+
var getCurrentLanguage = () => {
|
|
115
|
+
const config = getLocalizationConfig();
|
|
116
|
+
if (config.language && config.language in translations) {
|
|
117
|
+
return config.language;
|
|
118
|
+
}
|
|
119
|
+
const browserLang = detectBrowserLanguage();
|
|
120
|
+
if (browserLang) {
|
|
121
|
+
return browserLang;
|
|
122
|
+
}
|
|
123
|
+
return "en";
|
|
124
|
+
};
|
|
125
|
+
var getTranslations = () => {
|
|
126
|
+
const currentLang = getCurrentLanguage();
|
|
127
|
+
return translations[currentLang];
|
|
128
|
+
};
|
|
129
|
+
var getSupportedLanguages = () => {
|
|
130
|
+
return Object.keys(translations);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/lang/index.ts
|
|
134
|
+
var getLang = () => {
|
|
135
|
+
return getTranslations();
|
|
136
|
+
};
|
|
137
|
+
var replaceParams = (str, params) => {
|
|
138
|
+
if (!params) return str;
|
|
139
|
+
let result = str;
|
|
140
|
+
for (const [key, value] of Object.entries(params)) {
|
|
141
|
+
result = result.replace(`:${key}`, value);
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
};
|
|
145
|
+
function __(str, ...args) {
|
|
146
|
+
const [params] = args;
|
|
147
|
+
if (typeof navigator === "undefined" && typeof window === "undefined") {
|
|
148
|
+
return replaceParams(str, params);
|
|
149
|
+
}
|
|
150
|
+
const translated = getLang()?.[str] ?? str;
|
|
151
|
+
return replaceParams(translated, params);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/store/idkit.ts
|
|
155
|
+
import { shallow } from "zustand/shallow";
|
|
156
|
+
import { createWithEqualityFn } from "zustand/traditional";
|
|
157
|
+
import {
|
|
158
|
+
AppErrorCodes,
|
|
159
|
+
DEFAULT_VERIFICATION_LEVEL
|
|
160
|
+
} from "@worldcoin/idkit-core";
|
|
161
|
+
var SELF_HOSTED_APP_ID = "self_hosted";
|
|
162
|
+
var useIDKitStore = createWithEqualityFn()(
|
|
163
|
+
(set, get) => ({
|
|
164
|
+
app_id: "",
|
|
165
|
+
signal: "",
|
|
166
|
+
action: "",
|
|
167
|
+
action_description: "",
|
|
168
|
+
bridge_url: "",
|
|
169
|
+
verification_level: DEFAULT_VERIFICATION_LEVEL,
|
|
170
|
+
partner: false,
|
|
171
|
+
open: false,
|
|
172
|
+
result: null,
|
|
173
|
+
errorTitle: "",
|
|
174
|
+
errorDetail: "",
|
|
175
|
+
autoClose: true,
|
|
176
|
+
errorState: null,
|
|
177
|
+
processing: false,
|
|
178
|
+
errorCallbacks: {},
|
|
179
|
+
verifyCallbacks: {},
|
|
180
|
+
successCallbacks: {},
|
|
181
|
+
stage: "WORLD_ID" /* WORLD_ID */,
|
|
182
|
+
setStage: (stage) => set({ stage }),
|
|
183
|
+
setErrorState: (errorState) => set({ errorState }),
|
|
184
|
+
setProcessing: (processing) => set({ processing }),
|
|
185
|
+
retryFlow: () => {
|
|
186
|
+
set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
|
|
187
|
+
},
|
|
188
|
+
addErrorCallback: (cb, source) => {
|
|
189
|
+
set((state) => {
|
|
190
|
+
state.errorCallbacks[source] = cb;
|
|
191
|
+
return state;
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
addSuccessCallback: (cb, source) => {
|
|
195
|
+
set((state) => {
|
|
196
|
+
state.successCallbacks[source] = cb;
|
|
197
|
+
return state;
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
addVerificationCallback: (cb, source) => {
|
|
201
|
+
set((state) => {
|
|
202
|
+
state.verifyCallbacks[source] = cb;
|
|
203
|
+
return state;
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
setOptions: ({
|
|
207
|
+
handleVerify,
|
|
208
|
+
onSuccess,
|
|
209
|
+
signal,
|
|
210
|
+
action,
|
|
211
|
+
app_id,
|
|
212
|
+
partner,
|
|
213
|
+
onError,
|
|
214
|
+
verification_level,
|
|
215
|
+
action_description,
|
|
216
|
+
bridge_url,
|
|
217
|
+
autoClose,
|
|
218
|
+
advanced
|
|
219
|
+
}, source) => {
|
|
220
|
+
set({
|
|
221
|
+
signal,
|
|
222
|
+
action,
|
|
223
|
+
bridge_url,
|
|
224
|
+
action_description,
|
|
225
|
+
autoClose: autoClose ?? true,
|
|
226
|
+
app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
|
|
227
|
+
verification_level: verification_level ?? DEFAULT_VERIFICATION_LEVEL,
|
|
228
|
+
partner
|
|
229
|
+
});
|
|
230
|
+
get().addSuccessCallback(onSuccess, source);
|
|
231
|
+
if (onError) get().addErrorCallback(onError, source);
|
|
232
|
+
if (handleVerify) get().addVerificationCallback(handleVerify, source);
|
|
233
|
+
},
|
|
234
|
+
handleVerify: (result) => {
|
|
235
|
+
set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
|
|
236
|
+
Promise.all(Object.values(get().verifyCallbacks).map(async (cb) => cb?.(result))).then(
|
|
237
|
+
() => {
|
|
238
|
+
set({ stage: "SUCCESS" /* SUCCESS */, result });
|
|
239
|
+
if (get().autoClose) setTimeout(() => get().onOpenChange(false), 2500);
|
|
240
|
+
},
|
|
241
|
+
(response) => {
|
|
242
|
+
let errorMessage = void 0;
|
|
243
|
+
if (response && typeof response === "object" && response.message) {
|
|
244
|
+
errorMessage = response.message;
|
|
245
|
+
}
|
|
246
|
+
set({
|
|
247
|
+
stage: "ERROR" /* ERROR */,
|
|
248
|
+
errorState: {
|
|
249
|
+
code: AppErrorCodes.FailedByHostApp,
|
|
250
|
+
message: errorMessage ? __(errorMessage) : void 0
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
},
|
|
256
|
+
onOpenChange: (open) => {
|
|
257
|
+
if (open) {
|
|
258
|
+
return set({ open });
|
|
259
|
+
}
|
|
260
|
+
const errorState = get().errorState;
|
|
261
|
+
if (get().stage === "ERROR" /* ERROR */ && errorState) {
|
|
262
|
+
const callbacks = get().errorCallbacks;
|
|
263
|
+
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
|
|
264
|
+
}
|
|
265
|
+
const result = get().result;
|
|
266
|
+
if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
|
|
267
|
+
const callbacks = get().successCallbacks;
|
|
268
|
+
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
|
|
269
|
+
}
|
|
270
|
+
set({
|
|
271
|
+
open,
|
|
272
|
+
result: null,
|
|
273
|
+
errorState: null,
|
|
274
|
+
processing: false,
|
|
275
|
+
stage: "WORLD_ID" /* WORLD_ID */
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}),
|
|
279
|
+
shallow
|
|
280
|
+
);
|
|
281
|
+
var idkit_default = useIDKitStore;
|
|
282
|
+
|
|
283
|
+
// src/types/config.ts
|
|
284
|
+
var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
|
|
285
|
+
ConfigSource2["HOOK"] = "hook";
|
|
286
|
+
ConfigSource2["PROPS"] = "props";
|
|
287
|
+
ConfigSource2["MANUAL"] = "manual";
|
|
288
|
+
return ConfigSource2;
|
|
289
|
+
})(ConfigSource || {});
|
|
290
|
+
|
|
291
|
+
// src/components/QRCode.tsx
|
|
292
|
+
import { memo, useMemo } from "react";
|
|
293
|
+
import QRCodeUtil from "qrcode/lib/core/qrcode.js";
|
|
294
|
+
import { jsx } from "react/jsx-runtime";
|
|
295
|
+
var generateMatrix = (data) => {
|
|
296
|
+
const arr = QRCodeUtil.create(data, { errorCorrectionLevel: "M" }).modules.data;
|
|
297
|
+
const sqrt = Math.sqrt(arr.length);
|
|
298
|
+
return arr.reduce(
|
|
299
|
+
(rows, key, index) => {
|
|
300
|
+
if (index % sqrt === 0) rows.push([key]);
|
|
301
|
+
else rows[rows.length - 1].push(key);
|
|
302
|
+
return rows;
|
|
303
|
+
},
|
|
304
|
+
[]
|
|
305
|
+
);
|
|
306
|
+
};
|
|
307
|
+
var Qrcode = ({ data, size = 300 }) => {
|
|
308
|
+
const dots = useMemo(() => {
|
|
309
|
+
const dots2 = [];
|
|
310
|
+
const matrix = generateMatrix(data);
|
|
311
|
+
const cellSize = size / matrix.length;
|
|
312
|
+
const qrList = [
|
|
313
|
+
{ x: 0, y: 0 },
|
|
314
|
+
{ x: 1, y: 0 },
|
|
315
|
+
{ x: 0, y: 1 }
|
|
316
|
+
];
|
|
317
|
+
qrList.forEach(({ x, y }) => {
|
|
318
|
+
const x1 = (matrix.length - 7) * cellSize * x;
|
|
319
|
+
const y1 = (matrix.length - 7) * cellSize * y;
|
|
320
|
+
for (let i = 0; i < 3; i++) {
|
|
321
|
+
dots2.push(
|
|
322
|
+
/* @__PURE__ */ jsx(
|
|
323
|
+
"rect",
|
|
324
|
+
{
|
|
325
|
+
fill: "currentColor",
|
|
326
|
+
x: x1 + cellSize * i,
|
|
327
|
+
y: y1 + cellSize * i,
|
|
328
|
+
width: cellSize * (7 - i * 2),
|
|
329
|
+
height: cellSize * (7 - i * 2),
|
|
330
|
+
rx: (i - 2) * -5,
|
|
331
|
+
ry: (i - 2) * -5,
|
|
332
|
+
className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
|
|
333
|
+
},
|
|
334
|
+
`${i}-${x}-${y}`
|
|
335
|
+
)
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
matrix.forEach((row, i) => {
|
|
340
|
+
row.forEach((_, j) => {
|
|
341
|
+
if (!matrix[i][j]) return;
|
|
342
|
+
if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8) return;
|
|
343
|
+
dots2.push(
|
|
344
|
+
/* @__PURE__ */ jsx(
|
|
345
|
+
"circle",
|
|
346
|
+
{
|
|
347
|
+
fill: "currentColor",
|
|
348
|
+
r: cellSize / 2.2,
|
|
349
|
+
cx: i * cellSize + cellSize / 2,
|
|
350
|
+
cy: j * cellSize + cellSize / 2,
|
|
351
|
+
className: "text-black dark:text-white"
|
|
352
|
+
},
|
|
353
|
+
`circle-${i}-${j}`
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
return dots2;
|
|
359
|
+
}, [size, data]);
|
|
360
|
+
return /* @__PURE__ */ jsx("svg", { height: size, width: size, "data-test-id": "qr-code", children: dots });
|
|
361
|
+
};
|
|
362
|
+
var QRCode_default = memo(Qrcode);
|
|
363
|
+
|
|
364
|
+
export {
|
|
365
|
+
setLocalizationConfig,
|
|
366
|
+
getLocalizationConfig,
|
|
367
|
+
getCurrentLanguage,
|
|
368
|
+
getSupportedLanguages,
|
|
369
|
+
__,
|
|
370
|
+
idkit_default,
|
|
371
|
+
ConfigSource,
|
|
372
|
+
QRCode_default
|
|
373
|
+
};
|
|
@@ -8,6 +8,16 @@ declare enum IDKITStage {
|
|
|
8
8
|
}
|
|
9
9
|
type CallbackFn<T> = (result: T) => Promise<void> | void;
|
|
10
10
|
|
|
11
|
+
type SupportedLanguage = 'en' | 'es' | 'th';
|
|
12
|
+
interface LocalizationConfig {
|
|
13
|
+
language?: SupportedLanguage;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const setLocalizationConfig: (config: LocalizationConfig) => void;
|
|
17
|
+
declare const getLocalizationConfig: () => LocalizationConfig;
|
|
18
|
+
declare const getCurrentLanguage: () => SupportedLanguage;
|
|
19
|
+
declare const getSupportedLanguages: () => SupportedLanguage[];
|
|
20
|
+
|
|
11
21
|
declare enum ConfigSource {
|
|
12
22
|
HOOK = "hook",
|
|
13
23
|
PROPS = "props",
|
|
@@ -40,6 +50,8 @@ type WidgetProps = Config & {
|
|
|
40
50
|
/** Whether to disable the default modal behavior. Defaults to `false`. */
|
|
41
51
|
disable_default_modal_behavior?: boolean;
|
|
42
52
|
container_id?: string;
|
|
53
|
+
/** Language for the widget UI. If not specified, will auto-detect from browser or use English as fallback. */
|
|
54
|
+
language?: SupportedLanguage;
|
|
43
55
|
};
|
|
44
56
|
|
|
45
|
-
export { type Config as C, IDKITStage as I, type WidgetProps as W,
|
|
57
|
+
export { type Config as C, IDKITStage as I, type SupportedLanguage as S, type WidgetProps as W, getCurrentLanguage as a, getSupportedLanguages as b, ConfigSource as c, type CallbackFn as d, getLocalizationConfig as g, setLocalizationConfig as s };
|
|
@@ -8,6 +8,16 @@ declare enum IDKITStage {
|
|
|
8
8
|
}
|
|
9
9
|
type CallbackFn<T> = (result: T) => Promise<void> | void;
|
|
10
10
|
|
|
11
|
+
type SupportedLanguage = 'en' | 'es' | 'th';
|
|
12
|
+
interface LocalizationConfig {
|
|
13
|
+
language?: SupportedLanguage;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const setLocalizationConfig: (config: LocalizationConfig) => void;
|
|
17
|
+
declare const getLocalizationConfig: () => LocalizationConfig;
|
|
18
|
+
declare const getCurrentLanguage: () => SupportedLanguage;
|
|
19
|
+
declare const getSupportedLanguages: () => SupportedLanguage[];
|
|
20
|
+
|
|
11
21
|
declare enum ConfigSource {
|
|
12
22
|
HOOK = "hook",
|
|
13
23
|
PROPS = "props",
|
|
@@ -40,6 +50,8 @@ type WidgetProps = Config & {
|
|
|
40
50
|
/** Whether to disable the default modal behavior. Defaults to `false`. */
|
|
41
51
|
disable_default_modal_behavior?: boolean;
|
|
42
52
|
container_id?: string;
|
|
53
|
+
/** Language for the widget UI. If not specified, will auto-detect from browser or use English as fallback. */
|
|
54
|
+
language?: SupportedLanguage;
|
|
43
55
|
};
|
|
44
56
|
|
|
45
|
-
export { type Config as C, IDKITStage as I, type WidgetProps as W,
|
|
57
|
+
export { type Config as C, IDKITStage as I, type SupportedLanguage as S, type WidgetProps as W, getCurrentLanguage as a, getSupportedLanguages as b, ConfigSource as c, type CallbackFn as d, getLocalizationConfig as g, setLocalizationConfig as s };
|