@os1-platform/dispatch-mobile 3.0.4 → 3.1.1
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/android/build.gradle +38 -9
- package/android/gradle.properties +17 -2
- package/lib/commonjs/components/dispatch/DispatchExecNavigator.js.map +1 -1
- package/lib/commonjs/components/executiontasks/forms/widgets/DateTimeWidget.js.map +1 -1
- package/lib/commonjs/components/executiontasks/imageCapture/CaptureUtils.js +1 -1
- package/lib/commonjs/components/executiontasks/imageCapture/CaptureUtils.js.map +1 -1
- package/lib/commonjs/components/executiontasks/validateOTP/ValidateOTPET.js +467 -287
- package/lib/commonjs/components/executiontasks/validateOTP/ValidateOTPET.js.map +1 -1
- package/lib/commonjs/components/executiontasks/validateOTP/ValidateOTPSchema.js +14 -1
- package/lib/commonjs/components/executiontasks/validateOTP/ValidateOTPSchema.js.map +1 -1
- package/lib/commonjs/components/executiontasks/validateOTP/ValidateOtpStyles.js +270 -0
- package/lib/commonjs/components/executiontasks/validateOTP/ValidateOtpStyles.js.map +1 -0
- package/lib/commonjs/components/executiontasks/validateOTP/components/ContactListView.js +99 -0
- package/lib/commonjs/components/executiontasks/validateOTP/components/ContactListView.js.map +1 -0
- package/lib/commonjs/components/executiontasks/validateOTP/components/OTPView.js +195 -0
- package/lib/commonjs/components/executiontasks/validateOTP/components/OTPView.js.map +1 -0
- package/lib/commonjs/components/executiontasks/validateOTP/components/VerificationComplete.js +106 -0
- package/lib/commonjs/components/executiontasks/validateOTP/components/VerificationComplete.js.map +1 -0
- package/lib/commonjs/components/executiontasks/validateOTP/constants.js +12 -5
- package/lib/commonjs/components/executiontasks/validateOTP/constants.js.map +1 -1
- package/lib/commonjs/components/executiontasks/validateOTP/sub-components/ContactCard.js +68 -0
- package/lib/commonjs/components/executiontasks/validateOTP/sub-components/ContactCard.js.map +1 -0
- package/lib/commonjs/components/executiontasks/validateOTP/sub-components/OTPInput.js +12 -5
- package/lib/commonjs/components/executiontasks/validateOTP/sub-components/OTPInput.js.map +1 -1
- package/lib/commonjs/components/executiontasks/validateOTP/sub-components/ResendOTPButton.js +61 -0
- package/lib/commonjs/components/executiontasks/validateOTP/sub-components/ResendOTPButton.js.map +1 -0
- package/lib/commonjs/components/executiontasks/validateOTP/utils.js +235 -114
- package/lib/commonjs/components/executiontasks/validateOTP/utils.js.map +1 -1
- package/lib/commonjs/components/utils/Scale.js +22 -0
- package/lib/commonjs/components/utils/Scale.js.map +1 -0
- package/lib/commonjs/components/widgets/ConfirmCancelModal.js +47 -0
- package/lib/commonjs/components/widgets/ConfirmCancelModal.js.map +1 -0
- package/lib/commonjs/components/widgets/SnackBarCustom.js +36 -4
- package/lib/commonjs/components/widgets/SnackBarCustom.js.map +1 -1
- package/lib/commonjs/components/widgets/SplitTextInput.js +48 -18
- package/lib/commonjs/components/widgets/SplitTextInput.js.map +1 -1
- package/lib/commonjs/constants/apiConstants.js +4 -1
- package/lib/commonjs/constants/apiConstants.js.map +1 -1
- package/lib/commonjs/constants/constants.js +2 -1
- package/lib/commonjs/constants/constants.js.map +1 -1
- package/lib/commonjs/icons/icExclamationcircleo_dark.svg +3 -0
- package/lib/commonjs/icons/icFailed.gif +0 -0
- package/lib/commonjs/icons/icRadioChecked.svg +4 -0
- package/lib/commonjs/icons/icRadioUnchecked.svg +4 -0
- package/lib/commonjs/icons/icSuccess.gif +0 -0
- package/lib/commonjs/icons/index.js +28 -0
- package/lib/commonjs/icons/index.js.map +1 -0
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/manager/sdk/DispatchSDKManager.js +5 -4
- package/lib/commonjs/manager/sdk/DispatchSDKManager.js.map +1 -1
- package/lib/commonjs/manager/sdk/callbacksHandler.js +9 -2
- package/lib/commonjs/manager/sdk/callbacksHandler.js.map +1 -1
- package/lib/commonjs/manager/syncmanager/constants.js +3 -1
- package/lib/commonjs/manager/syncmanager/constants.js.map +1 -1
- package/lib/commonjs/manager/syncmanager/document/DocumentHttpClient.js +3 -2
- package/lib/commonjs/manager/syncmanager/document/DocumentHttpClient.js.map +1 -1
- package/lib/commonjs/manager/syncmanager/document/DocumentSyncManager.js +70 -80
- package/lib/commonjs/manager/syncmanager/document/DocumentSyncManager.js.map +1 -1
- package/lib/commonjs/models/sdk.js +1 -0
- package/lib/commonjs/models/sdk.js.map +1 -1
- package/lib/commonjs/ui/screens/ValidateOTPScreen.js +132 -12
- package/lib/commonjs/ui/screens/ValidateOTPScreen.js.map +1 -1
- package/lib/commonjs/utils/ApiUtils.js +122 -3
- package/lib/commonjs/utils/ApiUtils.js.map +1 -1
- package/lib/commonjs/utils/ExecTaskUtils.js +67 -7
- package/lib/commonjs/utils/ExecTaskUtils.js.map +1 -1
- package/lib/commonjs/utils/context/valdiateOTPContext.js +11 -0
- package/lib/commonjs/utils/context/valdiateOTPContext.js.map +1 -0
- package/lib/commonjs/utils/helper.js.map +1 -1
- package/lib/commonjs/utils/hooks/useTimer.js +68 -30
- package/lib/commonjs/utils/hooks/useTimer.js.map +1 -1
- package/lib/module/components/dispatch/DispatchExecNavigator.js.map +1 -1
- package/lib/module/components/executiontasks/forms/widgets/DateTimeWidget.js.map +1 -1
- package/lib/module/components/executiontasks/imageCapture/CaptureUtils.js +1 -1
- package/lib/module/components/executiontasks/imageCapture/CaptureUtils.js.map +1 -1
- package/lib/module/components/executiontasks/validateOTP/ValidateOTPET.js +480 -290
- package/lib/module/components/executiontasks/validateOTP/ValidateOTPET.js.map +1 -1
- package/lib/module/components/executiontasks/validateOTP/ValidateOTPSchema.js +14 -0
- package/lib/module/components/executiontasks/validateOTP/ValidateOTPSchema.js.map +1 -1
- package/lib/module/components/executiontasks/validateOTP/ValidateOtpStyles.js +264 -0
- package/lib/module/components/executiontasks/validateOTP/ValidateOtpStyles.js.map +1 -0
- package/lib/module/components/executiontasks/validateOTP/components/ContactListView.js +88 -0
- package/lib/module/components/executiontasks/validateOTP/components/ContactListView.js.map +1 -0
- package/lib/module/components/executiontasks/validateOTP/components/OTPView.js +194 -0
- package/lib/module/components/executiontasks/validateOTP/components/OTPView.js.map +1 -0
- package/lib/module/components/executiontasks/validateOTP/components/VerificationComplete.js +96 -0
- package/lib/module/components/executiontasks/validateOTP/components/VerificationComplete.js.map +1 -0
- package/lib/module/components/executiontasks/validateOTP/constants.js +11 -4
- package/lib/module/components/executiontasks/validateOTP/constants.js.map +1 -1
- package/lib/module/components/executiontasks/validateOTP/sub-components/ContactCard.js +59 -0
- package/lib/module/components/executiontasks/validateOTP/sub-components/ContactCard.js.map +1 -0
- package/lib/module/components/executiontasks/validateOTP/sub-components/OTPInput.js +11 -5
- package/lib/module/components/executiontasks/validateOTP/sub-components/OTPInput.js.map +1 -1
- package/lib/module/components/executiontasks/validateOTP/sub-components/ResendOTPButton.js +52 -0
- package/lib/module/components/executiontasks/validateOTP/sub-components/ResendOTPButton.js.map +1 -0
- package/lib/module/components/executiontasks/validateOTP/utils.js +219 -108
- package/lib/module/components/executiontasks/validateOTP/utils.js.map +1 -1
- package/lib/module/components/utils/Scale.js +14 -0
- package/lib/module/components/utils/Scale.js.map +1 -0
- package/lib/module/components/widgets/ConfirmCancelModal.js +40 -0
- package/lib/module/components/widgets/ConfirmCancelModal.js.map +1 -0
- package/lib/module/components/widgets/SnackBarCustom.js +36 -4
- package/lib/module/components/widgets/SnackBarCustom.js.map +1 -1
- package/lib/module/components/widgets/SplitTextInput.js +48 -19
- package/lib/module/components/widgets/SplitTextInput.js.map +1 -1
- package/lib/module/constants/apiConstants.js +4 -1
- package/lib/module/constants/apiConstants.js.map +1 -1
- package/lib/module/constants/constants.js +1 -0
- package/lib/module/constants/constants.js.map +1 -1
- package/lib/module/icons/icExclamationcircleo_dark.svg +3 -0
- package/lib/module/icons/icFailed.gif +0 -0
- package/lib/module/icons/icRadioChecked.svg +4 -0
- package/lib/module/icons/icRadioUnchecked.svg +4 -0
- package/lib/module/icons/icSuccess.gif +0 -0
- package/lib/module/icons/index.js +5 -0
- package/lib/module/icons/index.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/manager/sdk/DispatchSDKManager.js +5 -3
- package/lib/module/manager/sdk/DispatchSDKManager.js.map +1 -1
- package/lib/module/manager/sdk/callbacksHandler.js +12 -3
- package/lib/module/manager/sdk/callbacksHandler.js.map +1 -1
- package/lib/module/manager/syncmanager/constants.js +2 -0
- package/lib/module/manager/syncmanager/constants.js.map +1 -1
- package/lib/module/manager/syncmanager/document/DocumentHttpClient.js +3 -2
- package/lib/module/manager/syncmanager/document/DocumentHttpClient.js.map +1 -1
- package/lib/module/manager/syncmanager/document/DocumentSyncManager.js +70 -80
- package/lib/module/manager/syncmanager/document/DocumentSyncManager.js.map +1 -1
- package/lib/module/models/sdk.js +2 -0
- package/lib/module/models/sdk.js.map +1 -1
- package/lib/module/ui/screens/ValidateOTPScreen.js +139 -11
- package/lib/module/ui/screens/ValidateOTPScreen.js.map +1 -1
- package/lib/module/utils/ApiUtils.js +118 -2
- package/lib/module/utils/ApiUtils.js.map +1 -1
- package/lib/module/utils/ExecTaskUtils.js +66 -7
- package/lib/module/utils/ExecTaskUtils.js.map +1 -1
- package/lib/module/utils/context/valdiateOTPContext.js +4 -0
- package/lib/module/utils/context/valdiateOTPContext.js.map +1 -0
- package/lib/module/utils/helper.js +1 -0
- package/lib/module/utils/helper.js.map +1 -1
- package/lib/module/utils/hooks/useTimer.js +67 -30
- package/lib/module/utils/hooks/useTimer.js.map +1 -1
- package/lib/typescript/components/executiontasks/collectPayment/PaymentStyles.d.ts +3 -3
- package/lib/typescript/components/executiontasks/deliver/DeliverETInput.d.ts +0 -1
- package/lib/typescript/components/executiontasks/scan/modalConstant.d.ts +0 -1
- package/lib/typescript/components/executiontasks/validateOTP/ValidateOTPET.d.ts +3 -3
- package/lib/typescript/components/executiontasks/validateOTP/ValidateOTPSchema.d.ts +169 -5
- package/lib/typescript/components/executiontasks/validateOTP/ValidateOtpStyles.d.ts +255 -0
- package/lib/typescript/components/executiontasks/validateOTP/components/ContactListView.d.ts +3 -0
- package/lib/typescript/components/executiontasks/validateOTP/components/OTPView.d.ts +3 -0
- package/lib/typescript/components/executiontasks/validateOTP/components/VerificationComplete.d.ts +3 -0
- package/lib/typescript/components/executiontasks/validateOTP/constants.d.ts +11 -4
- package/lib/typescript/components/executiontasks/validateOTP/sub-components/ContactCard.d.ts +8 -0
- package/lib/typescript/components/executiontasks/validateOTP/sub-components/ResendOTPButton.d.ts +12 -0
- package/lib/typescript/components/executiontasks/validateOTP/utils.d.ts +31 -7
- package/lib/typescript/components/utils/Scale.d.ts +4 -0
- package/lib/typescript/components/widgets/ConfirmCancelModal.d.ts +9 -0
- package/lib/typescript/components/widgets/SnackBarCustom.d.ts +4 -8
- package/lib/typescript/components/widgets/SplitTextInput.d.ts +1 -1
- package/lib/typescript/components/widgets/Timer.d.ts +3 -3
- package/lib/typescript/constants/apiConstants.d.ts +3 -0
- package/lib/typescript/constants/constants.d.ts +1 -0
- package/lib/typescript/icons/index.d.ts +4 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/manager/sdk/callbacksHandler.d.ts +4 -1
- package/lib/typescript/manager/syncmanager/constants.d.ts +2 -0
- package/lib/typescript/models/execTasks/ETConfig.d.ts +1 -1
- package/lib/typescript/models/sdk.d.ts +3 -0
- package/lib/typescript/network/GraphQLClient.d.ts +4 -4
- package/lib/typescript/styles/executionTasks/CommonStyles.d.ts +2 -2
- package/lib/typescript/ui/screens/HttpRequestScreen.d.ts +0 -1
- package/lib/typescript/utils/ApiUtils.d.ts +6 -2
- package/lib/typescript/utils/ExecTaskUtils.d.ts +1 -0
- package/lib/typescript/utils/context/paymentContext.d.ts +0 -1
- package/lib/typescript/utils/context/valdiateOTPContext.d.ts +6 -0
- package/lib/typescript/utils/hooks/useModal.d.ts +0 -2
- package/lib/typescript/utils/hooks/useTimer.d.ts +7 -5
- package/package.json +46 -44
- package/src/components/dispatch/DispatchExecNavigator.tsx +1 -1
- package/src/components/executiontasks/forms/widgets/DateTimeWidget.tsx +2 -2
- package/src/components/executiontasks/imageCapture/CaptureUtils.ts +1 -1
- package/src/components/executiontasks/validateOTP/ValidateOTPET.tsx +654 -381
- package/src/components/executiontasks/validateOTP/ValidateOTPSchema.ts +193 -8
- package/src/components/executiontasks/validateOTP/ValidateOtpStyles.ts +296 -0
- package/src/components/executiontasks/validateOTP/components/ContactListView.tsx +109 -0
- package/src/components/executiontasks/validateOTP/components/OTPView.tsx +216 -0
- package/src/components/executiontasks/validateOTP/components/VerificationComplete.tsx +124 -0
- package/src/components/executiontasks/validateOTP/constants.ts +11 -4
- package/src/components/executiontasks/validateOTP/sub-components/ContactCard.tsx +72 -0
- package/src/components/executiontasks/validateOTP/sub-components/OTPInput.tsx +13 -7
- package/src/components/executiontasks/validateOTP/sub-components/ResendOTPButton.tsx +86 -0
- package/src/components/executiontasks/validateOTP/utils.ts +313 -143
- package/src/components/utils/Scale.ts +13 -0
- package/src/components/widgets/ConfirmCancelModal.tsx +49 -0
- package/src/components/widgets/SnackBarCustom.tsx +37 -13
- package/src/components/widgets/SplitTextInput.tsx +58 -21
- package/src/constants/apiConstants.ts +3 -0
- package/src/constants/constants.ts +2 -2
- package/src/icons/icExclamationcircleo_dark.svg +3 -0
- package/src/icons/icFailed.gif +0 -0
- package/src/icons/icRadioChecked.svg +4 -0
- package/src/icons/icRadioUnchecked.svg +4 -0
- package/src/icons/icSuccess.gif +0 -0
- package/src/icons/index.ts +5 -0
- package/src/index.tsx +2 -0
- package/src/manager/sdk/DispatchSDKManager.ts +6 -5
- package/src/manager/sdk/callbacksHandler.ts +29 -12
- package/src/manager/syncmanager/constants.ts +2 -0
- package/src/manager/syncmanager/document/DocumentHttpClient.ts +29 -29
- package/src/manager/syncmanager/document/DocumentSyncManager.ts +75 -84
- package/src/models/sdk.ts +6 -0
- package/src/ui/screens/ValidateOTPScreen.tsx +194 -32
- package/src/utils/ApiUtils.ts +131 -3
- package/src/utils/ExecTaskUtils.ts +77 -15
- package/src/utils/context/valdiateOTPContext.ts +9 -0
- package/src/utils/helper.ts +0 -1
- package/src/utils/hooks/useTimer.ts +94 -36
|
@@ -32,7 +32,7 @@ export async function getBaseETResponse(
|
|
|
32
32
|
const startLocation = await cache.getObjectFromCache(
|
|
33
33
|
DispatchSdkCache.KEYS.TASK_START_LOCATION
|
|
34
34
|
);
|
|
35
|
-
console.log(
|
|
35
|
+
console.log('getBaseETResponse:startLocation:', startLocation);
|
|
36
36
|
let baseResponse: BaseETResponse = {
|
|
37
37
|
entityCode: entityCode,
|
|
38
38
|
success: success,
|
|
@@ -40,13 +40,13 @@ export async function getBaseETResponse(
|
|
|
40
40
|
reasonCode: reasonCode,
|
|
41
41
|
id: taskId,
|
|
42
42
|
meta: {
|
|
43
|
-
startLocation:{
|
|
44
|
-
latitude:startLocation.latitude,
|
|
45
|
-
longitude:startLocation.longitude
|
|
43
|
+
startLocation: {
|
|
44
|
+
latitude: startLocation.latitude,
|
|
45
|
+
longitude: startLocation.longitude,
|
|
46
46
|
},
|
|
47
|
-
endLocation:{
|
|
48
|
-
latitude:lastLocation.latitude,
|
|
49
|
-
longitude:lastLocation.longitude
|
|
47
|
+
endLocation: {
|
|
48
|
+
latitude: lastLocation.latitude,
|
|
49
|
+
longitude: lastLocation.longitude,
|
|
50
50
|
},
|
|
51
51
|
// location: {
|
|
52
52
|
// latitude: location.latitude,
|
|
@@ -61,7 +61,7 @@ export async function getBaseETResponse(
|
|
|
61
61
|
},
|
|
62
62
|
mergedObjectiveIds,
|
|
63
63
|
};
|
|
64
|
-
console.log(
|
|
64
|
+
console.log('getBaseETResponse:baseResponse:', JSON.stringify(baseResponse));
|
|
65
65
|
|
|
66
66
|
return baseResponse;
|
|
67
67
|
}
|
|
@@ -155,8 +155,6 @@ export function onTaskStart(
|
|
|
155
155
|
await cache.setKeyInCache(keys.TASK_START_TIME, Date.now().toString());
|
|
156
156
|
await cache.setKeyInCache(keys.CURRENT_WORKING_TASK_ID, eventData.taskId);
|
|
157
157
|
await cache.setObjectInCache(keys.TASK_START_LOCATION, location);
|
|
158
|
-
|
|
159
|
-
|
|
160
158
|
})();
|
|
161
159
|
if (triggerEvent) {
|
|
162
160
|
const customEtName = eventData.taskName;
|
|
@@ -269,13 +267,77 @@ export function handleDynamicValues(jsonInput: any, dataBlob: any) {
|
|
|
269
267
|
return jsonInput;
|
|
270
268
|
}
|
|
271
269
|
|
|
270
|
+
export function parseRequestBody(body: any, userInput: any) {
|
|
271
|
+
const requestBody = JSON.parse(JSON.stringify(body)); // Deep clone the input
|
|
272
|
+
|
|
273
|
+
// Preprocess `userInput` placeholders before calling handleDynamicValues
|
|
274
|
+
const preprocessUserInput = (jsonInput: any) => {
|
|
275
|
+
for (const key in jsonInput) {
|
|
276
|
+
if (Object.prototype.hasOwnProperty.call(jsonInput, key)) {
|
|
277
|
+
const value = jsonInput[key];
|
|
278
|
+
|
|
279
|
+
if (typeof value === 'string' && value.includes('{{$.userInput}}')) {
|
|
280
|
+
// Replace `{{$.userInput}}` with the OTP value from userInput
|
|
281
|
+
jsonInput[key] = userInput.otp || value;
|
|
282
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
283
|
+
// Recursively preprocess nested objects
|
|
284
|
+
preprocessUserInput(value);
|
|
285
|
+
} else if (Array.isArray(value)) {
|
|
286
|
+
// Recursively preprocess arrays
|
|
287
|
+
jsonInput[key] = value.map((item) => {
|
|
288
|
+
if (typeof item === 'string' && item.includes('{{$.userInput}}')) {
|
|
289
|
+
return userInput.otp || userInput.input || item;
|
|
290
|
+
} else if (
|
|
291
|
+
typeof item === 'string' &&
|
|
292
|
+
item.includes('{{$.inputs.userInput}}')
|
|
293
|
+
) {
|
|
294
|
+
return userInput.input || item;
|
|
295
|
+
} else if (typeof item === 'object' && item !== null) {
|
|
296
|
+
preprocessUserInput(item);
|
|
297
|
+
return item;
|
|
298
|
+
}
|
|
299
|
+
return item;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return jsonInput;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// Step 1: Preprocess the body for `{{$.userInput}}`
|
|
308
|
+
const preprocessedBody = preprocessUserInput(requestBody);
|
|
309
|
+
|
|
310
|
+
// Step 2: Pass the preprocessed body to `handleDynamicValues`
|
|
311
|
+
const resolvedBody = handleDynamicValues(preprocessedBody, userInput);
|
|
312
|
+
|
|
313
|
+
return resolvedBody;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// old masking
|
|
317
|
+
// export const maskContact = (contact: string) => {
|
|
318
|
+
// if (contact && contact?.includes('@')) {
|
|
319
|
+
// const [name, domain] = contact.split('@');
|
|
320
|
+
// const maskedName = name.substring(0, 3) + '****';
|
|
321
|
+
// const maskedEmail = maskedName + '@' + domain;
|
|
322
|
+
// return maskedEmail;
|
|
323
|
+
// } else {
|
|
324
|
+
// return `${contact && contact.slice(0, 2)}****${contact.slice(-4)}`;
|
|
325
|
+
// }
|
|
326
|
+
// };
|
|
272
327
|
export const maskContact = (contact: string) => {
|
|
273
|
-
if (contact.includes('@')) {
|
|
328
|
+
if (contact && contact.includes('@')) {
|
|
274
329
|
const [name, domain] = contact.split('@');
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
330
|
+
let maskedName;
|
|
331
|
+
if (name.length <= 2) {
|
|
332
|
+
maskedName = name.substring(0, 1) + '*****';
|
|
333
|
+
} else {
|
|
334
|
+
maskedName = name.substring(0, 2) + '*****';
|
|
335
|
+
}
|
|
336
|
+
return maskedName + '@' + domain;
|
|
278
337
|
} else {
|
|
279
|
-
|
|
338
|
+
const visibleDigits = 4;
|
|
339
|
+
const maskedPart = '*'.repeat(Math.max(contact.length - visibleDigits, 0));
|
|
340
|
+
const visiblePart = contact.slice(-visibleDigits);
|
|
341
|
+
return maskedPart + visiblePart;
|
|
280
342
|
}
|
|
281
343
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { createContext } from 'react';
|
|
3
|
+
import { DispatchSDKConfig } from '../../models/sdk';
|
|
4
|
+
import NetworkClient from '../../network/NetworkClient';
|
|
5
|
+
|
|
6
|
+
export const ValidateOTPContext = createContext<{
|
|
7
|
+
sdkConfig: DispatchSDKConfig;
|
|
8
|
+
networkInstance: NetworkClient;
|
|
9
|
+
} | null>(null);
|
package/src/utils/helper.ts
CHANGED
|
@@ -1,44 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { AppState, AppStateStatus } from 'react-native';
|
|
4
|
+
|
|
5
|
+
// Function to format the expiry time (without showing '0 sec' when it's unnecessary)
|
|
6
|
+
export const formatExpiryTime = (timeInSeconds: number) => {
|
|
7
|
+
const minutes = Math.floor(timeInSeconds / 60);
|
|
8
|
+
const seconds = timeInSeconds % 60;
|
|
9
|
+
|
|
10
|
+
if (minutes > 0 && seconds > 0) {
|
|
11
|
+
return `${minutes} min ${seconds} sec`;
|
|
12
|
+
} else if (minutes > 0 && seconds === 0) {
|
|
13
|
+
return `${minutes} min`;
|
|
14
|
+
} else {
|
|
15
|
+
return `${seconds} sec`;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const useResendOtpTimer = (
|
|
20
|
+
initialTimerValue: number,
|
|
21
|
+
onTimerEnd?: () => void
|
|
22
|
+
) => {
|
|
23
|
+
const [timer, setTimer] = useState(initialTimerValue);
|
|
24
|
+
const appState = useRef(AppState.currentState);
|
|
25
|
+
const initialTimeRef = useRef(Date.now());
|
|
26
|
+
|
|
27
|
+
const resetTimer = useCallback(() => {
|
|
28
|
+
initialTimeRef.current = Date.now();
|
|
29
|
+
setTimer(initialTimerValue);
|
|
30
|
+
}, [initialTimerValue]);
|
|
31
|
+
|
|
32
|
+
const updateTimer = useCallback(() => {
|
|
33
|
+
const currentTime = Date.now();
|
|
34
|
+
const elapsedTimeInSeconds = Math.floor(
|
|
35
|
+
(currentTime - initialTimeRef.current) / 1000
|
|
36
|
+
);
|
|
37
|
+
const remainingTime = Math.max(0, initialTimerValue - elapsedTimeInSeconds);
|
|
38
|
+
|
|
39
|
+
if (remainingTime !== timer) {
|
|
40
|
+
setTimer(remainingTime);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (remainingTime === 0 && onTimerEnd) {
|
|
44
|
+
onTimerEnd();
|
|
45
|
+
}
|
|
46
|
+
}, [initialTimerValue, onTimerEnd, timer]);
|
|
47
|
+
|
|
10
48
|
useEffect(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
49
|
+
resetTimer();
|
|
50
|
+
}, [initialTimerValue, resetTimer]);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
// Update the timer immediately on mount
|
|
54
|
+
updateTimer();
|
|
55
|
+
const intervalId = setInterval(updateTimer, 1000);
|
|
56
|
+
return () => clearInterval(intervalId);
|
|
57
|
+
}, [updateTimer]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const handleAppStateChange = (nextAppState: AppStateStatus) => {
|
|
61
|
+
if (
|
|
62
|
+
appState.current.match(/inactive|background/) &&
|
|
63
|
+
nextAppState === 'active'
|
|
64
|
+
) {
|
|
65
|
+
// Calculate elapsed time and adjust the initial time reference
|
|
66
|
+
const currentTime = Date.now();
|
|
67
|
+
const elapsedTimeInSeconds = Math.floor(
|
|
68
|
+
(currentTime - initialTimeRef.current) / 1000
|
|
69
|
+
);
|
|
70
|
+
const newRemainingTime = Math.max(
|
|
71
|
+
0,
|
|
72
|
+
initialTimerValue - elapsedTimeInSeconds
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Update initial time ref based on new remaining time
|
|
76
|
+
initialTimeRef.current =
|
|
77
|
+
currentTime - (initialTimerValue - newRemainingTime) * 1000;
|
|
78
|
+
|
|
79
|
+
// Update the timer
|
|
80
|
+
setTimer(newRemainingTime);
|
|
81
|
+
updateTimer();
|
|
22
82
|
}
|
|
23
|
-
|
|
83
|
+
appState.current = nextAppState;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const subscription = AppState.addEventListener(
|
|
87
|
+
'change',
|
|
88
|
+
handleAppStateChange
|
|
89
|
+
);
|
|
24
90
|
return () => {
|
|
25
|
-
|
|
91
|
+
subscription.remove();
|
|
26
92
|
};
|
|
27
|
-
});
|
|
93
|
+
}, [updateTimer, initialTimerValue]);
|
|
28
94
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
95
|
+
return {
|
|
96
|
+
formattedTime: formatExpiryTime(timer),
|
|
97
|
+
timer: timer,
|
|
98
|
+
resetTimer,
|
|
34
99
|
};
|
|
35
|
-
|
|
36
|
-
const timer =
|
|
37
|
-
minutes === 0 && seconds === 0
|
|
38
|
-
? null
|
|
39
|
-
: `${minutes}: ${seconds < 10 ? `0${seconds}` : seconds}`;
|
|
40
|
-
|
|
41
|
-
return [timer, resetTimer];
|
|
42
100
|
};
|
|
43
101
|
|
|
44
|
-
export default
|
|
102
|
+
export default useResendOtpTimer;
|