@umituz/react-native-subscription 2.24.4 → 2.24.5
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.24.
|
|
3
|
+
"version": "2.24.5",
|
|
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",
|
|
@@ -60,6 +60,23 @@ export function useFeatureGate(
|
|
|
60
60
|
const prevCreditBalanceRef = useRef(creditBalance);
|
|
61
61
|
const isWaitingForPurchaseRef = useRef(false);
|
|
62
62
|
|
|
63
|
+
// Refs to always get current values in closures
|
|
64
|
+
const hasCreditsRef = useRef(hasCredits);
|
|
65
|
+
const hasSubscriptionRef = useRef(hasSubscription);
|
|
66
|
+
const onShowPaywallRef = useRef(onShowPaywall);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
hasCreditsRef.current = hasCredits;
|
|
70
|
+
}, [hasCredits]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
hasSubscriptionRef.current = hasSubscription;
|
|
74
|
+
}, [hasSubscription]);
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
onShowPaywallRef.current = onShowPaywall;
|
|
78
|
+
}, [onShowPaywall]);
|
|
79
|
+
|
|
63
80
|
// Execute pending action when credits increase after purchase
|
|
64
81
|
useEffect(() => {
|
|
65
82
|
const prevBalance = prevCreditBalanceRef.current;
|
|
@@ -100,18 +117,19 @@ export function useFeatureGate(
|
|
|
100
117
|
// Step 1: Auth check
|
|
101
118
|
if (!authGate.requireAuth(() => {})) {
|
|
102
119
|
// Wrap action to re-check credits after auth succeeds
|
|
120
|
+
// Using refs to get current values when callback executes
|
|
103
121
|
const postAuthAction = () => {
|
|
104
122
|
// Step 2: Subscription check (bypasses credits if subscribed)
|
|
105
|
-
if (
|
|
123
|
+
if (hasSubscriptionRef.current) {
|
|
106
124
|
action();
|
|
107
125
|
return;
|
|
108
126
|
}
|
|
109
127
|
|
|
110
|
-
// Step 3: Credits check
|
|
111
|
-
if (!
|
|
128
|
+
// Step 3: Credits check (use ref for current value)
|
|
129
|
+
if (!hasCreditsRef.current) {
|
|
112
130
|
pendingActionRef.current = action;
|
|
113
131
|
isWaitingForPurchaseRef.current = true;
|
|
114
|
-
|
|
132
|
+
onShowPaywallRef.current(requiredCredits);
|
|
115
133
|
return;
|
|
116
134
|
}
|
|
117
135
|
|