@umituz/react-native-subscription 2.24.0 → 2.24.2
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.2",
|
|
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",
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* Generic and reusable - uses config from module-level provider.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare const __DEV__: boolean;
|
|
9
|
-
|
|
10
8
|
import { useQuery } from "@umituz/react-native-design-system";
|
|
11
9
|
import { useCallback, useMemo } from "react";
|
|
12
10
|
import type { UserCredits } from "../../domain/entities/Credits";
|
|
@@ -65,37 +63,23 @@ export const useCredits = ({
|
|
|
65
63
|
|
|
66
64
|
const queryEnabled = enabled && !!userId && isConfigured;
|
|
67
65
|
|
|
68
|
-
if (__DEV__) {
|
|
69
|
-
console.log("[useCredits] Query state:", {
|
|
70
|
-
userId: userId?.slice(0, 8),
|
|
71
|
-
enabled,
|
|
72
|
-
isConfigured,
|
|
73
|
-
queryEnabled,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
66
|
const { data, isLoading, error, refetch } = useQuery({
|
|
78
67
|
queryKey: creditsQueryKeys.user(userId ?? ""),
|
|
79
68
|
queryFn: async () => {
|
|
80
69
|
if (!userId || !isConfigured) {
|
|
81
|
-
if (__DEV__) console.log("[useCredits] Query skipped:", { hasUserId: !!userId, isConfigured });
|
|
82
70
|
return null;
|
|
83
71
|
}
|
|
84
|
-
if (__DEV__) console.log("[useCredits] Executing queryFn for userId:", userId.slice(0, 8));
|
|
85
72
|
const repository = getCreditsRepository();
|
|
86
73
|
const result = await repository.getCredits(userId);
|
|
87
74
|
if (!result.success) {
|
|
88
|
-
if (__DEV__) console.error("[useCredits] Query failed:", result.error?.message);
|
|
89
75
|
throw new Error(result.error?.message || "Failed to fetch credits");
|
|
90
76
|
}
|
|
91
77
|
|
|
92
78
|
// Background sync: If mapper detected expired status, sync to Firestore
|
|
93
79
|
if (result.data?.status === "expired") {
|
|
94
|
-
if (__DEV__) console.log("[useCredits] Detected expired subscription, syncing...");
|
|
95
80
|
repository.syncExpiredStatus(userId).catch(() => {});
|
|
96
81
|
}
|
|
97
82
|
|
|
98
|
-
if (__DEV__) console.log("[useCredits] Query success:", { hasData: !!result.data, credits: result.data?.credits, status: result.data?.status });
|
|
99
83
|
return result.data || null;
|
|
100
84
|
},
|
|
101
85
|
enabled: queryEnabled,
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
|
|
22
22
|
import { useCallback } from "react";
|
|
23
23
|
|
|
24
|
-
declare const __DEV__: boolean;
|
|
25
|
-
|
|
26
24
|
export interface UseCreditsGateParams {
|
|
27
25
|
/** Whether user has enough credits for the action */
|
|
28
26
|
hasCredits: boolean;
|
|
@@ -52,27 +50,12 @@ export function useCreditsGate(
|
|
|
52
50
|
const requireCredits = useCallback(
|
|
53
51
|
(_action: () => void | Promise<void>): boolean => {
|
|
54
52
|
if (!hasCredits) {
|
|
55
|
-
if (__DEV__) {
|
|
56
|
-
|
|
57
|
-
console.log("[useCreditsGate] Insufficient credits", {
|
|
58
|
-
creditBalance,
|
|
59
|
-
requiredCredits,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
53
|
onCreditsRequired(requiredCredits);
|
|
63
54
|
return false;
|
|
64
55
|
}
|
|
65
|
-
|
|
66
|
-
if (__DEV__) {
|
|
67
|
-
|
|
68
|
-
console.log("[useCreditsGate] Has credits, proceeding", {
|
|
69
|
-
creditBalance,
|
|
70
|
-
requiredCredits,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
56
|
return true;
|
|
74
57
|
},
|
|
75
|
-
[hasCredits,
|
|
58
|
+
[hasCredits, requiredCredits, onCreditsRequired]
|
|
76
59
|
);
|
|
77
60
|
|
|
78
61
|
return {
|
|
@@ -57,21 +57,24 @@ export function useFeatureGate(
|
|
|
57
57
|
|
|
58
58
|
// Store pending action for execution after purchase
|
|
59
59
|
const pendingActionRef = useRef<(() => void | Promise<void>) | null>(null);
|
|
60
|
-
const
|
|
60
|
+
const prevCreditBalanceRef = useRef(creditBalance);
|
|
61
|
+
const isWaitingForPurchaseRef = useRef(false);
|
|
61
62
|
|
|
62
|
-
// Execute pending action when credits
|
|
63
|
+
// Execute pending action when credits increase after purchase
|
|
63
64
|
useEffect(() => {
|
|
64
|
-
const
|
|
65
|
-
const
|
|
65
|
+
const prevBalance = prevCreditBalanceRef.current;
|
|
66
|
+
const currentBalance = creditBalance;
|
|
67
|
+
const creditsIncreased = currentBalance > prevBalance;
|
|
66
68
|
|
|
67
|
-
if (
|
|
69
|
+
if (isWaitingForPurchaseRef.current && creditsIncreased && pendingActionRef.current) {
|
|
68
70
|
const action = pendingActionRef.current;
|
|
69
71
|
pendingActionRef.current = null;
|
|
72
|
+
isWaitingForPurchaseRef.current = false;
|
|
70
73
|
action();
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
|
|
74
|
-
}, [
|
|
76
|
+
prevCreditBalanceRef.current = creditBalance;
|
|
77
|
+
}, [creditBalance]);
|
|
75
78
|
|
|
76
79
|
// Compose individual gates
|
|
77
80
|
const authGate = useAuthGate({
|
|
@@ -110,6 +113,7 @@ export function useFeatureGate(
|
|
|
110
113
|
if (!creditsGate.requireCredits(() => {})) {
|
|
111
114
|
// Store pending action for execution after purchase
|
|
112
115
|
pendingActionRef.current = action;
|
|
116
|
+
isWaitingForPurchaseRef.current = true;
|
|
113
117
|
return;
|
|
114
118
|
}
|
|
115
119
|
|