@umituz/react-native-subscription 2.37.81 → 2.37.83
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 +1 -1
- package/src/domains/subscription/infrastructure/hooks/useRestorePurchase.ts +1 -3
- package/src/domains/subscription/presentation/useSubscriptionStatus.ts +7 -8
- package/src/domains/subscription/utils/authGuards.ts +0 -4
- package/src/domains/wallet/presentation/hooks/useTransactionHistory.ts +4 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.37.
|
|
3
|
+
"version": "2.37.83",
|
|
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,6 @@ import { useAlert } from "@umituz/react-native-design-system/molecules";
|
|
|
3
3
|
import {
|
|
4
4
|
useAuthStore,
|
|
5
5
|
selectUserId,
|
|
6
|
-
selectIsAnonymous,
|
|
7
6
|
} from "@umituz/react-native-auth";
|
|
8
7
|
import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionManager";
|
|
9
8
|
import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
|
|
@@ -18,13 +17,12 @@ interface RestoreResult {
|
|
|
18
17
|
|
|
19
18
|
export const useRestorePurchase = () => {
|
|
20
19
|
const userId = useAuthStore(selectUserId);
|
|
21
|
-
const isAnonymous = useAuthStore(selectIsAnonymous);
|
|
22
20
|
const queryClient = useQueryClient();
|
|
23
21
|
const { showSuccess, showInfo, showError } = useAlert();
|
|
24
22
|
|
|
25
23
|
return useMutation({
|
|
26
24
|
mutationFn: async (): Promise<RestoreResult> => {
|
|
27
|
-
if (!userId
|
|
25
|
+
if (!userId) {
|
|
28
26
|
throw new Error("User not authenticated");
|
|
29
27
|
}
|
|
30
28
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useQuery, useQueryClient } from "@umituz/react-native-design-system/tanstack";
|
|
2
2
|
import { useEffect, useSyncExternalStore } from "react";
|
|
3
|
-
import { useAuthStore, selectUserId
|
|
3
|
+
import { useAuthStore, selectUserId } from "@umituz/react-native-auth";
|
|
4
4
|
import { SubscriptionManager } from "../infrastructure/managers/SubscriptionManager";
|
|
5
5
|
import { initializationState } from "../infrastructure/state/initializationState";
|
|
6
6
|
import { subscriptionEventBus, SUBSCRIPTION_EVENTS } from "../../../shared/infrastructure/SubscriptionEventBus";
|
|
7
7
|
import { SubscriptionStatusResult } from "./useSubscriptionStatus.types";
|
|
8
|
-
import {
|
|
8
|
+
import { isAuthenticated } from "../utils/authGuards";
|
|
9
9
|
import { NO_CACHE_QUERY_CONFIG } from "../../../shared/infrastructure/react-query/queryConfig";
|
|
10
10
|
import { usePreviousUserCleanup } from "../../../shared/infrastructure/react-query/hooks/usePreviousUserCleanup";
|
|
11
11
|
|
|
@@ -17,10 +17,9 @@ export const subscriptionStatusQueryKeys = {
|
|
|
17
17
|
|
|
18
18
|
export const useSubscriptionStatus = (): SubscriptionStatusResult => {
|
|
19
19
|
const userId = useAuthStore(selectUserId);
|
|
20
|
-
const isAnonymous = useAuthStore(selectIsAnonymous);
|
|
21
20
|
const queryClient = useQueryClient();
|
|
22
21
|
const isConfigured = SubscriptionManager.isConfigured();
|
|
23
|
-
const
|
|
22
|
+
const hasUser = isAuthenticated(userId);
|
|
24
23
|
|
|
25
24
|
const initState = useSyncExternalStore(
|
|
26
25
|
initializationState.subscribe,
|
|
@@ -32,12 +31,12 @@ export const useSubscriptionStatus = (): SubscriptionStatusResult => {
|
|
|
32
31
|
? initState.initialized && initState.userId === userId
|
|
33
32
|
: false;
|
|
34
33
|
|
|
35
|
-
const queryEnabled =
|
|
34
|
+
const queryEnabled = hasUser && isConfigured && isInitialized;
|
|
36
35
|
|
|
37
36
|
const { data, status, error, refetch } = useQuery({
|
|
38
37
|
queryKey: subscriptionStatusQueryKeys.user(userId),
|
|
39
38
|
queryFn: async () => {
|
|
40
|
-
if (!
|
|
39
|
+
if (!hasUser) {
|
|
41
40
|
return null;
|
|
42
41
|
}
|
|
43
42
|
|
|
@@ -50,7 +49,7 @@ export const useSubscriptionStatus = (): SubscriptionStatusResult => {
|
|
|
50
49
|
usePreviousUserCleanup(userId, queryClient, subscriptionStatusQueryKeys.user);
|
|
51
50
|
|
|
52
51
|
useEffect(() => {
|
|
53
|
-
if (!
|
|
52
|
+
if (!hasUser) return undefined;
|
|
54
53
|
|
|
55
54
|
const unsubscribe = subscriptionEventBus.on(
|
|
56
55
|
SUBSCRIPTION_EVENTS.PREMIUM_STATUS_CHANGED,
|
|
@@ -64,7 +63,7 @@ export const useSubscriptionStatus = (): SubscriptionStatusResult => {
|
|
|
64
63
|
);
|
|
65
64
|
|
|
66
65
|
return unsubscribe;
|
|
67
|
-
}, [userId,
|
|
66
|
+
}, [userId, hasUser, queryClient]);
|
|
68
67
|
|
|
69
68
|
const isLoading = status === "pending";
|
|
70
69
|
|
|
@@ -3,7 +3,3 @@ import { isDefined } from "../../../shared/utils/validators";
|
|
|
3
3
|
export function isAuthenticated(userId: string | null | undefined): userId is string {
|
|
4
4
|
return isDefined(userId) && userId.length > 0;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
export function isRegisteredUser(userId: string | null | undefined, isAnonymous: boolean): userId is string {
|
|
8
|
-
return isAuthenticated(userId) && !isAnonymous;
|
|
9
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useQuery } from "@umituz/react-native-design-system/tanstack";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
-
import { useAuthStore, selectUserId
|
|
3
|
+
import { useAuthStore, selectUserId } from "@umituz/react-native-auth";
|
|
4
4
|
import { NO_CACHE_QUERY_CONFIG } from "../../../../shared/infrastructure/react-query/queryConfig";
|
|
5
5
|
import type {
|
|
6
6
|
CreditLog,
|
|
@@ -31,19 +31,18 @@ export function useTransactionHistory({
|
|
|
31
31
|
limit = 50,
|
|
32
32
|
}: UseTransactionHistoryParams): UseTransactionHistoryResult {
|
|
33
33
|
const userId = useAuthStore(selectUserId);
|
|
34
|
-
const isAnonymous = useAuthStore(selectIsAnonymous);
|
|
35
34
|
|
|
36
35
|
const repository = useMemo(
|
|
37
36
|
() => new TransactionRepository(config),
|
|
38
37
|
[config]
|
|
39
38
|
);
|
|
40
39
|
|
|
41
|
-
const
|
|
40
|
+
const hasUser = !!userId;
|
|
42
41
|
|
|
43
42
|
const { data, isLoading, error, refetch } = useQuery({
|
|
44
43
|
queryKey: [...transactionQueryKeys.user(userId ?? ""), limit],
|
|
45
44
|
queryFn: async () => {
|
|
46
|
-
if (!userId
|
|
45
|
+
if (!userId) return [];
|
|
47
46
|
|
|
48
47
|
const result = await repository.getTransactions({
|
|
49
48
|
userId,
|
|
@@ -56,7 +55,7 @@ export function useTransactionHistory({
|
|
|
56
55
|
|
|
57
56
|
return result.data ?? [];
|
|
58
57
|
},
|
|
59
|
-
enabled:
|
|
58
|
+
enabled: hasUser,
|
|
60
59
|
...NO_CACHE_QUERY_CONFIG,
|
|
61
60
|
});
|
|
62
61
|
|