@umituz/react-native-subscription 2.27.95 → 2.27.97
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/credits/core/Credits.ts +3 -11
- package/src/domains/credits/infrastructure/CreditsRepository.ts +28 -1
- package/src/domains/paywall/components/PaywallContainer.tsx +17 -1
- package/src/domains/paywall/components/PaywallContainer.types.ts +2 -1
- package/src/domains/paywall/hooks/usePaywallActions.ts +1 -1
- package/src/domains/subscription/application/SubscriptionInitializer.ts +1 -1
- package/src/domains/subscription/application/SubscriptionSyncService.ts +32 -5
- package/src/domains/subscription/application/SubscriptionSyncUtils.ts +1 -1
- package/src/domains/subscription/infrastructure/handlers/PackageHandler.ts +32 -12
- package/src/domains/subscription/infrastructure/hooks/subscriptionQueryKeys.ts +4 -4
- package/src/domains/subscription/infrastructure/hooks/useSubscriptionPackages.ts +1 -7
- package/src/domains/subscription/infrastructure/hooks/useSubscriptionQueries.ts +0 -2
- package/src/domains/subscription/infrastructure/managers/SubscriptionManager.ts +5 -4
- package/src/domains/subscription/infrastructure/utils/InitializationCache.ts +20 -7
- package/src/domains/subscription/infrastructure/utils/PremiumStatusSyncer.ts +1 -1
- package/src/domains/subscription/presentation/screens/SubscriptionDetailScreen.tsx +55 -16
- package/src/domains/subscription/presentation/screens/components/CreditsList.tsx +14 -1
- package/src/domains/subscription/presentation/screens/components/DevTestSection.tsx +10 -2
- package/src/domains/subscription/presentation/screens/components/SubscriptionActions.tsx +6 -1
- package/src/domains/subscription/presentation/screens/components/SubscriptionHeader.tsx +20 -1
- package/src/domains/subscription/presentation/screens/components/UpgradePrompt.tsx +13 -1
- package/src/domains/subscription/presentation/useAuthAwarePurchase.ts +1 -1
- package/src/domains/subscription/presentation/useFeatureGate.ts +11 -7
- package/src/domains/subscription/presentation/usePaywallVisibility.ts +1 -1
- package/src/domains/subscription/presentation/useSubscriptionStatus.ts +1 -5
- package/src/init/index.ts +0 -3
- package/src/presentation/hooks/index.ts +0 -4
- package/src/shared/infrastructure/SubscriptionEventBus.ts +27 -0
- package/src/types/i18next.d.ts +2 -0
- package/src/utils/packageTypeDetector.ts +0 -4
- package/src/domains/subscription/presentation/types/README.md +0 -22
- package/src/domains/subscription/presentation/types/SubscriptionDetailTypes.ts +0 -153
- package/src/domains/subscription/presentation/types/SubscriptionSettingsTypes.ts +0 -74
- package/src/domains/subscription/presentation/useAuthSubscriptionSync.ts +0 -63
- package/src/domains/subscription/presentation/usePremiumGate.ts +0 -84
- package/src/domains/subscription/presentation/useSavedPurchaseAutoExecution.ts +0 -148
- package/src/domains/subscription/presentation/useSubscriptionSettingsConfig.ts +0 -115
- package/src/domains/subscription/presentation/useSubscriptionSettingsConfig.utils.ts +0 -57
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useSubscriptionSettingsConfig Hook
|
|
3
|
-
* Returns ready-to-use config for settings screens
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useMemo, useCallback } from "react";
|
|
7
|
-
import { useCredits } from "../../credits/presentation/useCredits";
|
|
8
|
-
import { usePaywallVisibility } from "./usePaywallVisibility";
|
|
9
|
-
import { calculateDaysRemaining } from "../core/SubscriptionStatus";
|
|
10
|
-
import { formatDate } from "./utils/subscriptionDateUtils";
|
|
11
|
-
import { useCreditsArray, getSubscriptionStatusType } from "./useSubscriptionSettingsConfig.utils";
|
|
12
|
-
import { getCreditsConfig } from "../../credits/infrastructure/CreditsRepositoryProvider";
|
|
13
|
-
import type {
|
|
14
|
-
SubscriptionSettingsConfig,
|
|
15
|
-
SubscriptionStatusType,
|
|
16
|
-
UseSubscriptionSettingsConfigParams,
|
|
17
|
-
} from "./types/SubscriptionSettingsTypes";
|
|
18
|
-
|
|
19
|
-
export type {
|
|
20
|
-
SubscriptionSettingsConfig,
|
|
21
|
-
SubscriptionSettingsItemConfig,
|
|
22
|
-
SubscriptionSettingsTranslations,
|
|
23
|
-
UseSubscriptionSettingsConfigParams,
|
|
24
|
-
} from "./types/SubscriptionSettingsTypes";
|
|
25
|
-
|
|
26
|
-
export const useSubscriptionSettingsConfig = (
|
|
27
|
-
params: Omit<UseSubscriptionSettingsConfigParams, 'userId'>
|
|
28
|
-
): SubscriptionSettingsConfig => {
|
|
29
|
-
const { translations, creditLimit, upgradePrompt } = params;
|
|
30
|
-
|
|
31
|
-
const { credits } = useCredits();
|
|
32
|
-
const { openPaywall } = usePaywallVisibility();
|
|
33
|
-
|
|
34
|
-
const handleOpenPaywall = useCallback(() => {
|
|
35
|
-
openPaywall("settings");
|
|
36
|
-
}, [openPaywall]);
|
|
37
|
-
|
|
38
|
-
const isPremium = credits?.isPremium ?? false;
|
|
39
|
-
const willRenew = credits?.willRenew ?? false;
|
|
40
|
-
|
|
41
|
-
const expiresAtIso = credits?.expirationDate?.toISOString() ?? null;
|
|
42
|
-
const purchasedAtIso = credits?.purchasedAt?.toISOString() ?? null;
|
|
43
|
-
|
|
44
|
-
const dynamicCreditLimit = useMemo(() => {
|
|
45
|
-
if (credits?.creditLimit) return credits.creditLimit;
|
|
46
|
-
const config = getCreditsConfig();
|
|
47
|
-
return creditLimit ?? config.creditLimit;
|
|
48
|
-
}, [credits?.creditLimit, creditLimit]);
|
|
49
|
-
|
|
50
|
-
const formattedExpirationDate = useMemo(() => formatDate(expiresAtIso), [expiresAtIso]);
|
|
51
|
-
const formattedPurchaseDate = useMemo(() => formatDate(purchasedAtIso), [purchasedAtIso]);
|
|
52
|
-
|
|
53
|
-
const daysRemaining = useMemo(() => calculateDaysRemaining(expiresAtIso), [expiresAtIso]);
|
|
54
|
-
|
|
55
|
-
const periodType = credits?.periodType;
|
|
56
|
-
|
|
57
|
-
const statusType: SubscriptionStatusType = credits?.status
|
|
58
|
-
? (credits.status as SubscriptionStatusType)
|
|
59
|
-
: getSubscriptionStatusType(isPremium, willRenew, expiresAtIso, periodType);
|
|
60
|
-
|
|
61
|
-
const creditsArray = useCreditsArray(credits, dynamicCreditLimit, translations);
|
|
62
|
-
|
|
63
|
-
const hasCredits = creditsArray.length > 0;
|
|
64
|
-
const display = useMemo(() => ({
|
|
65
|
-
showHeader: isPremium || hasCredits,
|
|
66
|
-
showCredits: hasCredits,
|
|
67
|
-
showUpgradePrompt: !isPremium && !hasCredits && !!upgradePrompt,
|
|
68
|
-
showExpirationDate: (isPremium || hasCredits) && !!expiresAtIso,
|
|
69
|
-
}), [isPremium, hasCredits, upgradePrompt, expiresAtIso]);
|
|
70
|
-
|
|
71
|
-
return useMemo((): SubscriptionSettingsConfig => ({
|
|
72
|
-
enabled: true,
|
|
73
|
-
settingsItem: {
|
|
74
|
-
title: translations.title,
|
|
75
|
-
description: translations.description,
|
|
76
|
-
isPremium,
|
|
77
|
-
statusLabel: isPremium ? translations.statusActive : translations.statusInactive,
|
|
78
|
-
icon: "diamond",
|
|
79
|
-
onPress: handleOpenPaywall,
|
|
80
|
-
},
|
|
81
|
-
sectionConfig: {
|
|
82
|
-
statusType,
|
|
83
|
-
isPremium,
|
|
84
|
-
display,
|
|
85
|
-
expirationDate: formattedExpirationDate,
|
|
86
|
-
purchaseDate: formattedPurchaseDate,
|
|
87
|
-
isLifetime: isPremium && !expiresAtIso,
|
|
88
|
-
daysRemaining,
|
|
89
|
-
willRenew,
|
|
90
|
-
credits: creditsArray,
|
|
91
|
-
translations: {
|
|
92
|
-
title: translations.title,
|
|
93
|
-
statusLabel: translations.statusLabel,
|
|
94
|
-
statusActive: translations.statusActive,
|
|
95
|
-
statusExpired: translations.statusExpired,
|
|
96
|
-
statusInactive: translations.statusInactive,
|
|
97
|
-
statusCanceled: translations.statusCanceled,
|
|
98
|
-
statusFree: translations.statusInactive,
|
|
99
|
-
expiresLabel: translations.expiresLabel,
|
|
100
|
-
purchasedLabel: translations.purchasedLabel,
|
|
101
|
-
lifetimeLabel: translations.lifetimeLabel,
|
|
102
|
-
creditsTitle: translations.creditsTitle,
|
|
103
|
-
remainingLabel: translations.remainingLabel,
|
|
104
|
-
manageButton: translations.manageButton,
|
|
105
|
-
upgradeButton: translations.upgradeButton,
|
|
106
|
-
},
|
|
107
|
-
onUpgrade: handleOpenPaywall,
|
|
108
|
-
upgradePrompt,
|
|
109
|
-
},
|
|
110
|
-
}), [
|
|
111
|
-
translations, isPremium, statusType, display, formattedExpirationDate,
|
|
112
|
-
formattedPurchaseDate, expiresAtIso, daysRemaining, willRenew,
|
|
113
|
-
creditsArray, handleOpenPaywall, upgradePrompt,
|
|
114
|
-
]);
|
|
115
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useSubscriptionSettingsConfig Utilities
|
|
3
|
-
* Helper functions for subscription settings config
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useMemo } from "react";
|
|
7
|
-
import type { UserCredits } from "../../credits/core/Credits";
|
|
8
|
-
import { resolveSubscriptionStatus, type PeriodType, type SubscriptionStatusType } from "../core/SubscriptionStatus";
|
|
9
|
-
import type { SubscriptionSettingsTranslations } from "./types/SubscriptionSettingsTypes";
|
|
10
|
-
|
|
11
|
-
export interface CreditsInfo {
|
|
12
|
-
id: string;
|
|
13
|
-
label: string;
|
|
14
|
-
current: number;
|
|
15
|
-
total: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Builds credits array for display
|
|
20
|
-
*/
|
|
21
|
-
export function useCreditsArray(
|
|
22
|
-
credits: UserCredits | null | undefined,
|
|
23
|
-
creditLimit: number | undefined,
|
|
24
|
-
translations: SubscriptionSettingsTranslations
|
|
25
|
-
): CreditsInfo[] {
|
|
26
|
-
return useMemo(() => {
|
|
27
|
-
if (!credits) return [];
|
|
28
|
-
const validCredits = isNaN(credits.credits) ? 0 : credits.credits;
|
|
29
|
-
return [
|
|
30
|
-
{
|
|
31
|
-
id: "credits",
|
|
32
|
-
label: translations.creditsLabel,
|
|
33
|
-
current: validCredits,
|
|
34
|
-
total: creditLimit ?? validCredits,
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
}, [credits, creditLimit, translations.creditsLabel]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Calculates subscription status type based on premium, renewal status, and period type
|
|
42
|
-
*/
|
|
43
|
-
export function getSubscriptionStatusType(
|
|
44
|
-
isPremium: boolean,
|
|
45
|
-
willRenew?: boolean,
|
|
46
|
-
expiresAt?: string | null,
|
|
47
|
-
periodType?: PeriodType
|
|
48
|
-
): SubscriptionStatusType {
|
|
49
|
-
const isExpired = expiresAt ? new Date(expiresAt) < new Date() : false;
|
|
50
|
-
|
|
51
|
-
return resolveSubscriptionStatus({
|
|
52
|
-
isPremium,
|
|
53
|
-
willRenew,
|
|
54
|
-
isExpired,
|
|
55
|
-
periodType,
|
|
56
|
-
});
|
|
57
|
-
}
|