@umituz/react-native-subscription 2.2.2 → 2.2.4
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.2.
|
|
3
|
+
"version": "2.2.4",
|
|
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",
|
|
@@ -58,4 +58,4 @@
|
|
|
58
58
|
"README.md",
|
|
59
59
|
"LICENSE"
|
|
60
60
|
]
|
|
61
|
-
}
|
|
61
|
+
}
|
|
@@ -99,12 +99,14 @@ export function useFeatureGate(
|
|
|
99
99
|
onShowAuthModal(() => {
|
|
100
100
|
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
101
101
|
// eslint-disable-next-line no-console
|
|
102
|
-
console.log(
|
|
102
|
+
console.log(
|
|
103
|
+
"[useFeatureGate] Auth successful. Component will re-render to check premium status."
|
|
104
|
+
);
|
|
103
105
|
}
|
|
104
|
-
//
|
|
105
|
-
// The component will re-render with new auth state
|
|
106
|
-
// and user
|
|
107
|
-
|
|
106
|
+
// We NO LONGER call action() blindly here.
|
|
107
|
+
// The component will re-render with the new auth state,
|
|
108
|
+
// and the user should be allowed to try the action again.
|
|
109
|
+
// This avoids executing actions before credits are loaded or verified.
|
|
108
110
|
});
|
|
109
111
|
return;
|
|
110
112
|
}
|
|
@@ -17,10 +17,17 @@ export interface CreditCheckResult {
|
|
|
17
17
|
export interface CreditCheckerConfig {
|
|
18
18
|
repository: CreditsRepository;
|
|
19
19
|
getCreditType: (operationType: string) => CreditType;
|
|
20
|
+
/**
|
|
21
|
+
* Optional callback called after successful credit deduction.
|
|
22
|
+
* Use this to invalidate TanStack Query cache or trigger UI updates.
|
|
23
|
+
* @param userId - The user whose credits were deducted
|
|
24
|
+
* @param creditType - The type of credit that was deducted
|
|
25
|
+
*/
|
|
26
|
+
onCreditDeducted?: (userId: string, creditType: CreditType) => void;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
export const createCreditChecker = (config: CreditCheckerConfig) => {
|
|
23
|
-
const { repository, getCreditType } = config;
|
|
30
|
+
const { repository, getCreditType, onCreditDeducted } = config;
|
|
24
31
|
|
|
25
32
|
const checkCreditsAvailable = async (
|
|
26
33
|
userId: string | undefined,
|
|
@@ -59,6 +66,8 @@ export const createCreditChecker = (config: CreditCheckerConfig) => {
|
|
|
59
66
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
60
67
|
const result = await repository.deductCredit(userId, creditType);
|
|
61
68
|
if (result.success) {
|
|
69
|
+
// Notify subscribers that credits were deducted
|
|
70
|
+
onCreditDeducted?.(userId, creditType);
|
|
62
71
|
return;
|
|
63
72
|
}
|
|
64
73
|
lastError = new Error(result.error?.message || "Deduction failed");
|
|
@@ -77,3 +86,4 @@ export const createCreditChecker = (config: CreditCheckerConfig) => {
|
|
|
77
86
|
};
|
|
78
87
|
|
|
79
88
|
export type CreditChecker = ReturnType<typeof createCreditChecker>;
|
|
89
|
+
|