@verified-network/verified-custody 0.2.0 → 0.2.2

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/src/pages/otp.tsx DELETED
@@ -1,410 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import { useVaultStore } from "../services/store";
3
- import {
4
- checkOTPVerification,
5
- errorToast,
6
- sendOTPVerification,
7
- } from "../utils/helpers";
8
- import PageSlider from "../components/slider";
9
- import { PrivacyOverlay } from "../components/overlays";
10
- import { imageAssets } from "../utils/constants";
11
-
12
- const OTPPage = (props: {
13
- setStep: (step: string) => void;
14
- setIsLoading: (isLoading: boolean) => void;
15
- setUserNumberFmt: (number: string) => void;
16
- setUserEmail: (email: string) => void;
17
- selectedCountry: { name: string; area: string; flag: string };
18
- userNumberFmt: string;
19
- userEmail: string;
20
- }) => {
21
- const [searchActive, setSearchActive] = useState(false);
22
- const [countdown, setCountdown] = useState(60);
23
- const [otpIncorrect, setOtpIncorrect] = useState(false);
24
-
25
- const { pk, vaultContract } = useVaultStore();
26
-
27
- useEffect(() => {
28
- if (countdown === 0) return;
29
-
30
- const reduceCountdown = setInterval(() => {
31
- setCountdown((prevCountdown) => prevCountdown - 1);
32
- }, 1000);
33
-
34
- return () => clearInterval(reduceCountdown);
35
- }, [countdown]);
36
-
37
- //todo: add key actions to input focus change
38
- const handlleInputFocus = (currentInput: any) => {
39
- if (currentInput.value.length > 0) {
40
- const nextInput = currentInput.nextElementSibling;
41
- if (nextInput) {
42
- nextInput.focus();
43
- }
44
- } else if (currentInput.value.length === 0) {
45
- currentInput.focus();
46
- }
47
- };
48
-
49
- const handleOtpPaste = (e: any) => {
50
- const pastedText = e.clipboardData.getData("text");
51
- const numbersFromText = pastedText?.replace(/\D/g, "");
52
- const allOptInputs: any = document.getElementsByClassName("otp-input");
53
- if (allOptInputs?.length === 4 && numbersFromText?.length > 0) {
54
- for (let i = 0; i < allOptInputs.length; i++) {
55
- if (numbersFromText[i]) {
56
- allOptInputs[i].value = numbersFromText[i];
57
- allOptInputs[i].focus();
58
- }
59
- }
60
- }
61
- };
62
-
63
- const handleOtpBackspace = (e: any) => {
64
- const previousInpput = e.target.previousElementSibling;
65
- if (previousInpput) {
66
- previousInpput.focus();
67
- }
68
- };
69
-
70
- const handleButtonDisplay = () => {
71
- const button: any = document.getElementById(
72
- "verified-custd-mdl-otp-button"
73
- );
74
- const otp1: any = document.getElementById("verified-custd-mdl-otp-input-1");
75
- const otp2: any = document.getElementById("verified-custd-mdl-otp-input-2");
76
- const otp3: any = document.getElementById("verified-custd-mdl-otp-input-3");
77
- const otp4: any = document.getElementById("verified-custd-mdl-otp-input-4");
78
- if (
79
- button &&
80
- otp1?.value.length > 0 &&
81
- otp2?.value.length > 0 &&
82
- otp3?.value.length > 0 &&
83
- otp4?.value.length > 0 &&
84
- !otpIncorrect
85
- ) {
86
- button.className = "verified-custd-mdl-startup-button-active";
87
- } else {
88
- button.className = "verified-custd-mdl-startup-button";
89
- }
90
- };
91
-
92
- const handleVerifyOtp = async () => {
93
- const vaultId =
94
- props.userEmail?.length > 0
95
- ? props.userEmail
96
- : `+${props.selectedCountry.area}${props.userNumberFmt?.replace(
97
- " ",
98
- ""
99
- )}`;
100
- const otp1: any = document.getElementById("verified-custd-mdl-otp-input-1");
101
- const otp2: any = document.getElementById("verified-custd-mdl-otp-input-2");
102
- const otp3: any = document.getElementById("verified-custd-mdl-otp-input-3");
103
- const otp4: any = document.getElementById("verified-custd-mdl-otp-input-4");
104
- if (
105
- otp1?.value?.length > 0 &&
106
- otp2?.value?.length > 0 &&
107
- otp3?.value?.length > 0 &&
108
- otp4?.value?.length > 0 &&
109
- vaultId &&
110
- pk &&
111
- vaultContract
112
- ) {
113
- props.setIsLoading(true);
114
- const fullOtp = otp1?.value + otp2?.value + otp3?.value + otp4?.value;
115
- await checkOTPVerification(vaultId, fullOtp).then((res) => {
116
- props.setIsLoading(false);
117
- if (res) {
118
- props.setStep("4");
119
- } else {
120
- setOtpIncorrect(true);
121
- }
122
- });
123
- }
124
- };
125
-
126
- const handleResendOtp = async () => {
127
- const vaultId =
128
- props.userEmail?.length > 0
129
- ? props.userEmail
130
- : `+${props.selectedCountry.area}${props.userNumberFmt?.replace(
131
- " ",
132
- ""
133
- )}`;
134
-
135
- const channel = props.userEmail?.length > 0 ? "email" : "sms";
136
-
137
- if (vaultId && channel) {
138
- props.setIsLoading(true);
139
- await sendOTPVerification(vaultId, channel).then((res) => {
140
- props.setIsLoading(false);
141
- if (res) {
142
- setCountdown(60);
143
- setOtpIncorrect(false);
144
- const otp1: any = document.getElementById(
145
- "verified-custd-mdl-otp-input-1"
146
- );
147
- const otp2: any = document.getElementById(
148
- "verified-custd-mdl-otp-input-2"
149
- );
150
- const otp3: any = document.getElementById(
151
- "verified-custd-mdl-otp-input-3"
152
- );
153
- const otp4: any = document.getElementById(
154
- "verified-custd-mdl-otp-input-4"
155
- );
156
- (otp1!.value = ""),
157
- (otp2!.value = ""),
158
- (otp3!.value = ""),
159
- (otp4!.value = "");
160
- } else {
161
- errorToast("Oops something went wrong", "Unexpected error");
162
- }
163
- });
164
- }
165
- };
166
-
167
- return (
168
- <div className="verified-custd-mdl-startup-language">
169
- <div className="verified-custd-mdl-startup-contact">
170
- <PageSlider sliderCount={[1, 2, 3]} currentSlider="0" />
171
- <div className="verified-custd-mdl-startup-contact-content">
172
- <p className="verified-custd-mdl-startup-contact-text">Enter OTP</p>
173
- <div className="verified-custd-mdl-startup-otp-text">
174
- <p className="verified-custd-mdl-startup-otp-header-text">
175
- Enter <span style={{ color: "#0C0C0E" }}>4-Digit OTP</span> (One
176
- Time Password) sent to your{" "}
177
- {props.userNumberFmt?.length > 0
178
- ? "phone number"
179
- : "email address"}
180
- </p>
181
- <div className="verified-custd-mdl-startup-otp-footer">
182
- <p className="verified-custd-mdl-startup-otp-footer-text">
183
- {props.userNumberFmt?.length > 0 && (
184
- <React.Fragment>
185
- <span>(+{props.selectedCountry?.area})</span>{" "}
186
- <span> {props.userNumberFmt?.split(" ")[0]}</span>{" "}
187
- <span> {props.userNumberFmt?.split(" ")[1]}</span>
188
- </React.Fragment>
189
- )}
190
- {props.userEmail?.length > 0 && <span>{props.userEmail}</span>}
191
- </p>
192
- <img
193
- onClick={() => {
194
- props.setUserNumberFmt("");
195
- props.setUserEmail("");
196
- props.setStep("2");
197
- }}
198
- src={imageAssets.editBlue}
199
- alt="edit-icon"
200
- className="verified-custd-mdl-st-otp-icon"
201
- />
202
- </div>
203
- </div>
204
- </div>
205
- <div className="verified-custd-mdl-otp-input-container">
206
- <div className="verified-custd-mdl-otp-input-group">
207
- <input
208
- onInputCapture={(e: any) => {
209
- e.target.value = e.target.value?.replace(/\D/g, "");
210
- setOtpIncorrect(false);
211
- }}
212
- onInput={(e) => {
213
- handlleInputFocus(e.target);
214
- handleButtonDisplay();
215
- }}
216
- onKeyDown={(e: any) => {
217
- if (e.key === "Backspace" && e.target.value === "") {
218
- handleOtpBackspace(e);
219
- }
220
- }}
221
- onPaste={(e) => {
222
- handleOtpPaste(e);
223
- }}
224
- className={
225
- otpIncorrect
226
- ? "verified-custd-mdl-otp-input-red"
227
- : "verified-custd-mdl-otp-input"
228
- }
229
- type="text"
230
- maxLength={1}
231
- id="verified-custd-mdl-otp-input-1"
232
- />
233
- <input
234
- onInputCapture={(e: any) => {
235
- e.target.value = e.target.value?.replace(/\D/g, "");
236
- setOtpIncorrect(false);
237
- }}
238
- onInput={(e) => {
239
- handlleInputFocus(e.target);
240
- handleButtonDisplay();
241
- }}
242
- onKeyDown={(e: any) => {
243
- if (e.key === "Backspace" && e.target.value === "") {
244
- handleOtpBackspace(e);
245
- }
246
- }}
247
- className={
248
- otpIncorrect
249
- ? "verified-custd-mdl-otp-input-red"
250
- : "verified-custd-mdl-otp-input"
251
- }
252
- type="text"
253
- maxLength={1}
254
- id="verified-custd-mdl-otp-input-2"
255
- />
256
- <input
257
- onInputCapture={(e: any) => {
258
- e.target.value = e.target.value?.replace(/\D/g, "");
259
- setOtpIncorrect(false);
260
- }}
261
- onInput={(e) => {
262
- handlleInputFocus(e.target);
263
- handleButtonDisplay();
264
- }}
265
- onKeyDown={(e: any) => {
266
- if (e.key === "Backspace" && e.target.value === "") {
267
- handleOtpBackspace(e);
268
- }
269
- }}
270
- className={
271
- otpIncorrect
272
- ? "verified-custd-mdl-otp-input-red"
273
- : "verified-custd-mdl-otp-input"
274
- }
275
- type="text"
276
- maxLength={1}
277
- id="verified-custd-mdl-otp-input-3"
278
- />
279
- <input
280
- onInputCapture={(e: any) => {
281
- e.target.value = e.target.value?.replace(/\D/g, "");
282
- setOtpIncorrect(false);
283
- }}
284
- onInput={(e) => {
285
- handlleInputFocus(e.target);
286
- handleButtonDisplay();
287
- }}
288
- onKeyDown={(e: any) => {
289
- if (e.key === "Backspace" && e.target.value === "") {
290
- handleOtpBackspace(e);
291
- }
292
- }}
293
- className={
294
- otpIncorrect
295
- ? "verified-custd-mdl-otp-input-red"
296
- : "verified-custd-mdl-otp-input"
297
- }
298
- type="text"
299
- maxLength={1}
300
- id="verified-custd-mdl-otp-input-4"
301
- />
302
- </div>
303
- <div className="verified-custd-mdl-otp-timer">
304
- {!otpIncorrect && countdown > 5 && (
305
- <p className="verified-custd-mdl-otp-timer-text">
306
- <span style={{ color: "#717286", fontWeight: 400 }}>00:</span>
307
- {countdown}
308
- </p>
309
- )}
310
- {!otpIncorrect && countdown <= 5 && countdown > 0 && (
311
- <p className="verified-custd-mdl-otp-timer-text-red">
312
- <span style={{ fontWeight: 400 }}>00:</span>
313
- {countdown}
314
- </p>
315
- )}
316
- {!otpIncorrect && countdown === 0 && (
317
- <p className="verified-custd-mdl-otp-resend-text">
318
- Didn't receive an OTP ?
319
- </p>
320
- )}
321
- {otpIncorrect && (
322
- <p className="verified-custd-mdl-otp-incorrect-text">
323
- Please enter the correct OTP
324
- </p>
325
- )}
326
- {!otpIncorrect && countdown > 0 && (
327
- <p className="verified-custd-mdl-otp-resend-text">Resend OTP</p>
328
- )}
329
- {!otpIncorrect && countdown === 0 && (
330
- <p
331
- onClick={async () => {
332
- //clear input content
333
- const inputs: any =
334
- document.getElementsByClassName("otp-input");
335
- if (inputs) {
336
- for (let i = 0; i < inputs.length; i++) {
337
- inputs[i].value = "";
338
- }
339
- }
340
-
341
- await handleResendOtp();
342
- }}
343
- className="verified-custd-mdl-otp-resend-text-active"
344
- >
345
- Resend OTP
346
- </p>
347
- )}
348
- {otpIncorrect && (
349
- <p
350
- onClick={async () => {
351
- //clear input content
352
- const inputs: any =
353
- document.getElementsByClassName("otp-input");
354
- if (inputs) {
355
- for (let i = 0; i < inputs.length; i++) {
356
- inputs[i].value = "";
357
- }
358
- }
359
-
360
- await handleResendOtp();
361
- }}
362
- className="verified-custd-mdl-otp-resend-text-active"
363
- >
364
- Resend OTP
365
- </p>
366
- )}
367
- </div>
368
- </div>
369
- </div>
370
-
371
- {!searchActive && <div style={{ height: "100px" }}></div>}
372
-
373
- <div className="verified-custd-mdl-startup-contact-footer">
374
- <div className="verified-custd-mdl-st-contact-footer-first-section">
375
- <button
376
- id="verified-custd-mdl-otp-button"
377
- onClick={async (e: any) => {
378
- if (
379
- e.target.className.includes(
380
- "verified-custd-mdl-startup-button"
381
- ) &&
382
- e.target.className !== "verified-custd-mdl-startup-button"
383
- ) {
384
- e.target.className = "verified-custd-mdl-startup-button-click";
385
- await handleVerifyOtp();
386
- } else {
387
- const buttonElement = document.getElementsByClassName(
388
- "verified-custd-mdl-startup-button-active"
389
- );
390
- if (buttonElement.length > 0) {
391
- buttonElement[0].className =
392
- "verified-custd-mdl-startup-button-click";
393
- await handleVerifyOtp();
394
- }
395
- }
396
- }}
397
- className="verified-custd-mdl-startup-button"
398
- >
399
- Proceed
400
- </button>
401
- <div className="verified-custd-mdl-st-contact-footer-second-section">
402
- <PrivacyOverlay />
403
- </div>
404
- </div>
405
- </div>
406
- </div>
407
- );
408
- };
409
-
410
- export default OTPPage;