@opexa/portal-components 0.0.311 → 0.0.313

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.
Files changed (121) hide show
  1. package/dist/client/hooks/useFileQuery.js +5 -5
  2. package/dist/client/hooks/useGenerateSumsubVerificationTokenMutation.d.ts +2 -0
  3. package/dist/client/hooks/useGenerateSumsubVerificationTokenMutation.js +19 -0
  4. package/dist/client/hooks/useGlobalStore.d.ts +25 -1
  5. package/dist/client/hooks/useGlobalStore.js +3 -2
  6. package/dist/client/utils/recaptcha.d.ts +14 -0
  7. package/dist/client/utils/recaptcha.js +18 -0
  8. package/dist/components/AccountVerification/AccountVerification.js +33 -21
  9. package/dist/components/Banner/Banner.client.d.ts +12 -0
  10. package/dist/components/Banner/Banner.client.js +49 -0
  11. package/dist/components/Banner/Banner.d.ts +5 -0
  12. package/dist/components/Banner/Banner.js +3 -0
  13. package/dist/components/Disclaimer/ResponsibleGaming.d.ts +10 -0
  14. package/dist/components/Disclaimer/ResponsibleGaming.js +13 -0
  15. package/dist/components/Disclaimer/TermsOfUse.d.ts +11 -0
  16. package/dist/components/Disclaimer/TermsOfUse.js +13 -0
  17. package/dist/components/Jackpots/JackpotsCarousel/JackpotsCarouselItem.module.css +184 -184
  18. package/dist/components/Jackpots/JackpotsList/JackpotsListItem.module.css +184 -184
  19. package/dist/components/KYC/CaptureIdDocument.d.ts +1 -0
  20. package/dist/components/KYC/CaptureIdDocument.js +219 -0
  21. package/dist/components/KYC/CaptureSelfie.d.ts +1 -0
  22. package/dist/components/KYC/CaptureSelfie.js +285 -0
  23. package/dist/components/KYC/DisplayImage.d.ts +5 -0
  24. package/dist/components/KYC/DisplayImage.js +8 -0
  25. package/dist/components/KYC/FileUpload.d.ts +10 -0
  26. package/dist/components/KYC/FileUpload.js +72 -0
  27. package/dist/components/KYC/KYC.d.ts +4 -3
  28. package/dist/components/KYC/KYC.js +10 -3
  29. package/dist/components/KYC/KYCDefault/BasicInformation.d.ts +1 -0
  30. package/dist/components/KYC/KYCDefault/BasicInformation.js +101 -0
  31. package/dist/components/KYC/KYCDefault/IdentityVerification.d.ts +1 -0
  32. package/dist/components/KYC/KYCDefault/IdentityVerification.js +120 -0
  33. package/dist/components/KYC/KYCDefault/Indicator.d.ts +1 -0
  34. package/dist/components/KYC/KYCDefault/Indicator.js +8 -0
  35. package/dist/components/KYC/KYCDefault/KYCDefault.d.ts +7 -0
  36. package/dist/components/KYC/KYCDefault/KYCDefault.js +45 -0
  37. package/dist/components/KYC/KYCDefault/KYCDefaultContext.d.ts +6 -0
  38. package/dist/components/KYC/KYCDefault/KYCDefaultContext.js +2 -0
  39. package/dist/components/KYC/KYCDefault/PersonalInformation.d.ts +1 -0
  40. package/dist/components/KYC/KYCDefault/PersonalInformation.js +122 -0
  41. package/dist/components/KYC/KYCDefault/index.d.ts +1 -0
  42. package/dist/components/KYC/KYCDefault/index.js +1 -0
  43. package/dist/components/KYC/KYCDefault/useKYCDefault.d.ts +25 -0
  44. package/dist/components/KYC/KYCDefault/useKYCDefault.js +38 -0
  45. package/dist/components/KYC/KYCReminder.d.ts +1 -0
  46. package/dist/components/KYC/KYCReminder.lazy.js +3 -3
  47. package/dist/components/KYC/KYCSumsub.d.ts +5 -0
  48. package/dist/components/KYC/KYCSumsub.js +54 -0
  49. package/dist/components/KYC/NoCameraError.d.ts +7 -0
  50. package/dist/components/KYC/NoCameraError.js +6 -0
  51. package/dist/components/KYC/PersonOverlayDesktop.d.ts +7 -0
  52. package/dist/components/KYC/PersonOverlayDesktop.js +9 -0
  53. package/dist/components/KYC/index.d.ts +0 -1
  54. package/dist/components/KYC/index.js +0 -1
  55. package/dist/components/KYC/utils.d.ts +9 -0
  56. package/dist/components/KYC/utils.js +79 -0
  57. package/dist/components/Quests/JourneyQuest.js +1 -1
  58. package/dist/components/Quests/RemainingTime.d.ts +5 -1
  59. package/dist/components/Quests/RemainingTime.js +6 -2
  60. package/dist/components/SignIn/utils.d.ts +8 -0
  61. package/dist/components/SignIn/utils.js +26 -0
  62. package/dist/components/SignUp/SignUpDefault/SignUp.lazy.d.ts +17 -0
  63. package/dist/components/SignUp/SignUpDefault/SignUp.lazy.js +18 -0
  64. package/dist/components/SignUp/SignUpDefault/SignUpContext.d.ts +6 -0
  65. package/dist/components/SignUp/SignUpDefault/SignUpContext.js +2 -0
  66. package/dist/components/SignUp/SignUpDefault/SignUpForm.d.ts +1 -0
  67. package/dist/components/SignUp/SignUpDefault/SignUpForm.js +310 -0
  68. package/dist/components/SignUp/SignUpKYC/CaptureIdDocument.d.ts +1 -0
  69. package/dist/components/SignUp/SignUpKYC/CaptureIdDocument.js +198 -0
  70. package/dist/components/SignUp/SignUpKYC/CaptureSelfie.d.ts +1 -0
  71. package/dist/components/SignUp/SignUpKYC/CaptureSelfie.js +251 -0
  72. package/dist/components/SignUp/SignUpKYC/ImageUploader.d.ts +10 -0
  73. package/dist/components/SignUp/SignUpKYC/ImageUploader.js +42 -0
  74. package/dist/components/SignUp/SignUpKYC/PersonOverlayDesktop.d.ts +7 -0
  75. package/dist/components/SignUp/SignUpKYC/PersonOverlayDesktop.js +9 -0
  76. package/dist/components/SignUp/SignUpKYC/SignUpFormKYC.d.ts +1 -0
  77. package/dist/components/SignUp/SignUpKYC/SignUpFormKYC.js +464 -0
  78. package/dist/components/SignUp/SignUpKYC/useImageUploader.d.ts +11 -0
  79. package/dist/components/SignUp/SignUpKYC/useImageUploader.js +20 -0
  80. package/dist/components/SignUp/SignUpKYC/utils.d.ts +9 -0
  81. package/dist/components/SignUp/SignUpKYC/utils.js +79 -0
  82. package/dist/components/Tournaments/TournamentsCarousel/TournamentsCarouselItem.module.css +184 -184
  83. package/dist/components/Tournaments/TournamentsList/TournamentItem.module.css +184 -184
  84. package/dist/constants/Branches.d.ts +2 -0
  85. package/dist/constants/Branches.js +42 -0
  86. package/dist/handlers/postTransformIdFrontImage.d.ts +3 -0
  87. package/dist/handlers/postTransformIdFrontImage.js +82 -0
  88. package/dist/handlers/postTransformSelfieImage.d.ts +3 -0
  89. package/dist/handlers/postTransformSelfieImage.js +82 -0
  90. package/dist/next.config.js +1 -0
  91. package/dist/services/account.d.ts +4 -0
  92. package/dist/services/account.js +5 -1
  93. package/dist/services/queries.d.ts +1 -0
  94. package/dist/services/queries.js +2644 -2639
  95. package/dist/styles/theme.css +706 -706
  96. package/dist/third-parties/FacebookPixel/FacebookPixel.d.ts +4 -0
  97. package/dist/third-parties/FacebookPixel/FacebookPixel.js +4 -0
  98. package/dist/third-parties/FacebookPixel/api.d.ts +0 -0
  99. package/dist/third-parties/FacebookPixel/api.js +1 -0
  100. package/dist/third-parties/FacebookPixel/index.d.ts +1 -0
  101. package/dist/third-parties/FacebookPixel/index.js +1 -0
  102. package/dist/third-parties/GoogleRecaptcha/GoogleRecaptcha.d.ts +4 -0
  103. package/dist/third-parties/GoogleRecaptcha/GoogleRecaptcha.js +4 -0
  104. package/dist/third-parties/GoogleRecaptcha/api.d.ts +0 -0
  105. package/dist/third-parties/GoogleRecaptcha/api.js +1 -0
  106. package/dist/third-parties/GoogleRecaptcha/index.d.ts +1 -0
  107. package/dist/third-parties/GoogleRecaptcha/index.js +1 -0
  108. package/dist/third-parties/index.d.ts +2 -0
  109. package/dist/third-parties/index.js +2 -0
  110. package/dist/ui/Dialog/Dialog.d.ts +88 -88
  111. package/dist/ui/Dialog/dialog.recipe.d.ts +8 -8
  112. package/dist/ui/Dialog/dialog.recipe.js +1 -1
  113. package/dist/utils/gamesAvailable3pmTo3am.d.ts +1 -0
  114. package/dist/utils/gamesAvailable3pmTo3am.js +1 -0
  115. package/dist/utils/getGameName.d.ts +1 -0
  116. package/dist/utils/getGameName.js +6 -0
  117. package/dist/utils/isBetween3amAnd3pm.d.ts +1 -0
  118. package/dist/utils/isBetween3amAnd3pm.js +5 -0
  119. package/dist/utils/mutationKeys.d.ts +1 -0
  120. package/dist/utils/mutationKeys.js +1 -0
  121. package/package.json +160 -158
