@reevit/react 0.4.7 → 0.4.8
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/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -422,6 +422,7 @@ function useReevit(options) {
|
|
|
422
422
|
});
|
|
423
423
|
const apiClientRef = useRef(null);
|
|
424
424
|
const initializingRef = useRef(!!config.initialPaymentIntent);
|
|
425
|
+
const initRequestIdRef = useRef(0);
|
|
425
426
|
useEffect(() => {
|
|
426
427
|
if (config.initialPaymentIntent) {
|
|
427
428
|
if (!state.paymentIntent || state.paymentIntent.id !== config.initialPaymentIntent.id) {
|
|
@@ -445,11 +446,11 @@ function useReevit(options) {
|
|
|
445
446
|
return;
|
|
446
447
|
}
|
|
447
448
|
initializingRef.current = true;
|
|
449
|
+
const requestId = ++initRequestIdRef.current;
|
|
448
450
|
dispatch({ type: "INIT_START" });
|
|
449
451
|
try {
|
|
450
452
|
const apiClient = apiClientRef.current;
|
|
451
453
|
if (!apiClient) {
|
|
452
|
-
initializingRef.current = false;
|
|
453
454
|
throw new Error("API client not initialized");
|
|
454
455
|
}
|
|
455
456
|
const reference = config.reference || generateReference();
|
|
@@ -498,6 +499,9 @@ function useReevit(options) {
|
|
|
498
499
|
data = result.data;
|
|
499
500
|
error = result.error;
|
|
500
501
|
}
|
|
502
|
+
if (requestId !== initRequestIdRef.current) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
501
505
|
if (error) {
|
|
502
506
|
dispatch({ type: "INIT_ERROR", payload: error });
|
|
503
507
|
onError?.(error);
|
|
@@ -517,6 +521,9 @@ function useReevit(options) {
|
|
|
517
521
|
const paymentIntent = mapToPaymentIntent(data, { ...config, reference });
|
|
518
522
|
dispatch({ type: "INIT_SUCCESS", payload: paymentIntent });
|
|
519
523
|
} catch (err) {
|
|
524
|
+
if (requestId !== initRequestIdRef.current) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
520
527
|
const error = {
|
|
521
528
|
code: "INIT_FAILED",
|
|
522
529
|
message: err instanceof Error ? err.message : "Failed to initialize checkout",
|
|
@@ -598,6 +605,7 @@ function useReevit(options) {
|
|
|
598
605
|
);
|
|
599
606
|
const reset = useCallback(() => {
|
|
600
607
|
initializingRef.current = false;
|
|
608
|
+
initRequestIdRef.current += 1;
|
|
601
609
|
dispatch({ type: "RESET" });
|
|
602
610
|
}, []);
|
|
603
611
|
const close = useCallback(async () => {
|