@umituz/react-native-subscription 2.31.12 → 2.31.13
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.31.
|
|
3
|
+
"version": "2.31.13",
|
|
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",
|
|
@@ -10,10 +10,23 @@ export const executeFeatureAction = (
|
|
|
10
10
|
onShowPaywallRef: MutableRefObject<(requiredCredits?: number) => void>,
|
|
11
11
|
pendingActionRef: MutableRefObject<(() => void | Promise<void>) | null>,
|
|
12
12
|
isWaitingForAuthCreditsRef: MutableRefObject<boolean>,
|
|
13
|
-
isWaitingForPurchaseRef: MutableRefObject<boolean
|
|
13
|
+
isWaitingForPurchaseRef: MutableRefObject<boolean>,
|
|
14
|
+
isCreditsLoadedRef: MutableRefObject<boolean>
|
|
14
15
|
): void => {
|
|
15
16
|
if (!isAuthenticated) {
|
|
16
17
|
const postAuthAction = () => {
|
|
18
|
+
if (hasSubscriptionRef.current || creditBalanceRef.current >= requiredCreditsRef.current) {
|
|
19
|
+
action();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isCreditsLoadedRef.current) {
|
|
24
|
+
pendingActionRef.current = action;
|
|
25
|
+
isWaitingForPurchaseRef.current = true;
|
|
26
|
+
onShowPaywallRef.current(requiredCreditsRef.current);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
pendingActionRef.current = action;
|
|
18
31
|
isWaitingForAuthCreditsRef.current = true;
|
|
19
32
|
};
|
|
@@ -5,23 +5,27 @@ export interface FeatureGateRefs {
|
|
|
5
5
|
hasSubscriptionRef: MutableRefObject<boolean>;
|
|
6
6
|
onShowPaywallRef: MutableRefObject<(requiredCredits?: number) => void>;
|
|
7
7
|
requiredCreditsRef: MutableRefObject<number>;
|
|
8
|
+
isCreditsLoadedRef: MutableRefObject<boolean>;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const useSyncedRefs = (
|
|
11
12
|
creditBalance: number,
|
|
12
13
|
hasSubscription: boolean,
|
|
13
14
|
onShowPaywall: (requiredCredits?: number) => void,
|
|
14
|
-
requiredCredits: number
|
|
15
|
+
requiredCredits: number,
|
|
16
|
+
isCreditsLoaded: boolean
|
|
15
17
|
): FeatureGateRefs => {
|
|
16
18
|
const creditBalanceRef = useRef(creditBalance);
|
|
17
19
|
const hasSubscriptionRef = useRef(hasSubscription);
|
|
18
20
|
const onShowPaywallRef = useRef(onShowPaywall);
|
|
19
21
|
const requiredCreditsRef = useRef(requiredCredits);
|
|
22
|
+
const isCreditsLoadedRef = useRef(isCreditsLoaded);
|
|
20
23
|
|
|
21
24
|
useEffect(() => { creditBalanceRef.current = creditBalance; }, [creditBalance]);
|
|
22
25
|
useEffect(() => { hasSubscriptionRef.current = hasSubscription; }, [hasSubscription]);
|
|
23
26
|
useEffect(() => { onShowPaywallRef.current = onShowPaywall; }, [onShowPaywall]);
|
|
24
27
|
useEffect(() => { requiredCreditsRef.current = requiredCredits; }, [requiredCredits]);
|
|
28
|
+
useEffect(() => { isCreditsLoadedRef.current = isCreditsLoaded; }, [isCreditsLoaded]);
|
|
25
29
|
|
|
26
|
-
return { creditBalanceRef, hasSubscriptionRef, onShowPaywallRef, requiredCreditsRef };
|
|
30
|
+
return { creditBalanceRef, hasSubscriptionRef, onShowPaywallRef, requiredCreditsRef, isCreditsLoadedRef };
|
|
27
31
|
};
|
|
@@ -22,7 +22,7 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
|
|
|
22
22
|
const isWaitingForPurchaseRef = useRef(false);
|
|
23
23
|
const isWaitingForAuthCreditsRef = useRef(false);
|
|
24
24
|
|
|
25
|
-
const { creditBalanceRef, hasSubscriptionRef, onShowPaywallRef, requiredCreditsRef } = useSyncedRefs(creditBalance, hasSubscription, onShowPaywall, requiredCredits);
|
|
25
|
+
const { creditBalanceRef, hasSubscriptionRef, onShowPaywallRef, requiredCreditsRef, isCreditsLoadedRef } = useSyncedRefs(creditBalance, hasSubscription, onShowPaywall, requiredCredits, isCreditsLoaded);
|
|
26
26
|
|
|
27
27
|
useEffect(() => {
|
|
28
28
|
if (shouldExecuteAuthAction(
|
|
@@ -79,10 +79,11 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
|
|
|
79
79
|
onShowPaywallRef,
|
|
80
80
|
pendingActionRef,
|
|
81
81
|
isWaitingForAuthCreditsRef,
|
|
82
|
-
isWaitingForPurchaseRef
|
|
82
|
+
isWaitingForPurchaseRef,
|
|
83
|
+
isCreditsLoadedRef
|
|
83
84
|
);
|
|
84
85
|
},
|
|
85
|
-
[isAuthenticated, onShowAuthModal, hasSubscriptionRef, creditBalanceRef, requiredCreditsRef, onShowPaywallRef]
|
|
86
|
+
[isAuthenticated, onShowAuthModal, hasSubscriptionRef, creditBalanceRef, requiredCreditsRef, onShowPaywallRef, isCreditsLoadedRef]
|
|
86
87
|
);
|
|
87
88
|
|
|
88
89
|
return {
|