@umituz/react-native-subscription 2.19.0 → 2.19.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.19.0",
3
+ "version": "2.19.2",
4
4
  "description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -3,7 +3,7 @@
3
3
  * Automatically executes pending purchase after successful authentication
4
4
  */
5
5
 
6
- import { useEffect } from "react";
6
+ import { useEffect, useRef } from "react";
7
7
  import { usePendingPurchaseStore } from "../../infrastructure/stores/PendingPurchaseStore";
8
8
  import { usePremium } from "./usePremium";
9
9
 
@@ -22,24 +22,29 @@ export const usePendingPurchaseHandler = ({
22
22
  userId,
23
23
  isAuthenticated,
24
24
  }: UsePendingPurchaseHandlerParams): void => {
25
- const {
26
- getPendingPurchase,
27
- clearPendingPurchase,
28
- hasPendingPurchase,
29
- } = usePendingPurchaseStore();
25
+ const { pending, clearPendingPurchase } = usePendingPurchaseStore();
30
26
  const { purchasePackage } = usePremium(userId);
27
+ const isExecutingRef = useRef(false);
28
+ const executedPackageIdRef = useRef<string | null>(null);
31
29
 
32
30
  useEffect(() => {
33
- if (!isAuthenticated || !userId || !hasPendingPurchase()) {
31
+ if (!isAuthenticated || !userId || !pending) {
34
32
  return;
35
33
  }
36
34
 
37
- const executePendingPurchase = async () => {
38
- const pending = getPendingPurchase();
35
+ // Prevent duplicate executions
36
+ if (isExecutingRef.current) {
37
+ return;
38
+ }
39
39
 
40
- if (!pending) {
41
- return;
42
- }
40
+ // Prevent re-executing the same package
41
+ if (executedPackageIdRef.current === pending.package.identifier) {
42
+ return;
43
+ }
44
+
45
+ const executePendingPurchase = async () => {
46
+ isExecutingRef.current = true;
47
+ executedPackageIdRef.current = pending.package.identifier;
43
48
 
44
49
  if (__DEV__) {
45
50
  console.log(
@@ -63,16 +68,10 @@ export const usePendingPurchaseHandler = ({
63
68
  }
64
69
  } finally {
65
70
  clearPendingPurchase();
71
+ isExecutingRef.current = false;
66
72
  }
67
73
  };
68
74
 
69
75
  void executePendingPurchase();
70
- }, [
71
- isAuthenticated,
72
- userId,
73
- hasPendingPurchase,
74
- getPendingPurchase,
75
- clearPendingPurchase,
76
- purchasePackage,
77
- ]);
76
+ }, [isAuthenticated, userId, pending, clearPendingPurchase, purchasePackage]);
78
77
  };