@@ -0,0 +1,285 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as faceapi from 'face-api.js';
4
+ import { useEffect, useRef, useState } from 'react';
5
+ import { twMerge } from 'tailwind-merge';
6
+ import { useUploadImageFileMutation } from '../../client/hooks/useUploadImageFileMutation.js';
7
+ import { ArrowLeftIcon } from '../../icons/ArrowLeftIcon.js';
8
+ import { Camera01Icon } from '../../icons/Camera01Icon.js';
9
+ import { XIcon } from '../../icons/XIcon.js';
10
+ import { Button } from '../../ui/Button/index.js';
11
+ import { Dialog } from '../../ui/Dialog/index.js';
12
+ import { onMobileDevice } from '../../utils/onMobileDevice.js';
13
+ import { useKYCContext } from './KYCContext.js';
14
+ import NoCameraError from './NoCameraError.js';
15
+ import PersonOverlayDesktop from './PersonOverlayDesktop.js';
16
+ import { dataURLtoBlob, loadFaceApiModels, resizeFile, showPermissionInstructions, } from './utils.js';
17
+ export function CaptureSelfie() {
18
+ const kyc = useKYCContext();
19
+ const { mutate, isPending } = useUploadImageFileMutation();
20
+ const mobileDevice = onMobileDevice();
21
+ const [modelsLoaded, setModelsLoaded] = useState(false);
22
+ const [videoStream, setVideoStream] = useState(null);
23
+ const [cameraError, setCameraError] = useState(null);
24
+ const [captureInProgress, setCaptureInProgress] = useState(false);
25
+ const [selectedImage, setSelectedImage] = useState(null);
26
+ const [isFaceCentered, setIsFaceCentered] = useState(false);
27
+ const [isCapturing, setIsCapturing] = useState(false);
28
+ const [countdown, setCountdown] = useState(3);
29
+ const videoRef = useRef(null);
30
+ const faceCanvasRef = useRef(null);
31
+ const detectionIntervalRef = useRef(null);
32
+ const countdownTimerRef = useRef(null);
33
+ useEffect(() => {
34
+ loadFaceApiModels()
35
+ .then(() => setModelsLoaded(true))
36
+ .catch(() => setModelsLoaded(false));
37
+ }, []);
38
+ useEffect(() => {
39
+ if (captureInProgress) {
40
+ startFaceDetection();
41
+ }
42
+ }, [captureInProgress]);
43
+ async function startCamera() {
44
+ try {
45
+ setCaptureInProgress(true);
46
+ const stream = await navigator.mediaDevices.getUserMedia({
47
+ video: {
48
+ facingMode: mobileDevice ? 'user' : 'environment',
49
+ aspectRatio: mobileDevice ? 9 / 16 : 16 / 9,
50
+ width: { ideal: 1920 },
51
+ height: { ideal: 1080 },
52
+ },
53
+ audio: false,
54
+ });
55
+ setVideoStream(stream);
56
+ if (videoRef.current) {
57
+ videoRef.current.srcObject = stream;
58
+ videoRef.current.onloadedmetadata = () => {
59
+ videoRef.current
60
+ ?.play()
61
+ .then(() => {
62
+ if (modelsLoaded) {
63
+ startFaceDetection();
64
+ }
65
+ })
66
+ .catch((error) => {
67
+ console.error('Error playing video:', error);
68
+ setCameraError('Failed to play video stream. Please check your camera settings.');
69
+ });
70
+ };
71
+ }
72
+ }
73
+ catch (error) {
74
+ if (error instanceof DOMException) {
75
+ console.error('Error accessing camera:', error.message);
76
+ setCameraError(error.name);
77
+ }
78
+ else {
79
+ console.error('Unknown error accessing camera:', error);
80
+ setCameraError('An unknown error occurred. Please check permissions and try again.');
81
+ }
82
+ setCaptureInProgress(false);
83
+ stopCamera();
84
+ }
85
+ }
86
+ function startFaceDetection() {
87
+ if (!modelsLoaded) {
88
+ console.error('Cannot start face detection: video element not ready or models not loaded');
89
+ return;
90
+ }
91
+ if (!faceCanvasRef.current) {
92
+ faceCanvasRef.current = faceapi.createCanvasFromMedia(videoRef.current);
93
+ const parentDiv = document.getElementById('parent');
94
+ faceCanvasRef.current.className = `absolute inset-0 m-auto h-${parentDiv?.clientHeight} w-${parentDiv?.clientWidth} md:aspect-video object-cover md:object-contain`;
95
+ faceCanvasRef.current.style.width = `${videoRef.current?.clientWidth}px`;
96
+ faceCanvasRef.current.style.height = `${videoRef.current?.clientHeight}px`;
97
+ }
98
+ const displaySize = {
99
+ width: videoRef.current?.clientWidth || 643,
100
+ height: videoRef.current?.clientHeight || 333,
101
+ };
102
+ // Clear any existing interval
103
+ if (detectionIntervalRef.current) {
104
+ clearInterval(detectionIntervalRef.current);
105
+ }
106
+ faceapi.matchDimensions(faceCanvasRef.current, displaySize);
107
+ let countdownInterval = null;
108
+ detectionIntervalRef.current = window.setInterval(async () => {
109
+ if (!videoRef.current || !faceCanvasRef.current) {
110
+ console.error('Video or canvas element is not ready');
111
+ return;
112
+ }
113
+ try {
114
+ const detection = await faceapi
115
+ .detectSingleFace(videoRef.current, new faceapi.TinyFaceDetectorOptions())
116
+ .withFaceLandmarks();
117
+ if (detection) {
118
+ const resizedDetection = faceapi.resizeResults(detection, displaySize);
119
+ const frame_height = resizedDetection.detection.box.height;
120
+ const frame_width = resizedDetection.detection.box.width;
121
+ const frame_x = resizedDetection.detection.box.x;
122
+ const frame_y = resizedDetection.detection.box.y;
123
+ const faceCenterX = frame_x + frame_width / 2;
124
+ const faceCenterY = frame_y + frame_height / 2;
125
+ const screenCenterX = displaySize.width / 2;
126
+ const screenCenterY = displaySize.height / 2;
127
+ const centerThresholdX = displaySize.width * 0.15;
128
+ const centerThresholdY = displaySize.height * 0.15;
129
+ const isFaceCentered = Math.abs(faceCenterX - screenCenterX) <= centerThresholdX &&
130
+ Math.abs(faceCenterY - screenCenterY) <= centerThresholdY;
131
+ setIsFaceCentered(isFaceCentered);
132
+ const faceDetectionConfidence = detection.detection.score * 100;
133
+ // const context = faceCanvasRef.current.getContext('2d');
134
+ // if (context) {
135
+ // context.clearRect(
136
+ // 0,
137
+ // 0,
138
+ // faceCanvasRef.current.width,
139
+ // faceCanvasRef.current.height,
140
+ // );
141
+ // faceapi.draw.drawDetections(
142
+ // faceCanvasRef.current,
143
+ // resizedDetection,
144
+ // );
145
+ // faceapi.draw.drawFaceLandmarks(
146
+ // faceCanvasRef.current,
147
+ // resizedDetection,
148
+ // );
149
+ // }
150
+ //adjust the faceDetectionConfidence if need
151
+ if (isFaceCentered && faceDetectionConfidence >= 65) {
152
+ if (!countdownInterval) {
153
+ setIsCapturing(true);
154
+ countdownInterval = setInterval(() => {
155
+ setCountdown((prev) => {
156
+ if (prev === 1) {
157
+ clearInterval(countdownInterval);
158
+ countdownInterval = null;
159
+ captureImage();
160
+ return 3;
161
+ }
162
+ return prev - 1;
163
+ });
164
+ }, 1000);
165
+ }
166
+ }
167
+ else {
168
+ if (countdownInterval) {
169
+ clearInterval(countdownInterval);
170
+ countdownInterval = null;
171
+ setCountdown(3);
172
+ setIsCapturing(false);
173
+ }
174
+ }
175
+ }
176
+ }
177
+ catch (error) {
178
+ console.error('Error during face detection:', error);
179
+ setCameraError('An error occurred while detecting your face. Please try again.');
180
+ }
181
+ }, 100);
182
+ }
183
+ function stopCamera() {
184
+ setCaptureInProgress(false);
185
+ if (detectionIntervalRef.current) {
186
+ clearInterval(detectionIntervalRef.current);
187
+ detectionIntervalRef.current = null;
188
+ }
189
+ if (countdownTimerRef.current) {
190
+ clearInterval(countdownTimerRef.current);
191
+ countdownTimerRef.current = null;
192
+ }
193
+ if (videoStream) {
194
+ videoStream.getTracks().forEach((track) => track.stop());
195
+ setVideoStream(null);
196
+ }
197
+ if (videoRef.current && videoRef.current.srcObject) {
198
+ const stream = videoRef.current.srcObject;
199
+ stream.getTracks().forEach((track) => {
200
+ track.stop();
201
+ });
202
+ videoRef.current.srcObject = null;
203
+ videoRef.current.pause();
204
+ videoRef.current.currentTime = 0;
205
+ videoRef.current.load();
206
+ }
207
+ setCountdown(3);
208
+ }
209
+ function captureImage() {
210
+ if (videoRef.current && faceCanvasRef.current) {
211
+ const canvas = document.createElement('canvas');
212
+ canvas.width = videoRef.current.videoWidth;
213
+ canvas.height = videoRef.current.videoHeight;
214
+ const context = canvas.getContext('2d');
215
+ if (context) {
216
+ context.drawImage(videoRef.current, 0, 0, canvas.width, canvas.height);
217
+ const imageData = canvas.toDataURL('image/png');
218
+ setSelectedImage(imageData);
219
+ stopCamera();
220
+ }
221
+ }
222
+ }
223
+ function retakePhoto() {
224
+ setSelectedImage(null);
225
+ setCaptureInProgress(true);
226
+ setCameraError(null);
227
+ if (faceCanvasRef.current) {
228
+ const canvas = faceCanvasRef.current.querySelector('canvas');
229
+ if (canvas) {
230
+ canvas.width = canvas.width;
231
+ }
232
+ faceCanvasRef.current.innerHTML = '';
233
+ }
234
+ if (videoRef.current) {
235
+ videoRef.current.play();
236
+ }
237
+ startCamera();
238
+ }
239
+ async function usePhoto() {
240
+ if (!selectedImage) {
241
+ console.error('No photo selected to use');
242
+ return;
243
+ }
244
+ const blob = dataURLtoBlob(selectedImage);
245
+ const img = new File([blob], 'image', { type: blob.type });
246
+ const resizedImage = (await resizeFile(img));
247
+ if (resizedImage) {
248
+ await mutate({
249
+ file: resizedImage,
250
+ }, {
251
+ onSuccess: (data) => {
252
+ kyc.setSelfieImageId(data);
253
+ kyc.setCapturing(null);
254
+ stopCamera();
255
+ },
256
+ });
257
+ }
258
+ }
259
+ function checkCameraPermission() {
260
+ const constraints = { video: true };
261
+ navigator.mediaDevices
262
+ .getUserMedia(constraints)
263
+ .then(() => {
264
+ setCameraError(null);
265
+ startCamera();
266
+ })
267
+ .catch(() => {
268
+ showPermissionInstructions();
269
+ });
270
+ }
271
+ useEffect(() => {
272
+ return () => {
273
+ if (detectionIntervalRef.current) {
274
+ clearInterval(detectionIntervalRef.current);
275
+ }
276
+ if (countdownTimerRef.current) {
277
+ clearInterval(countdownTimerRef.current);
278
+ }
279
+ };
280
+ }, []);
281
+ return (_jsxs("div", { className: "w-full p-4 lg:w-[640px] lg:px-12 lg:py-4xl", children: [_jsxs("button", { type: "button", className: "flex items-center gap-lg lg:absolute lg:right-5 lg:top-5 lg:p-md", onClick: () => {
282
+ stopCamera();
283
+ kyc.setCapturing(null);
284
+ }, children: [_jsx(XIcon, { className: "text-text-senary-300 hidden size-5 lg:block" }), _jsx(ArrowLeftIcon, { className: "text-text-senary-300 size-5 lg:hidden" }), _jsx("span", { className: "text-lg font-semibold lg:hidden", children: "Back" })] }), _jsx(Dialog.Title, { className: "mt-6 text-center text-lg font-semibold lg:mt-0", children: "Take a Selfie Holding Your ID" }), _jsx(Dialog.Description, { className: "text-text-tertiary-600 mx-auto mt-sm max-w-[19rem] text-center text-sm lg:max-w-full", children: "Make sure your face and ID are clearly visible, with no glare or blur." }), _jsx("div", { id: "parent", className: "border-border-disabled mt-6 aspect-video rounded-xl border bg-black lg:mt-8", children: ['NotAllowedError', 'NotReadableError', 'NotFoundError'].includes(cameraError) ? (_jsx(NoCameraError, { onRetry: checkCameraPermission, title: "Camera Access Required", description: "We were unable to detect a camera on your device. Please ensure it is properly connected and accessible to this application." })) : captureInProgress && !cameraError ? (_jsxs("div", { className: "relative flex h-fit w-full flex-col items-center justify-center", children: [_jsx("video", { ref: videoRef, autoPlay: true, muted: true, playsInline: true, className: "h-[60vh] w-full rounded-lg object-cover md:aspect-video md:h-[333px]", width: "100%", height: "100%" }), _jsx("canvas", { ref: faceCanvasRef, className: "absolute inset-0 h-[60vh] w-full object-cover md:aspect-video md:h-[333px] md:object-contain", width: "100%", height: "100%" }), isCapturing && (_jsx("span", { className: "absolute inset-x-0 bottom-8 flex items-center justify-center text-5xl font-bold text-[#713B12CC] md:bottom-4", children: countdown })), !isFaceCentered && (_jsx("span", { className: "absolute inset-x-0 bottom-12 mx-auto w-1/2 text-center text-xs text-white md:bottom-3", children: "Please center your face in the camera view. Make sure your ID is clearly visible next to your face." })), _jsx(PersonOverlayDesktop, { isFaceCentered: isFaceCentered, width: videoRef.current?.clientWidth || 543, height: videoRef.current?.clientHeight || 333 })] })) : (selectedImage && (_jsx("img", { src: selectedImage, alt: "Captured Photo", className: "h-full w-full rounded-lg object-cover md:aspect-video md:h-[333px]" }))) }), selectedImage && (_jsxs("div", { className: "flex flex-col items-center justify-center gap-2 md:flex-row", children: [_jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: retakePhoto, type: "button", children: ["Rekate Photo", _jsx(Camera01Icon, { className: "size-5" })] }), _jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: usePhoto, type: "button", disabled: isPending, children: ["Use Photo", _jsx(Camera01Icon, { className: "size-5" })] })] })), !captureInProgress && !cameraError && (_jsxs(Button, { className: twMerge('mx-auto mt-6 px-xl lg:mt-8', selectedImage && 'hidden'), onClick: startCamera, disabled: !modelsLoaded, type: "button", children: ["Start Camera", _jsx(Camera01Icon, { className: "size-5" })] }))] }));
285
+ }
@@ -0,0 +1,5 @@
1
+ interface Props {
2
+ id: string;
3
+ }
4
+ declare function DisplayImage({ id }: Props): import("react/jsx-runtime").JSX.Element;
5
+ export default DisplayImage;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Image from 'next/image';
3
+ import { useFileQuery } from '../../client/hooks/useFileQuery.js';
4
+ function DisplayImage({ id }) {
5
+ const { data } = useFileQuery(id ?? '');
6
+ return (_jsx("div", { className: "border-border-primary bg-bg-primary min-h-[11.25rem]", children: data?.url && (_jsx(Image, { src: data.url, alt: "Uploaded", className: "w-full object-contain", width: 500, height: 500 })) }));
7
+ }
8
+ export default DisplayImage;
@@ -0,0 +1,10 @@
1
+ import type { CaptureSubject } from './useKYC';
2
+ interface FileUploadProps {
3
+ name: string;
4
+ value: string;
5
+ hasDescription?: boolean;
6
+ onChange?: (id: string) => void;
7
+ captureObject: CaptureSubject;
8
+ }
9
+ declare function FileUpload({ value, name, hasDescription, onChange, captureObject, }: FileUploadProps): import("react/jsx-runtime").JSX.Element;
10
+ export default FileUpload;
@@ -0,0 +1,72 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import Image from 'next/image';
4
+ import { useEffect, useState } from 'react';
5
+ import { twMerge } from 'tailwind-merge';
6
+ import invariant from 'tiny-invariant';
7
+ import { useUploadImageFileMutation } from '../../client/hooks/useUploadImageFileMutation.js';
8
+ import { getSession } from '../../client/services/getSession.js';
9
+ import { UploadCloud02Icon } from '../../icons/UploadCloud02Icon.js';
10
+ import { getFile } from '../../services/file.js';
11
+ import { Button } from '../../ui/Button/index.js';
12
+ import { createPoll } from '../../utils/createPoll.js';
13
+ import { useKYCContext } from './KYCContext.js';
14
+ import { validateFile } from './utils.js';
15
+ function FileUpload({ value, name, hasDescription, onChange, captureObject, }) {
16
+ const kyc = useKYCContext();
17
+ const { mutate, isPending } = useUploadImageFileMutation();
18
+ const [isLoading, setIsLoading] = useState(false);
19
+ const [uploadedImageUrl, setUploadedImageUrl] = useState(null);
20
+ async function pollImage(id) {
21
+ if (!id)
22
+ return;
23
+ setIsLoading(true);
24
+ const poll = createPoll(async () => {
25
+ const session = await getSession();
26
+ invariant(session.status === 'authenticated');
27
+ const file = await getFile(id, {
28
+ headers: {
29
+ Authorization: `Bearer ${session.token}`,
30
+ },
31
+ });
32
+ return file ?? null;
33
+ }, { until: (r) => !!r, interval: 1000, maxAttempt: 5 });
34
+ const image = await poll();
35
+ if (!image) {
36
+ console.error('Image not found or failed to load');
37
+ }
38
+ setUploadedImageUrl(image?.url ?? null);
39
+ setIsLoading(false);
40
+ }
41
+ useEffect(() => {
42
+ pollImage(value);
43
+ }, [value]);
44
+ if (isPending || isLoading) {
45
+ return (_jsx("div", { className: "border-border-primary bg-bg-primary flex min-h-[11.25rem] flex-col justify-center gap-lg rounded-xl border px-3xl py-xl", children: _jsx("div", { className: "flex items-center justify-center", children: _jsx("span", { className: "text-text-secondary-700", children: "Uploading..." }) }) }));
46
+ }
47
+ function handleFileChange(event) {
48
+ const file = event.target.files?.[0];
49
+ if (!file) {
50
+ console.error('No file selected');
51
+ return;
52
+ }
53
+ const error = validateFile(file);
54
+ if (error) {
55
+ console.error(error);
56
+ return;
57
+ }
58
+ mutate({ file }, {
59
+ onSuccess: (id) => {
60
+ onChange?.(id);
61
+ },
62
+ });
63
+ }
64
+ function handleUploadClick() {
65
+ const fileInput = document.getElementById(`file-upload-${name}`);
66
+ if (fileInput) {
67
+ fileInput.click();
68
+ }
69
+ }
70
+ return (_jsxs("div", { className: "border-border-primary bg-bg-primary flex min-h-[11.25rem] flex-col justify-center gap-lg rounded-xl border px-3xl py-xl", children: [uploadedImageUrl ? (_jsxs("div", { className: "border-border-primary bg-bg-primary min-h-[9.25rem]", children: [_jsx(Image, { src: uploadedImageUrl, alt: "Uploaded", className: "w-full object-contain", width: 350, height: 350, draggable: false }), _jsx(Button, { size: "xs", variant: "outline", className: twMerge('mx-auto mt-4 w-fit', value && 'hidden'), type: "button", onClick: handleUploadClick, children: "Reupload" })] })) : hasDescription ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "border-border-primary shadow-xs mx-auto flex size-8 items-center justify-center rounded-sm border", children: _jsx(UploadCloud02Icon, { className: "text-text-quinary size-4" }) }), _jsxs("p", { className: "text-text-tertiary-600 text-center text-sm", children: [_jsx("span", { className: "text-button-secondary-fg cursor-pointer font-semibold", onClick: handleUploadClick, children: "Click to upload" }), ' ', "or drag and drop", _jsx("br", {}), "PNG, JPG or JPEG (max. 10mb)", _jsx("br", {}), "or"] })] })) : null, _jsx("input", { type: "file", id: `file-upload-${name}`, name: name, onChange: handleFileChange, accept: "image/png, image/jpg, image/jpeg", className: "hidden" }), _jsx(Button, { size: "xs", variant: "outline", className: "mx-auto w-fit", onClick: () => kyc.setCapturing(captureObject), disabled: isPending, type: "button", children: value ? 'Retake Photo' : 'Take a Photo' })] }));
71
+ }
72
+ export default FileUpload;
@@ -1,3 +1,4 @@
1
- import type { KYCProps } from './KYC.lazy';
2
- export declare function KYC(props: KYCProps): import("react/jsx-runtime").JSX.Element | undefined;
3
- export type { KYCProps };
1
+ import type { KYCDefaultProps } from './KYCDefault';
2
+ import type { KYCSumsubProps } from './KYCSumsub';
3
+ export type KYCProps = KYCDefaultProps | KYCSumsubProps;
4
+ export declare function KYC(props: KYCProps): import("react/jsx-runtime").JSX.Element | null;
@@ -3,12 +3,19 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import dynamic from 'next/dynamic';
4
4
  import { useShallow } from 'zustand/shallow';
