@finspringinnovations/fdsdk 0.0.8 → 0.0.9

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.
@@ -93,6 +93,9 @@ const AadhaarVerification = ({ onGoBack, onVerificationComplete, }) => {
93
93
  const [isOtpLocked, setIsOtpLocked] = (0, react_1.useState)(false);
94
94
  const [otpVerificationError, setOtpVerificationError] = (0, react_1.useState)('');
95
95
  const [isValidateOtpTaskCalled, setIsValidateOtpTaskCalled] = (0, react_1.useState)(false);
96
+ // Prevent OTP send API from running twice when 12 digits are entered (iOS can fire onChangeText multiple times)
97
+ const sendOtpTriggeredRef = react_1.default.useRef(false);
98
+ const autoSendOtpTimeoutRef = react_1.default.useRef(null);
96
99
  // If customer/application/details has Aadhaar already, show verified view
97
100
  react_1.default.useEffect(() => {
98
101
  const checkAadhaarStatus = async () => {
@@ -134,6 +137,9 @@ const AadhaarVerification = ({ onGoBack, onVerificationComplete, }) => {
134
137
  // Auto send OTP when 12 digits are entered
135
138
  const autoSendOtp = async (aadhaarNum) => {
136
139
  var _a;
140
+ if (sendOtpTriggeredRef.current)
141
+ return;
142
+ sendOtpTriggeredRef.current = true;
137
143
  // Start session timer
138
144
  const timer = setInterval(() => {
139
145
  setSessionTime((prev) => {
@@ -174,6 +180,7 @@ const AadhaarVerification = ({ onGoBack, onVerificationComplete, }) => {
174
180
  }
175
181
  }
176
182
  catch (error) {
183
+ sendOtpTriggeredRef.current = false;
177
184
  // Don't show alert immediately, let user try to enter OTP
178
185
  // They can use resend if needed
179
186
  setVerificationState('initial');
@@ -225,6 +232,7 @@ const AadhaarVerification = ({ onGoBack, onVerificationComplete, }) => {
225
232
  setOtp(['', '', '', '', '', '']);
226
233
  setIsResendEnabled(false);
227
234
  setSessionTime(120);
235
+ sendOtpTriggeredRef.current = false;
228
236
  // Reset verification state when Aadhaar changes
229
237
  setIsOtpVerified(false);
230
238
  setOtpVerificationError('');
@@ -245,10 +253,15 @@ const AadhaarVerification = ({ onGoBack, onVerificationComplete, }) => {
245
253
  else if (cleaned.length === 12) {
246
254
  setAadhaarError('');
247
255
  // setAadhaarSuccess('Valid Aadhaar number');
248
- // Auto send OTP and transition to OTP view when 12 digits are entered
256
+ // Auto send OTP when 12 digits are entered. Cancel any existing timeout so we only schedule one
257
+ // (on iOS onChangeText can fire multiple times for the same 12 digits, causing duplicate API calls).
249
258
  if (verificationState === 'initial') {
250
- // Small delay to show success message briefly before transitioning
251
- setTimeout(() => {
259
+ if (autoSendOtpTimeoutRef.current) {
260
+ clearTimeout(autoSendOtpTimeoutRef.current);
261
+ autoSendOtpTimeoutRef.current = null;
262
+ }
263
+ autoSendOtpTimeoutRef.current = setTimeout(() => {
264
+ autoSendOtpTimeoutRef.current = null;
252
265
  autoSendOtp(cleaned);
253
266
  }, 500);
254
267
  }
@@ -482,7 +495,7 @@ const AadhaarVerification = ({ onGoBack, onVerificationComplete, }) => {
482
495
  };
483
496
  const handleButtonPress = async () => {
484
497
  if (verificationState === 'initial') {
485
- if (aadhaarNumber.length === 12) {
498
+ if (aadhaarNumber.length === 12 && !sendOtpTriggeredRef.current) {
486
499
  autoSendOtp(aadhaarNumber);
487
500
  }
488
501
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finspringinnovations/fdsdk",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "FD SDK for React Native applications",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -72,6 +72,10 @@ const AadhaarVerification: React.FC<AadhaarVerificationProps> = ({
72
72
  const [isOtpLocked, setIsOtpLocked] = useState<boolean>(false);
73
73
  const [otpVerificationError, setOtpVerificationError] = useState<string>('');
74
74
  const [isValidateOtpTaskCalled, setIsValidateOtpTaskCalled] = useState<boolean>(false);
75
+ // Prevent OTP send API from running twice when 12 digits are entered (iOS can fire onChangeText multiple times)
76
+ const sendOtpTriggeredRef = React.useRef<boolean>(false);
77
+ const autoSendOtpTimeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);
78
+
75
79
  // If customer/application/details has Aadhaar already, show verified view
76
80
  React.useEffect(() => {
77
81
  const checkAadhaarStatus = async () => {
@@ -116,6 +120,9 @@ const AadhaarVerification: React.FC<AadhaarVerificationProps> = ({
116
120
 
117
121
  // Auto send OTP when 12 digits are entered
118
122
  const autoSendOtp = async (aadhaarNum: string) => {
123
+ if (sendOtpTriggeredRef.current) return;
124
+ sendOtpTriggeredRef.current = true;
125
+
119
126
  // Start session timer
120
127
  const timer = setInterval(() => {
121
128
  setSessionTime((prev) => {
@@ -159,6 +166,7 @@ const AadhaarVerification: React.FC<AadhaarVerificationProps> = ({
159
166
  }
160
167
 
161
168
  } catch (error) {
169
+ sendOtpTriggeredRef.current = false;
162
170
 
163
171
  // Don't show alert immediately, let user try to enter OTP
164
172
  // They can use resend if needed
@@ -215,6 +223,7 @@ const AadhaarVerification: React.FC<AadhaarVerificationProps> = ({
215
223
  setOtp(['', '', '', '', '', '']);
216
224
  setIsResendEnabled(false);
217
225
  setSessionTime(120);
226
+ sendOtpTriggeredRef.current = false;
218
227
  // Reset verification state when Aadhaar changes
219
228
  setIsOtpVerified(false);
220
229
  setOtpVerificationError('');
@@ -236,10 +245,15 @@ const AadhaarVerification: React.FC<AadhaarVerificationProps> = ({
236
245
  setAadhaarError('');
237
246
  // setAadhaarSuccess('Valid Aadhaar number');
238
247
 
239
- // Auto send OTP and transition to OTP view when 12 digits are entered
248
+ // Auto send OTP when 12 digits are entered. Cancel any existing timeout so we only schedule one
249
+ // (on iOS onChangeText can fire multiple times for the same 12 digits, causing duplicate API calls).
240
250
  if (verificationState === 'initial') {
241
- // Small delay to show success message briefly before transitioning
242
- setTimeout(() => {
251
+ if (autoSendOtpTimeoutRef.current) {
252
+ clearTimeout(autoSendOtpTimeoutRef.current);
253
+ autoSendOtpTimeoutRef.current = null;
254
+ }
255
+ autoSendOtpTimeoutRef.current = setTimeout(() => {
256
+ autoSendOtpTimeoutRef.current = null;
243
257
  autoSendOtp(cleaned);
244
258
  }, 500);
245
259
  }
@@ -616,7 +630,7 @@ const AadhaarVerification: React.FC<AadhaarVerificationProps> = ({
616
630
 
617
631
 
618
632
  if (verificationState === 'initial') {
619
- if (aadhaarNumber.length === 12) {
633
+ if (aadhaarNumber.length === 12 && !sendOtpTriggeredRef.current) {
620
634
  autoSendOtp(aadhaarNumber);
621
635
  }
622
636
  } else if (verificationState === 'otp') {