@umituz/react-native-subscription 2.24.3 → 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;
|
|
@@ -99,7 +116,27 @@ export function useFeatureGate(
|
|
|
99
116
|
|
|
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
|
|
121
|
+
const postAuthAction = () => {
|
|
122
|
+
// Step 2: Subscription check (bypasses credits if subscribed)
|
|
123
|
+
if (hasSubscriptionRef.current) {
|
|
124
|
+
action();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Step 3: Credits check (use ref for current value)
|
|
129
|
+
if (!hasCreditsRef.current) {
|
|
130
|
+
pendingActionRef.current = action;
|
|
131
|
+
isWaitingForPurchaseRef.current = true;
|
|
132
|
+
onShowPaywallRef.current(requiredCredits);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// All checks passed
|
|
137
|
+
action();
|
|
138
|
+
};
|
|
139
|
+
onShowAuthModal(postAuthAction);
|
|
103
140
|
return;
|
|
104
141
|
}
|
|
105
142
|
|
|
@@ -124,7 +161,10 @@ export function useFeatureGate(
|
|
|
124
161
|
authGate,
|
|
125
162
|
creditsGate,
|
|
126
163
|
hasSubscription,
|
|
164
|
+
hasCredits,
|
|
165
|
+
requiredCredits,
|
|
127
166
|
onShowAuthModal,
|
|
167
|
+
onShowPaywall,
|
|
128
168
|
]
|
|
129
169
|
);
|
|
130
170
|
|