5
5
  import { useGlobalStore } from '../../client/hooks/useGlobalStore.js';
6
- const Component = dynamic(() => import('./KYC.lazy.js').then((m) => m.KYC), {
6
+ const KYCDefault = dynamic(() => import('./KYCDefault/index.js').then((m) => m.KYCDefault), {
7
+ ssr: false,
8
+ loading: () => null,
9
+ });
10
+ const KYCSumsub = dynamic(() => import('./KYCSumsub.js').then((m) => m.KYCSumsub), {
7
11
  ssr: false,
8
12
  loading: () => null,
9
13
  });
10
14
  export function KYC(props) {
11
15
  const touched = useGlobalStore(useShallow((ctx) => ctx.kyc['~touched']));
12
- if (touched)
13
- return _jsx(Component, { ...props });
16
+ if (!touched)
17
+ return null;
18
+ if (props.provider === 'sumsub')
19
+ return _jsx(KYCSumsub, { ...props });
20
+ return _jsx(KYCDefault, { ...props });
14
21
  }
@@ -0,0 +1 @@
1
+ export declare function BasicInformation(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { zodResolver } from '@hookform/resolvers/zod';
3
+ import { differenceInYears, format, isSameDay, isValid, parse } from 'date-fns';
4
+ import { isNil, omitBy, size } from 'lodash-es';
5
+ import { useEffect } from 'react';
6
+ import { useForm } from 'react-hook-form';
7
+ import invariant from 'tiny-invariant';
8
+ import { z } from 'zod';
9
+ import { useAccountQuery } from '../../../client/hooks/useAccountQuery.js';
10
+ import { useUpdateAccountMutation } from '../../../client/hooks/useUpdateAccountMutation.js';
11
+ import { toaster } from '../../../client/utils/toaster.js';
12
+ import { Button } from '../../../ui/Button/index.js';
13
+ import { Dialog } from '../../../ui/Dialog/index.js';
14
+ import { Field } from '../../../ui/Field/index.js';
15
+ import { useKYCDefaultContext } from './KYCDefaultContext.js';
16
+ const definition = z.object({
17
+ realName: z
18
+ .string()
19
+ .min(3, 'Name must be 3 or more characters')
20
+ .max(50, 'Name must not be more than 50 characters')
21
+ .regex(/^[a-z0-9 ]+$/gi, 'Name must not contain special characters')
22
+ .trim(),
23
+ birthDay: z
24
+ .string()
25
+ .min(1, 'Date of birth is required')
26
+ .superRefine((value, ctx) => {
27
+ const dob = parse(value, 'yyyy-MM-dd', new Date());
28
+ if (!isValid(dob)) {
29
+ return ctx.addIssue({
30
+ code: z.ZodIssueCode.invalid_date,
31
+ });
32
+ }
33
+ const now = new Date();
34
+ const age = differenceInYears(now, dob);
35
+ if (age < 21) {
36
+ return ctx.addIssue({
37
+ code: z.ZodIssueCode.custom,
38
+ message: 'You must be at least 21 years old',
39
+ });
40
+ }
41
+ }),
42
+ branchCode: z.string().min(4).max(10).optional().or(z.literal('')),
43
+ });
44
+ export function BasicInformation() {
45
+ const kyc = useKYCDefaultContext();
46
+ const form = useForm({
47
+ resolver: zodResolver(definition),
48
+ mode: 'all',
49
+ defaultValues: {
50
+ birthDay: '',
51
+ branchCode: '',
52
+ realName: '',
53
+ },
54
+ });
55
+ const accountQuery = useAccountQuery();
56
+ const account = accountQuery.data;
57
+ const stepCompleted = account != null && account.realName != null && account.birthDay != null;
58
+ useEffect(() => {
59
+ if (stepCompleted)
60
+ kyc.setStep(2);
61
+ }, [stepCompleted, kyc]);
62
+ useEffect(() => {
63
+ if (account) {
64
+ form.reset({
65
+ realName: account.realName ?? '',
66
+ birthDay: account.birthDay
67
+ ? format(account.birthDay, 'yyyy-MM-dd')
68
+ : '',
69
+ });
70
+ }
71
+ }, [account, form]);
72
+ const updateAccountMutation = useUpdateAccountMutation({
73
+ onError(error) {
74
+ toaster.error({
75
+ title: 'Error',
76
+ description: error.message,
77
+ });
78
+ },
79
+ onSuccess() {
80
+ kyc.setStep(2);
81
+ toaster.success({
82
+ title: 'Success',
83
+ description: 'Basic information has been set successfully.',
84
+ });
85
+ },
86
+ });
87
+ return (_jsxs("div", { children: [_jsx(Dialog.Title, { className: "text-center font-semibold text-lg", children: "Basic Information" }), _jsx(Dialog.Description, { className: "mt-xs text-center text-sm text-text-secondary-700", children: "Enter your basic details for identification and communication." }), _jsxs("form", { className: "mt-3", onSubmit: form.handleSubmit((data) => {
88
+ invariant(account);
89
+ const input = omitBy({
90
+ realName: account.realName === data.realName ? undefined : data.realName,
91
+ birthDay: account.birthDay && isSameDay(data.birthDay, account.birthDay)
92
+ ? undefined
93
+ : format(data.birthDay, 'yyyy-MM-dd'),
94
+ }, isNil);
95
+ if (size(input) === 0)
96
+ return kyc.setStep(2);
97
+ updateAccountMutation.mutate(input);
98
+ }), children: [_jsxs(Field.Root, { invalid: !!form.formState.errors.realName, readOnly: !!accountQuery.data?.realName, children: [_jsx(Field.Label, { children: "Real Name" }), _jsx(Field.Input, { placeholder: "Enter your real name", ...form.register('realName') }), _jsx(Field.ErrorText, { children: form.formState.errors.realName?.message })] }), _jsxs(Field.Root, { className: "mt-3", invalid: !!form.formState.errors.branchCode, readOnly: !!accountQuery.data?.birthDay, children: [_jsx(Field.Label, { children: "Date of Birth" }), _jsx(Field.Input, { type: "date", ...form.register('birthDay') }), _jsx(Field.ErrorText, { children: form.formState.errors.birthDay?.message })] }), _jsx(Button, { type: "submit", className: "mt-8", disabled: accountQuery.isLoading ||
99
+ updateAccountMutation.isPending ||
100
+ stepCompleted, children: "Continue" })] })] }));
101
+ }
@@ -0,0 +1 @@
1
+ export declare function IdentityVerification(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,120 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { zodResolver } from '@hookform/resolvers/zod';
4
+ import { useEffect } from 'react';
5
+ import { Controller, useForm } from 'react-hook-form';
6
+ import { z } from 'zod';
7
+ import { useShallow } from 'zustand/shallow';
8
+ import { useCreateMemberVerificationMutation } from '../../../client/hooks/useCreateMemberVerificationMutation.js';
9
+ import { useGlobalStore } from '../../../client/hooks/useGlobalStore.js';
10
+ import { useMemberVerificationQuery } from '../../../client/hooks/useMemberVerificationQuery.js';
11
+ import { useUpdateMemberVerificationMutation } from '../../../client/hooks/useUpdateMemberVerificationMutation.js';
12
+ import { toaster } from '../../../client/utils/toaster.js';
13
+ import { Button } from '../../../ui/Button/index.js';
14
+ import { Dialog } from '../../../ui/Dialog/index.js';
15
+ import { Field } from '../../../ui/Field/index.js';
16
+ import { getQueryClient } from '../../../utils/getQueryClient.js';
17
+ import { getMemberVerificationQueryKey } from '../../../utils/queryKeys.js';
18
+ import { IdFrontImageField } from '../../shared/IdFrontImageField/index.js';
19
+ import { SelfieImageField } from '../../shared/SelfieImageField/index.js';
20
+ import { useKYCDefaultContext } from './KYCDefaultContext.js';
21
+ const formSchema = z.object({
22
+ selfieImage: z.string().min(1, 'Selfie image is required.'),
23
+ idFrontImage: z.string().min(1, 'Front image of ID is required.'),
24
+ });
25
+ export function IdentityVerification() {
26
+ const kyc = useKYCDefaultContext();
27
+ const { mutate: createMemberVerification, isPending: createPending } = useCreateMemberVerificationMutation({
28
+ onSuccess: () => {
29
+ toaster.success({
30
+ title: 'ID Front Image & Selfie Image uploaded successfully',
31
+ });
32
+ },
33
+ onError: (error) => {
34
+ toaster.error({
35
+ title: 'Failed to upload ID Front Image & Selfie Image',
36
+ description: error.message,
37
+ });
38
+ },
39
+ });
40
+ const { mutate: updateMemberVerification, isPending: updatePending } = useUpdateMemberVerificationMutation({
41
+ onSuccess: () => {
42
+ const queryClient = getQueryClient();
43
+ toaster.success({
44
+ title: 'ID Front Image & Selfie Image updated successfully',
45
+ });
46
+ queryClient.setQueryData(getMemberVerificationQueryKey(), (prev) => {
47
+ if (!prev)
48
+ return prev;
49
+ return {
50
+ ...prev,
51
+ status: 'CREATED',
52
+ };
53
+ });
54
+ },
55
+ onError: (error) => {
56
+ toaster.error({
57
+ title: 'Failed to upload ID Front Image & Selfie Image',
58
+ description: error.message,
59
+ });
60
+ },
61
+ });
62
+ const memberVerification = useMemberVerificationQuery();
63
+ const memberId = memberVerification.data?.id;
64
+ const globalStore = useGlobalStore(useShallow((ctx) => ({
65
+ kyc: ctx.kyc,
66
+ })));
67
+ const form = useForm({
68
+ resolver: zodResolver(formSchema),
69
+ defaultValues: {
70
+ idFrontImage: '',
71
+ selfieImage: '',
72
+ },
73
+ });
74
+ function onSubmit(values) {
75
+ if (!memberId) {
76
+ createMemberVerification({
77
+ selfieImage: values.selfieImage,
78
+ idFrontImage: values.idFrontImage,
79
+ address: '',
80
+ nationality: '',
81
+ natureOfWork: '',
82
+ permanentAddress: '',
83
+ placeOfBirth: '',
84
+ sourceOfIncome: '',
85
+ });
86
+ kyc.setStep(3);
87
+ }
88
+ else {
89
+ updateMemberVerification({
90
+ id: memberId,
91
+ data: {
92
+ selfieImage: values.selfieImage,
93
+ idFrontImage: values.idFrontImage,
94
+ },
95
+ });
96
+ kyc.setStep(3);
97
+ }
98
+ }
99
+ useEffect(() => {
100
+ if (kyc.selfieImageId)
101
+ form.setValue('selfieImage', kyc.selfieImageId);
102
+ if (kyc.idFrontImageId)
103
+ form.setValue('idFrontImage', kyc.idFrontImageId);
104
+ }, [form, kyc.idFrontImageId, kyc.selfieImageId]);
105
+ return (_jsxs("div", { children: [_jsx(Dialog.Title, { className: "text-center font-semibold text-lg", children: "Verify your identity" }), _jsx(Dialog.Description, { className: "mt-xs text-center text-sm text-text-secondary-700", children: "Verify your details to confirm your identity and secure your access." }), _jsxs("div", { className: "mt-7 rounded-xl border border-border-primary bg-bg-primary p-lg text-text-placeholder text-xs leading-tight", children: [_jsx("h3", { className: "font-semibold", children: "Instructions" }), _jsxs("ol", { className: "mt-2 list-inside list-decimal", children: [_jsx("li", { children: "Upload a full photo of your ID." }), _jsx("li", { children: "Please ensure that all details in the uploaded image are legible." }), _jsx("li", { children: "Please ensure that the ID uploaded is within the validity period." })] })] }), _jsxs("form", { className: "mt-xl", onSubmit: form.handleSubmit(onSubmit), children: [_jsx(Controller, { control: form.control, name: "idFrontImage", render: (o) => (_jsxs(Field.Root, { invalid: o.fieldState.invalid, children: [_jsx(Field.Label, { children: "Front of your ID" }), _jsx(IdFrontImageField, { value: o.field.value, onChange: o.field.onChange, onError: (error) => {
106
+ form.setValue('idFrontImage', '');
107
+ form.setError('idFrontImage', {
108
+ type: 'validate',
109
+ message: error.message,
110
+ });
111
+ } }), _jsx(Field.ErrorText, { children: o.fieldState.error?.message })] })) }), _jsx(Controller, { control: form.control, name: "selfieImage", render: (o) => (_jsxs(Field.Root, { invalid: o.fieldState.invalid, className: "mt-3", children: [_jsx(Field.Label, { children: "Selfie holding your ID" }), _jsx(SelfieImageField, { value: o.field.value, onChange: o.field.onChange, onError: (error) => {
112
+ form.setValue('selfieImage', '');
113
+ form.setError('selfieImage', {
114
+ type: 'validate',
115
+ message: error.message,
116
+ });
117
+ } }), _jsx(Field.ErrorText, { children: o.fieldState.error?.message })] })) }), _jsx(Button, { type: "submit", className: "mt-6", disabled: createPending || updatePending, children: "Continue" }), _jsx(Button, { variant: "outline", colorScheme: "gray", className: "mt-lg", type: "button", onClick: () => {
118
+ globalStore.kyc.setOpen(false);
119
+ }, children: "Skip for now" })] })] }));
120
+ }
@@ -0,0 +1 @@
1
+ export declare function Indicator(): import("react/jsx-runtime").JSX.Element;