@umituz/react-native-subscription 2.23.2 → 2.24.1
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.1",
|
|
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,27 @@ 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 prevCreditBalanceRef = useRef(creditBalance);
|
|
61
|
+
const isWaitingForPurchaseRef = useRef(false);
|
|
62
|
+
|
|
63
|
+
// Execute pending action when credits increase after purchase
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const prevBalance = prevCreditBalanceRef.current;
|
|
66
|
+
const currentBalance = creditBalance;
|
|
67
|
+
const creditsIncreased = currentBalance > prevBalance;
|
|
68
|
+
|
|
69
|
+
if (isWaitingForPurchaseRef.current && creditsIncreased && pendingActionRef.current) {
|
|
70
|
+
const action = pendingActionRef.current;
|
|
71
|
+
pendingActionRef.current = null;
|
|
72
|
+
isWaitingForPurchaseRef.current = false;
|
|
73
|
+
action();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
prevCreditBalanceRef.current = creditBalance;
|
|
77
|
+
}, [creditBalance]);
|
|
78
|
+
|
|
58
79
|
// Compose individual gates
|
|
59
80
|
const authGate = useAuthGate({
|
|
60
81
|
isAuthenticated,
|
|
@@ -90,6 +111,9 @@ export function useFeatureGate(
|
|
|
90
111
|
|
|
91
112
|
// Step 3: Credits check
|
|
92
113
|
if (!creditsGate.requireCredits(() => {})) {
|
|
114
|
+
// Store pending action for execution after purchase
|
|
115
|
+
pendingActionRef.current = action;
|
|
116
|
+
isWaitingForPurchaseRef.current = true;
|
|
93
117
|
return;
|
|
94
118
|
}
|
|
95
119
|
|