@umituz/react-native-subscription 2.33.4 → 2.33.6
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.33.
|
|
3
|
+
"version": "2.33.6",
|
|
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,7 +5,7 @@ import type { CreditsRepository } from "../../infrastructure/CreditsRepository";
|
|
|
5
5
|
import { creditsQueryKeys } from "../creditsQueryKeys";
|
|
6
6
|
import { calculateRemaining } from "../../../../shared/utils/numberUtils";
|
|
7
7
|
|
|
8
|
-
interface MutationContext {
|
|
8
|
+
export interface MutationContext {
|
|
9
9
|
previousCredits: UserCredits | null;
|
|
10
10
|
skippedOptimistic: boolean;
|
|
11
11
|
wasInsufficient?: boolean;
|
|
@@ -2,7 +2,8 @@ import { useCallback } from "react";
|
|
|
2
2
|
import { useMutation, useQueryClient } from "@umituz/react-native-design-system";
|
|
3
3
|
import { getCreditsRepository } from "../../infrastructure/CreditsRepositoryManager";
|
|
4
4
|
import type { UseDeductCreditParams, UseDeductCreditResult } from "./types";
|
|
5
|
-
import {
|
|
5
|
+
import type { DeductCreditsResult } from "../../core/Credits";
|
|
6
|
+
import { createDeductCreditMutationConfig, type MutationContext } from "./mutationConfig";
|
|
6
7
|
|
|
7
8
|
export const useDeductCredit = ({
|
|
8
9
|
userId,
|
|
@@ -11,7 +12,9 @@ export const useDeductCredit = ({
|
|
|
11
12
|
const repository = getCreditsRepository();
|
|
12
13
|
const queryClient = useQueryClient();
|
|
13
14
|
|
|
14
|
-
const mutation = useMutation
|
|
15
|
+
const mutation = useMutation<DeductCreditsResult, Error, number, MutationContext>(
|
|
16
|
+
createDeductCreditMutationConfig(userId, repository, queryClient)
|
|
17
|
+
);
|
|
15
18
|
|
|
16
19
|
const deductCredit = useCallback(async (cost: number = 1): Promise<boolean> => {
|
|
17
20
|
try {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { MutableRefObject } from "react";
|
|
2
2
|
|
|
3
|
+
declare const __DEV__: boolean;
|
|
4
|
+
|
|
3
5
|
export const executeFeatureAction = (
|
|
4
6
|
action: () => void | Promise<void>,
|
|
5
7
|
isAuthenticated: boolean,
|
|
@@ -13,20 +15,45 @@ export const executeFeatureAction = (
|
|
|
13
15
|
isWaitingForPurchaseRef: MutableRefObject<boolean>,
|
|
14
16
|
isCreditsLoadedRef: MutableRefObject<boolean>
|
|
15
17
|
): void => {
|
|
18
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
19
|
+
console.log("[FeatureGate] executeFeatureAction called:", {
|
|
20
|
+
isAuthenticated,
|
|
21
|
+
hasSubscription: hasSubscriptionRef.current,
|
|
22
|
+
creditBalance: creditBalanceRef.current,
|
|
23
|
+
requiredCredits: requiredCreditsRef.current,
|
|
24
|
+
isCreditsLoaded: isCreditsLoadedRef.current,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
if (!isAuthenticated) {
|
|
29
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
30
|
+
console.log("[FeatureGate] User not authenticated, showing auth modal");
|
|
31
|
+
}
|
|
17
32
|
const postAuthAction = () => {
|
|
33
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
34
|
+
console.log("[FeatureGate] Post-auth action called");
|
|
35
|
+
}
|
|
18
36
|
if (hasSubscriptionRef.current || creditBalanceRef.current >= requiredCreditsRef.current) {
|
|
37
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
38
|
+
console.log("[FeatureGate] Post-auth: User has access, executing action");
|
|
39
|
+
}
|
|
19
40
|
action();
|
|
20
41
|
return;
|
|
21
42
|
}
|
|
22
43
|
|
|
23
44
|
if (isCreditsLoadedRef.current) {
|
|
45
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
46
|
+
console.log("[FeatureGate] Post-auth: Credits loaded, showing paywall");
|
|
47
|
+
}
|
|
24
48
|
pendingActionRef.current = action;
|
|
25
49
|
isWaitingForPurchaseRef.current = true;
|
|
26
50
|
onShowPaywallRef.current(requiredCreditsRef.current);
|
|
27
51
|
return;
|
|
28
52
|
}
|
|
29
53
|
|
|
54
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
55
|
+
console.log("[FeatureGate] Post-auth: Waiting for credits to load");
|
|
56
|
+
}
|
|
30
57
|
pendingActionRef.current = action;
|
|
31
58
|
isWaitingForAuthCreditsRef.current = true;
|
|
32
59
|
};
|
|
@@ -35,16 +62,25 @@ export const executeFeatureAction = (
|
|
|
35
62
|
}
|
|
36
63
|
|
|
37
64
|
if (hasSubscriptionRef.current) {
|
|
65
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
66
|
+
console.log("[FeatureGate] User has subscription, executing action");
|
|
67
|
+
}
|
|
38
68
|
action();
|
|
39
69
|
return;
|
|
40
70
|
}
|
|
41
71
|
|
|
42
72
|
if (creditBalanceRef.current < requiredCreditsRef.current) {
|
|
73
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
74
|
+
console.log("[FeatureGate] Insufficient credits, showing paywall");
|
|
75
|
+
}
|
|
43
76
|
pendingActionRef.current = action;
|
|
44
77
|
isWaitingForPurchaseRef.current = true;
|
|
45
78
|
onShowPaywallRef.current(requiredCreditsRef.current);
|
|
46
79
|
return;
|
|
47
80
|
}
|
|
48
81
|
|
|
82
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
83
|
+
console.log("[FeatureGate] User has enough credits, executing action");
|
|
84
|
+
}
|
|
49
85
|
action();
|
|
50
86
|
};
|