@umituz/react-native-subscription 2.33.5 → 2.33.7

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.33.5",
3
+ "version": "2.33.7",
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",
@@ -1,5 +1,7 @@
1
1
  import type { MutableRefObject } from "react";
2
2
 
3
+ declare const __DEV__: boolean;
4
+
3
5
  export const executeFeatureAction = (
4
6
  action: () => void | Promise<void>,
5
7
  isAuthenticated: boolean,
@@ -13,20 +15,45 @@ export const executeFeatureAction = (
13
15
  isWaitingForPurchaseRef: MutableRefObject<boolean>,
14
16
  isCreditsLoadedRef: MutableRefObject<boolean>
15
17
  ): void => {
18
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
19
+ console.log("[FeatureGate] executeFeatureAction called:", {
20
+ isAuthenticated,
21
+ hasSubscription: hasSubscriptionRef.current,
22
+ creditBalance: creditBalanceRef.current,
23
+ requiredCredits: requiredCreditsRef.current,
24
+ isCreditsLoaded: isCreditsLoadedRef.current,
25
+ });
26
+ }
27
+
16
28
  if (!isAuthenticated) {
29
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
30
+ console.log("[FeatureGate] User not authenticated, showing auth modal");
31
+ }
17
32
  const postAuthAction = () => {
33
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
34
+ console.log("[FeatureGate] Post-auth action called");
35
+ }
18
36
  if (hasSubscriptionRef.current || creditBalanceRef.current >= requiredCreditsRef.current) {
37
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
38
+ console.log("[FeatureGate] Post-auth: User has access, executing action");
39
+ }
19
40
  action();
20
41
  return;
21
42
  }
22
43
 
23
44
  if (isCreditsLoadedRef.current) {
45
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
46
+ console.log("[FeatureGate] Post-auth: Credits loaded, showing paywall");
47
+ }
24
48
  pendingActionRef.current = action;
25
49
  isWaitingForPurchaseRef.current = true;
26
50
  onShowPaywallRef.current(requiredCreditsRef.current);
27
51
  return;
28
52
  }
29
53
 
54
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
55
+ console.log("[FeatureGate] Post-auth: Waiting for credits to load");
56
+ }
30
57
  pendingActionRef.current = action;
31
58
  isWaitingForAuthCreditsRef.current = true;
32
59
  };
@@ -35,16 +62,25 @@ export const executeFeatureAction = (
35
62
  }
36
63
 
37
64
  if (hasSubscriptionRef.current) {
65
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
66
+ console.log("[FeatureGate] User has subscription, executing action");
67
+ }
38
68
  action();
39
69
  return;
40
70
  }
41
71
 
42
72
  if (creditBalanceRef.current < requiredCreditsRef.current) {
73
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
74
+ console.log("[FeatureGate] Insufficient credits, showing paywall");
75
+ }
43
76
  pendingActionRef.current = action;
44
77
  isWaitingForPurchaseRef.current = true;
45
78
  onShowPaywallRef.current(requiredCreditsRef.current);
46
79
  return;
47
80
  }
48
81
 
82
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
83
+ console.log("[FeatureGate] User has enough credits, executing action");
84
+ }
49
85
  action();
50
86
  };
@@ -6,6 +6,8 @@ import { executeFeatureAction } from "./featureGateActions";
6
6
 
7
7
  export type { UseFeatureGateParams, UseFeatureGateResult } from "./useFeatureGate.types";
8
8
 
9
+ declare const __DEV__: boolean;
10
+
9
11
  export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResult {
10
12
  const {
11
13
  isAuthenticated,
@@ -25,14 +27,34 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
25
27
  const { creditBalanceRef, hasSubscriptionRef, onShowPaywallRef, requiredCreditsRef, isCreditsLoadedRef } = useSyncedRefs(creditBalance, hasSubscription, onShowPaywall, requiredCredits, isCreditsLoaded);
26
28
 
27
29
  useEffect(() => {
28
- if (shouldExecuteAuthAction(
30
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
31
+ console.log("[FeatureGate] Auth completion useEffect triggered:", {
32
+ isWaitingForAuthCredits: isWaitingForAuthCreditsRef.current,
33
+ isCreditsLoaded,
34
+ hasPendingAction: !!pendingActionRef.current,
35
+ hasSubscription,
36
+ creditBalance,
37
+ requiredCredits,
38
+ });
39
+ }
40
+
41
+ const shouldExecute = shouldExecuteAuthAction(
29
42
  isWaitingForAuthCreditsRef.current,
30
43
  isCreditsLoaded,
31
44
  !!pendingActionRef.current,
32
45
  hasSubscription,
33
46
  creditBalance,
34
47
  requiredCredits
35
- )) {
48
+ );
49
+
50
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
51
+ console.log("[FeatureGate] shouldExecuteAuthAction:", shouldExecute);
52
+ }
53
+
54
+ if (shouldExecute) {
55
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
56
+ console.log("[FeatureGate] ✅ EXECUTING PENDING ACTION after auth!");
57
+ }
36
58
  isWaitingForAuthCreditsRef.current = false;
37
59
  const action = pendingActionRef.current!;
38
60
  pendingActionRef.current = null;
@@ -41,6 +63,9 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
41
63
  }
42
64
 
43
65
  if (isWaitingForAuthCreditsRef.current && isCreditsLoaded && pendingActionRef.current) {
66
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
67
+ console.log("[FeatureGate] Auth credits loaded but insufficient, showing paywall");
68
+ }
44
69
  isWaitingForAuthCreditsRef.current = false;
45
70
  isWaitingForPurchaseRef.current = true;
46
71
  onShowPaywall(requiredCredits);
@@ -48,14 +73,34 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
48
73
  }, [isCreditsLoaded, creditBalance, hasSubscription, requiredCredits, onShowPaywall]);
49
74
 
50
75
  useEffect(() => {
51
- if (shouldExecutePurchaseAction(
76
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
77
+ console.log("[FeatureGate] Purchase completion useEffect triggered:", {
78
+ creditBalance,
79
+ prevCreditBalance: prevCreditBalanceRef.current,
80
+ hasSubscription,
81
+ prevHasSubscription: hasSubscriptionRef.current,
82
+ isWaitingForPurchase: isWaitingForPurchaseRef.current,
83
+ hasPendingAction: !!pendingActionRef.current,
84
+ });
85
+ }
86
+
87
+ const shouldExecute = shouldExecutePurchaseAction(
52
88
  isWaitingForPurchaseRef.current,
53
89
  creditBalance,
54
90
  prevCreditBalanceRef.current ?? 0,
55
91
  hasSubscription,
56
92
  hasSubscriptionRef.current,
57
93
  !!pendingActionRef.current
58
- )) {
94
+ );
95
+
96
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
97
+ console.log("[FeatureGate] shouldExecutePurchaseAction:", shouldExecute);
98
+ }
99
+
100
+ if (shouldExecute) {
101
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
102
+ console.log("[FeatureGate] ✅ EXECUTING PENDING ACTION after purchase!");
103
+ }
59
104
  const action = pendingActionRef.current!;
60
105
  pendingActionRef.current = null;
61
106
  isWaitingForPurchaseRef.current = false;