@opexa/portal-components 0.0.612 → 0.0.613
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/components/DigitainLauncher/Loading.d.ts +1 -0
- package/dist/components/DigitainLauncher/Loading.js +5 -0
- package/dist/components/Disclaimer/ResponsibleGaming.d.ts +10 -0
- package/dist/components/Disclaimer/ResponsibleGaming.js +13 -0
- package/dist/components/Disclaimer/TermsOfUse.d.ts +11 -0
- package/dist/components/Disclaimer/TermsOfUse.js +13 -0
- package/dist/components/FeatureFlag/FeatureFlag.d.ts +1 -0
- package/dist/components/FeatureFlag/FeatureFlag.js +29 -0
- package/dist/components/FeatureFlag/index.d.ts +1 -0
- package/dist/components/FeatureFlag/index.js +1 -0
- package/dist/components/Jackpots/Jackpots.module.css +184 -184
- package/dist/components/Jackpots/JackpotsCarousel/JackpotsCarouselItem.module.css +184 -0
- package/dist/components/Jackpots/JackpotsList/JackpotsListItem.module.css +184 -0
- package/dist/components/KYC/AutoOpen.d.ts +1 -0
- package/dist/components/KYC/AutoOpen.js +40 -0
- package/dist/components/KYC/BasicInformation.d.ts +1 -0
- package/dist/components/KYC/BasicInformation.js +101 -0
- package/dist/components/KYC/CaptureIdDocument.d.ts +1 -0
- package/dist/components/KYC/CaptureIdDocument.js +219 -0
- package/dist/components/KYC/CaptureSelfie.d.ts +1 -0
- package/dist/components/KYC/CaptureSelfie.js +285 -0
- package/dist/components/KYC/DisplayImage.d.ts +5 -0
- package/dist/components/KYC/DisplayImage.js +8 -0
- package/dist/components/KYC/FileUpload.d.ts +10 -0
- package/dist/components/KYC/FileUpload.js +72 -0
- package/dist/components/KYC/IdentityVerification.d.ts +1 -0
- package/dist/components/KYC/IdentityVerification.js +120 -0
- package/dist/components/KYC/Indicator.d.ts +1 -0
- package/dist/components/KYC/Indicator.js +8 -0
- package/dist/components/KYC/KYC.lazy.d.ts +6 -0
- package/dist/components/KYC/KYC.lazy.js +45 -0
- package/dist/components/KYC/KYCContext.d.ts +6 -0
- package/dist/components/KYC/KYCContext.js +2 -0
- package/dist/components/KYC/KYCDefault/BasicInformation.d.ts +1 -0
- package/dist/components/KYC/KYCDefault/BasicInformation.js +101 -0
- package/dist/components/KYC/KYCDefault/KYCVerificationStatus.lazy.js +2 -2
- package/dist/components/KYC/KYCReminder.lazy.js +1 -1
- package/dist/components/KYC/KYCVerificationStatus.lazy.js +2 -2
- package/dist/components/KYC/NoCameraError.d.ts +7 -0
- package/dist/components/KYC/NoCameraError.js +6 -0
- package/dist/components/KYC/PersonOverlayDesktop.d.ts +7 -0
- package/dist/components/KYC/PersonOverlayDesktop.js +9 -0
- package/dist/components/KYC/PersonalInformation.d.ts +1 -0
- package/dist/components/KYC/PersonalInformation.js +122 -0
- package/dist/components/KYC/backup/Header.d.ts +1 -0
- package/dist/components/KYC/backup/Header.js +8 -0
- package/dist/components/KYC/backup/Indicator.d.ts +1 -0
- package/dist/components/KYC/backup/Indicator.js +9 -0
- package/dist/components/KYC/backup/KYC.d.ts +1 -0
- package/dist/components/KYC/backup/KYC.js +14 -0
- package/dist/components/KYC/backup/KYC.lazy.d.ts +1 -0
- package/dist/components/KYC/backup/KYC.lazy.js +26 -0
- package/dist/components/KYC/backup/KYCContext.d.ts +6 -0
- package/dist/components/KYC/backup/KYCContext.js +2 -0
- package/dist/components/KYC/backup/Step1.d.ts +1 -0
- package/dist/components/KYC/backup/Step1.js +13 -0
- package/dist/components/KYC/backup/Step2.d.ts +1 -0
- package/dist/components/KYC/backup/Step2.js +13 -0
- package/dist/components/KYC/backup/Step3.d.ts +1 -0
- package/dist/components/KYC/backup/Step3.js +13 -0
- package/dist/components/KYC/backup/Step4.d.ts +1 -0
- package/dist/components/KYC/backup/Step4.js +7 -0
- package/dist/components/KYC/backup/useKYC.d.ts +10 -0
- package/dist/components/KYC/backup/useKYC.js +8 -0
- package/dist/components/KYC/loadModels.d.ts +1 -0
- package/dist/components/KYC/loadModels.js +9 -0
- package/dist/components/KYC/useKYC.d.ts +25 -0
- package/dist/components/KYC/useKYC.js +38 -0
- package/dist/components/KYC/utils.d.ts +9 -0
- package/dist/components/KYC/utils.js +79 -0
- package/dist/components/KYCNotRequired/KYCNotRequired.d.ts +0 -0
- package/dist/components/KYCNotRequired/KYCNotRequired.js +1 -0
- package/dist/components/Messages/Message.d.ts +1 -0
- package/dist/components/Messages/Message.js +35 -0
- package/dist/components/Messages/MessageContext.d.ts +6 -0
- package/dist/components/Messages/MessageContext.js +2 -0
- package/dist/components/Messages/MessagePopup.d.ts +1 -0
- package/dist/components/Messages/MessagePopup.js +20 -0
- package/dist/components/Messages/MessageTrigger.d.ts +8 -0
- package/dist/components/Messages/MessageTrigger.js +19 -0
- package/dist/components/PortalProvider/CXDTokenObserver.d.ts +1 -0
- package/dist/components/PortalProvider/CXDTokenObserver.js +30 -0
- package/dist/components/PortalProvider/LinkGoogleAccountObserver.d.ts +1 -0
- package/dist/components/PortalProvider/LinkGoogleAccountObserver.js +29 -0
- package/dist/components/Quests/CountdownTimer.d.ts +15 -0
- package/dist/components/Quests/CountdownTimer.js +33 -0
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuest.d.ts +4 -0
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuest.js +78 -0
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuestModal.d.ts +8 -0
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuestModal.js +9 -0
- package/dist/components/Quests/MultiWageringQuest.d.ts +1 -0
- package/dist/components/Quests/MultiWageringQuest.js +111 -0
- package/dist/components/Quests/OnboardingQuest/OnboardingQuest.d.ts +4 -0
- package/dist/components/Quests/OnboardingQuest/OnboardingQuest.js +4 -0
- package/dist/components/Quests/WageringQuest/WageringQuest.d.ts +4 -0
- package/dist/components/Quests/WageringQuest/WageringQuest.js +20 -0
- package/dist/components/Quests/WageringQuest/WageringQuestModal.d.ts +9 -0
- package/dist/components/Quests/WageringQuest/WageringQuestModal.js +9 -0
- package/dist/components/SessionWatcher/SessionWatcher.d.ts +1 -0
- package/dist/components/SessionWatcher/SessionWatcher.js +20 -0
- package/dist/components/SessionWatcher/index.d.ts +1 -0
- package/dist/components/SessionWatcher/index.js +1 -0
- package/dist/components/SignIn/utils.d.ts +8 -0
- package/dist/components/SignIn/utils.js +26 -0
- package/dist/components/SignUp/SignUp.lazy.d.ts +12 -0
- package/dist/components/SignUp/SignUp.lazy.js +18 -0
- package/dist/components/SignUp/SignUpContext.d.ts +6 -0
- package/dist/components/SignUp/SignUpContext.js +2 -0
- package/dist/components/SignUp/SignUpDefault/SignUp.lazy.d.ts +17 -0
- package/dist/components/SignUp/SignUpDefault/SignUp.lazy.js +18 -0
- package/dist/components/SignUp/SignUpDefault/SignUpContext.d.ts +6 -0
- package/dist/components/SignUp/SignUpDefault/SignUpContext.js +2 -0
- package/dist/components/SignUp/SignUpDefault/SignUpForm.d.ts +1 -0
- package/dist/components/SignUp/SignUpDefault/SignUpForm.js +310 -0
- package/dist/components/SignUp/SignUpForm.d.ts +1 -0
- package/dist/components/SignUp/SignUpForm.js +284 -0
- package/dist/components/SignUp/SignUpKYC/CaptureIdDocument.d.ts +1 -0
- package/dist/components/SignUp/SignUpKYC/CaptureIdDocument.js +198 -0
- package/dist/components/SignUp/SignUpKYC/CaptureSelfie.d.ts +1 -0
- package/dist/components/SignUp/SignUpKYC/CaptureSelfie.js +251 -0
- package/dist/components/SignUp/SignUpKYC/ImageUploader.d.ts +10 -0
- package/dist/components/SignUp/SignUpKYC/ImageUploader.js +42 -0
- package/dist/components/SignUp/SignUpKYC/PersonOverlayDesktop.d.ts +7 -0
- package/dist/components/SignUp/SignUpKYC/PersonOverlayDesktop.js +9 -0
- package/dist/components/SignUp/SignUpKYC/SignUpFormKYC.d.ts +1 -0
- package/dist/components/SignUp/SignUpKYC/SignUpFormKYC.js +464 -0
- package/dist/components/SignUp/SignUpKYC/useImageUploader.d.ts +11 -0
- package/dist/components/SignUp/SignUpKYC/useImageUploader.js +20 -0
- package/dist/components/SignUp/SignUpKYC/utils.d.ts +9 -0
- package/dist/components/SignUp/SignUpKYC/utils.js +79 -0
- package/dist/components/SignUp/SignUpPagcor/CaptureIdDocument.d.ts +1 -0
- package/dist/components/SignUp/SignUpPagcor/CaptureIdDocument.js +198 -0
- package/dist/components/SignUp/SignUpPagcor/CaptureSelfie.d.ts +1 -0
- package/dist/components/SignUp/SignUpPagcor/CaptureSelfie.js +251 -0
- package/dist/components/SignUp/SignUpPagcor/ImageUploader.d.ts +10 -0
- package/dist/components/SignUp/SignUpPagcor/ImageUploader.js +41 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpFormPagcor.d.ts +1 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpFormPagcor.js +429 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcor.lazy.d.ts +13 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcor.lazy.js +26 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcorContext.d.ts +7 -0
- package/dist/components/SignUp/SignUpPagcor/SignUpPagcorContext.js +2 -0
- package/dist/components/SignUp/SignUpPagcor/useImageUploader.d.ts +11 -0
- package/dist/components/SignUp/SignUpPagcor/useImageUploader.js +20 -0
- package/dist/components/Tournaments/TournamentsCarousel/TournamentsCarouselItem.module.css +184 -184
- package/dist/components/Tournaments/TournamentsList/TournamentItem.module.css +184 -184
- package/dist/components/shared/IdDocumentField.client.d.ts +25 -0
- package/dist/components/shared/IdDocumentField.client.js +204 -0
- package/dist/components/shared/IdDocumentField.d.ts +2 -0
- package/dist/components/shared/IdDocumentField.js +11 -0
- package/dist/components/shared/SelfieField.client.d.ts +20 -0
- package/dist/components/shared/SelfieField.client.js +327 -0
- package/dist/components/shared/SelfieField.d.ts +2 -0
- package/dist/components/shared/SelfieField.js +11 -0
- package/dist/constants/BranchCode.d.ts +4 -0
- package/dist/constants/BranchCode.js +42 -0
- package/dist/constants/Branches.d.ts +2 -0
- package/dist/constants/Branches.js +42 -0
- package/dist/handlers/postTransformIdFrontImage.d.ts +3 -0
- package/dist/handlers/postTransformIdFrontImage.js +67 -0
- package/dist/handlers/postTransformSelfieImage.d.ts +3 -0
- package/dist/handlers/postTransformSelfieImage.js +71 -0
- package/dist/handlers.d.ts +43 -0
- package/dist/handlers.js +297 -0
- package/dist/icons/BellRingIcon.d.ts +2 -0
- package/dist/icons/BellRingIcon.js +4 -0
- package/dist/images/responsible-gaming-yellow.png +0 -0
- package/dist/services/queries.js +2758 -2758
- package/dist/services/trigger.d.ts +2 -2
- package/dist/services/trigger.js +1 -1
- package/dist/styles/theme.css +762 -762
- package/dist/third-parties/FacebookPixel/FacebookPixel.d.ts +4 -0
- package/dist/third-parties/FacebookPixel/FacebookPixel.js +4 -0
- package/dist/third-parties/FacebookPixel/api.d.ts +0 -0
- package/dist/third-parties/FacebookPixel/api.js +1 -0
- package/dist/third-parties/FacebookPixel/index.d.ts +1 -0
- package/dist/third-parties/FacebookPixel/index.js +1 -0
- package/dist/third-parties/GoogleRecaptcha/GoogleRecaptcha.d.ts +4 -0
- package/dist/third-parties/GoogleRecaptcha/GoogleRecaptcha.js +4 -0
- package/dist/third-parties/GoogleRecaptcha/api.d.ts +0 -0
- package/dist/third-parties/GoogleRecaptcha/api.js +1 -0
- package/dist/third-parties/GoogleRecaptcha/index.d.ts +1 -0
- package/dist/third-parties/GoogleRecaptcha/index.js +1 -0
- package/dist/third-parties/index.d.ts +2 -0
- package/dist/third-parties/index.js +2 -0
- package/dist/ui/AlertDialog/AlertDialog.d.ts +121 -121
- package/dist/ui/AlertDialog/alertDialog.recipe.d.ts +11 -11
- package/dist/ui/Avatar/Avatar.d.ts +9 -9
- package/dist/ui/Avatar/avatar.recipe.d.ts +3 -3
- package/dist/ui/Badge/Badge.d.ts +12 -12
- package/dist/ui/Badge/badge.anatomy.d.ts +1 -1
- package/dist/ui/Badge/badge.recipe.d.ts +3 -3
- package/dist/ui/Carousel/Carousel.d.ts +45 -45
- package/dist/ui/Carousel/carousel.recipe.d.ts +5 -5
- package/dist/ui/Checkbox/Checkbox.d.ts +23 -23
- package/dist/ui/Checkbox/checkbox.recipe.d.ts +3 -3
- package/dist/ui/Clipboard/Clipboard.d.ts +18 -18
- package/dist/ui/Clipboard/clipboard.recipe.d.ts +3 -3
- package/dist/ui/Combobox/Combobox.d.ts +42 -42
- package/dist/ui/Combobox/combobox.recipe.d.ts +3 -3
- package/dist/ui/DatePicker/DatePicker.d.ts +72 -72
- package/dist/ui/DatePicker/datePicker.recipe.d.ts +3 -3
- package/dist/ui/Dialog/Dialog.d.ts +33 -33
- package/dist/ui/Dialog/dialog.recipe.d.ts +3 -3
- package/dist/ui/Drawer/Drawer.d.ts +33 -33
- package/dist/ui/Drawer/drawer.recipe.d.ts +3 -3
- package/dist/ui/Field/Field.d.ts +21 -21
- package/dist/ui/Field/field.recipe.d.ts +3 -3
- package/dist/ui/Menu/Menu.d.ts +306 -306
- package/dist/ui/Menu/menu.recipe.d.ts +17 -17
- package/dist/ui/NumberInput/NumberInput.d.ts +24 -24
- package/dist/ui/NumberInput/numberInput.recipe.d.ts +3 -3
- package/dist/ui/PasswordInput/PasswordInput.d.ts +18 -18
- package/dist/ui/PasswordInput/passwordInput.recipe.d.ts +3 -3
- package/dist/ui/PinInput/PinInput.d.ts +12 -12
- package/dist/ui/PinInput/pinInput.recipe.d.ts +3 -3
- package/dist/ui/Popover/Popover.d.ts +55 -55
- package/dist/ui/Popover/popover.recipe.d.ts +5 -5
- package/dist/ui/Progress/Progress.d.ts +27 -27
- package/dist/ui/Progress/progress.recipe.d.ts +3 -3
- package/dist/ui/SegmentGroup/SegmentGroup.d.ts +18 -18
- package/dist/ui/SegmentGroup/segmentGroup.recipe.d.ts +3 -3
- package/dist/ui/Select/Select.d.ts +45 -45
- package/dist/ui/Select/select.recipe.d.ts +3 -3
- package/dist/ui/Table/Table.d.ts +21 -21
- package/dist/ui/Table/table.anatomy.d.ts +1 -1
- package/dist/ui/Table/table.recipe.d.ts +3 -3
- package/dist/ui/Tabs/Tabs.d.ts +15 -15
- package/dist/ui/Tabs/tabs.recipe.d.ts +3 -3
- package/dist/utils/dataUrlToBlob.d.ts +1 -0
- package/dist/utils/dataUrlToBlob.js +11 -0
- package/dist/utils/gamesAvailable3pmTo3am.d.ts +1 -0
- package/dist/utils/gamesAvailable3pmTo3am.js +1 -0
- package/dist/utils/getGameName.d.ts +1 -0
- package/dist/utils/getGameName.js +6 -0
- package/dist/utils/isBetween3amAnd3pm.d.ts +1 -0
- package/dist/utils/isBetween3amAnd3pm.js +5 -0
- package/dist/utils/resizeImageSize.d.ts +2 -0
- package/dist/utils/resizeImageSize.js +11 -0
- package/package.json +163 -163
|
@@ -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,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;
|
|
@@ -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 { useKYCContext } from './KYCContext.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 = useKYCContext();
|
|
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 text-lg font-semibold", children: "Verify your identity" }), _jsx(Dialog.Description, { className: "text-text-secondary-700 mt-xs text-center text-sm", children: "Verify your details to confirm your identity and secure your access." }), _jsxs("div", { className: "border-border-primary bg-bg-primary text-text-placeholder mt-7 rounded-xl border p-lg 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;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { noop } from 'lodash-es';
|
|
3
|
+
import { Progress } from '../../ui/Progress/index.js';
|
|
4
|
+
import { useKYCContext } from './KYCContext.js';
|
|
5
|
+
export function Indicator() {
|
|
6
|
+
const kyc = useKYCContext();
|
|
7
|
+
return (_jsxs("div", { className: "flex items-center justify-center gap-1.5 py-3", children: [_jsx(Progress.Root, { className: "w-10 shrink-0", value: kyc.step > 1 ? 100 : 0, onValueChange: noop, children: _jsx(Progress.Track, { className: "bg-bg-primary-hover", children: _jsx(Progress.Range, {}) }) }), _jsx(Progress.Root, { className: "w-10 shrink-0", value: kyc.step > 2 ? 100 : 0, onValueChange: noop, children: _jsx(Progress.Track, { className: "bg-bg-primary-hover", children: _jsx(Progress.Range, {}) }) }), _jsx(Progress.Root, { className: "w-10 shrink-0", value: kyc.step === 3 ? 100 : 0, onValueChange: noop, children: _jsx(Progress.Track, { className: "bg-bg-primary-hover", children: _jsx(Progress.Range, {}) }) })] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ImageProps } from 'next/image';
|
|
2
|
+
import { type KYCReminderProps } from './KYCReminder.lazy';
|
|
3
|
+
export interface KYCProps extends KYCReminderProps {
|
|
4
|
+
logo: ImageProps['src'];
|
|
5
|
+
}
|
|
6
|
+
export declare function KYC(props: KYCProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import Image from 'next/image';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { useShallow } from 'zustand/shallow';
|
|
5
|
+
import { useAccountQuery } from '../../client/hooks/useAccountQuery.js';
|
|
6
|
+
import { useGlobalStore } from '../../client/hooks/useGlobalStore.js';
|
|
7
|
+
import { useMemberVerificationQuery } from '../../client/hooks/useMemberVerificationQuery.js';
|
|
8
|
+
import { XIcon } from '../../icons/XIcon.js';
|
|
9
|
+
import { Dialog } from '../../ui/Dialog/index.js';
|
|
10
|
+
import { Portal } from '../../ui/Portal/index.js';
|
|
11
|
+
import { BasicInformation } from './BasicInformation.js';
|
|
12
|
+
import { IdentityVerification } from './IdentityVerification.js';
|
|
13
|
+
import { Indicator } from './Indicator.js';
|
|
14
|
+
import { KYCContext } from './KYCContext.js';
|
|
15
|
+
import { KYCReminder } from './KYCReminder.lazy.js';
|
|
16
|
+
import { PersonalInformation } from './PersonalInformation.js';
|
|
17
|
+
import { useKYC } from './useKYC.js';
|
|
18
|
+
export function KYC(props) {
|
|
19
|
+
const globalStore = useGlobalStore(useShallow((ctx) => ({ kyc: ctx.kyc })));
|
|
20
|
+
const kyc = useKYC();
|
|
21
|
+
const { data: account } = useAccountQuery();
|
|
22
|
+
const { data: verification } = useMemberVerificationQuery();
|
|
23
|
+
const isBasicInfoCompleted = account?.realName !== null && account?.birthDay !== null;
|
|
24
|
+
const isUploadCompleted = Boolean(verification?.idFrontImage) && Boolean(verification?.selfieImage);
|
|
25
|
+
const isVerified = Boolean(verification?.status === 'VERIFIED') ||
|
|
26
|
+
Boolean(verification?.status === 'PENDING') ||
|
|
27
|
+
Boolean(verification?.status === 'APPROVED');
|
|
28
|
+
const isRejected = Boolean(verification?.status === 'REJECTED');
|
|
29
|
+
const hasMissingData = !isBasicInfoCompleted || !isUploadCompleted || !isVerified;
|
|
30
|
+
const steps = !isBasicInfoCompleted
|
|
31
|
+
? 1
|
|
32
|
+
: !isUploadCompleted
|
|
33
|
+
? 2
|
|
34
|
+
: isRejected
|
|
35
|
+
? 2
|
|
36
|
+
: 3;
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (steps) {
|
|
39
|
+
kyc.setStep(steps);
|
|
40
|
+
}
|
|
41
|
+
}, [steps, kyc]);
|
|
42
|
+
return (_jsxs(_Fragment, { children: [_jsx(KYCContext, { value: kyc, children: _jsx(Dialog.Root, { open: globalStore.kyc.open && hasMissingData, onOpenChange: (details) => {
|
|
43
|
+
globalStore.kyc.setOpen(details.open);
|
|
44
|
+
}, lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, onExitComplete: kyc.reset, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, {}), _jsx(Dialog.Positioner, { children: _jsx(Dialog.Content, { className: "bg-bg-primary-alt lg:min-h-auto mx-auto min-h-full w-full overflow-y-auto lg:w-fit", children: _jsxs("div", { className: "flex h-dvh w-full flex-col overflow-y-auto p-3xl sm:h-fit sm:overflow-auto lg:w-[400px]", children: [_jsx(Dialog.CloseTrigger, { children: _jsx(XIcon, {}) }), _jsx(Image, { src: props.logo, alt: "", width: 200, height: 100, className: "mx-auto mb-5 block h-7.5 w-auto", draggable: false }), _jsx(Indicator, {}), kyc.step === 1 && _jsx(BasicInformation, {}), kyc.step === 2 && _jsx(IdentityVerification, {}), kyc.step === 3 && _jsx(PersonalInformation, {})] }) }) })] }) }) }), _jsx(KYCReminder, { ...props })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function BasicInformation(): import("react/jsx-runtime").JSX.Element;
|