@umituz/react-native-subscription 2.23.2 → 2.24.0
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.
|
|
3
|
+
"version": "2.24.0",
|
|
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
|
* Combines auth, subscription, and credits gates into a unified feature gate.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useCallback } from "react";
|
|
6
|
+
import { useCallback, useRef, useEffect } from "react";
|
|
7
7
|
import { useAuthGate } from "./useAuthGate";
|
|
8
8
|
import { useSubscriptionGate } from "./useSubscriptionGate";
|
|
9
9
|
import { useCreditsGate } from "./useCreditsGate";
|
|
@@ -55,6 +55,24 @@ export function useFeatureGate(
|
|
|
55
55
|
onShowPaywall,
|
|
56
56
|
} = params;
|
|
57
57
|
|
|
58
|
+
// Store pending action for execution after purchase
|
|
59
|
+
const pendingActionRef = useRef<(() => void | Promise<void>) | null>(null);
|
|
60
|
+
const prevHasCreditsRef = useRef(hasCredits);
|
|
61
|
+
|
|
62
|
+
// Execute pending action when credits become available
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const hadNoCredits = !prevHasCreditsRef.current;
|
|
65
|
+
const nowHasCredits = hasCredits;
|
|
66
|
+
|
|
67
|
+
if (hadNoCredits && nowHasCredits && pendingActionRef.current) {
|
|
68
|
+
const action = pendingActionRef.current;
|
|
69
|
+
pendingActionRef.current = null;
|
|
70
|
+
action();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
prevHasCreditsRef.current = hasCredits;
|
|
74
|
+
}, [hasCredits]);
|
|
75
|
+
|
|
58
76
|
// Compose individual gates
|
|
59
77
|
const authGate = useAuthGate({
|
|
60
78
|
isAuthenticated,
|
|
@@ -90,6 +108,8 @@ export function useFeatureGate(
|
|
|
90
108
|
|
|
91
109
|
// Step 3: Credits check
|
|
92
110
|
if (!creditsGate.requireCredits(() => {})) {
|
|
111
|
+
// Store pending action for execution after purchase
|
|
112
|
+
pendingActionRef.current = action;
|
|
93
113
|
return;
|
|
94
114
|
}
|
|
95
115
|
|