@umituz/react-native-subscription 2.17.8 → 2.17.9

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.17.8",
3
+ "version": "2.17.9",
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",
@@ -13,8 +13,6 @@ export interface UserCredits {
13
13
  credits: number;
14
14
  purchasedAt: Date | null;
15
15
  lastUpdatedAt: Date | null;
16
- activeProductId?: string;
17
- activeCreditLimit?: number;
18
16
  }
19
17
 
20
18
  export interface CreditAllocation {
@@ -7,8 +7,6 @@ export class CreditsMapper {
7
7
  credits: snapData.credits,
8
8
  purchasedAt: snapData.purchasedAt?.toDate?.() || null,
9
9
  lastUpdatedAt: snapData.lastUpdatedAt?.toDate?.() || null,
10
- activeProductId: snapData.activeProductId,
11
- activeCreditLimit: snapData.activeCreditLimit,
12
10
  };
13
11
  }
14
12
 
@@ -10,6 +10,4 @@ export interface UserCreditsDocumentRead {
10
10
  lastUpdatedAt?: FirestoreTimestamp;
11
11
  lastPurchaseAt?: FirestoreTimestamp;
12
12
  processedPurchases?: string[];
13
- activeProductId?: string;
14
- activeCreditLimit?: number;
15
13
  }
@@ -46,7 +46,7 @@ export class CreditsRepository extends BaseRepository {
46
46
  if (dynamicLimit !== null) cfg = { ...cfg, creditLimit: dynamicLimit };
47
47
  }
48
48
  }
49
- const res = await initializeCreditsTransaction(db, this.getRef(db, userId), cfg, purchaseId, productId);
49
+ const res = await initializeCreditsTransaction(db, this.getRef(db, userId), cfg, purchaseId);
50
50
  return {
51
51
  success: true,
52
52
  data: CreditsMapper.toEntity({
@@ -17,8 +17,7 @@ export async function initializeCreditsTransaction(
17
17
  db: Firestore,
18
18
  creditsRef: DocumentReference,
19
19
  config: CreditsConfig,
20
- purchaseId?: string,
21
- productId?: string
20
+ purchaseId?: string
22
21
  ): Promise<InitializationResult> {
23
22
  return runTransaction(db, async (transaction: Transaction) => {
24
23
  const creditsDoc = await transaction.get(creditsRef);
@@ -56,11 +55,8 @@ export async function initializeCreditsTransaction(
56
55
  lastUpdatedAt: now,
57
56
  lastPurchaseAt: now,
58
57
  processedPurchases,
59
- activeProductId: productId || undefined,
60
- activeCreditLimit: config.creditLimit,
61
58
  };
62
59
 
63
- // Use merge:true to avoid overwriting other user fields
64
60
  transaction.set(creditsRef, creditsData, { merge: true });
65
61
 
66
62
  return { credits: newCredits };
@@ -64,17 +64,23 @@ export const useSubscriptionSettingsConfig = (
64
64
  const isPremium = !!premiumEntitlement || subscriptionActive;
65
65
 
66
66
  const dynamicCreditLimit = useMemo(() => {
67
- if (credits?.activeCreditLimit) {
68
- return credits.activeCreditLimit;
67
+ const config = getCreditsConfig();
68
+
69
+ if (premiumEntitlement?.productIdentifier) {
70
+ const packageType = detectPackageType(premiumEntitlement.productIdentifier);
71
+ const allocation = getCreditAllocation(packageType, config.packageAllocations);
72
+ if (allocation !== null) return allocation;
69
73
  }
70
- if (!premiumEntitlement?.productIdentifier) {
71
- return creditLimit;
74
+
75
+ if (credits?.credits && config.packageAllocations) {
76
+ const currentCredits = credits.credits;
77
+ const allocations = Object.values(config.packageAllocations).map(a => a.credits);
78
+ const closest = allocations.find(a => a >= currentCredits) || Math.max(...allocations);
79
+ return closest;
72
80
  }
73
- const config = getCreditsConfig();
74
- const packageType = detectPackageType(premiumEntitlement.productIdentifier);
75
- const allocation = getCreditAllocation(packageType, config.packageAllocations);
76
- return allocation ?? creditLimit ?? config.creditLimit;
77
- }, [credits?.activeCreditLimit, premiumEntitlement?.productIdentifier, creditLimit]);
81
+
82
+ return creditLimit ?? config.creditLimit;
83
+ }, [premiumEntitlement?.productIdentifier, credits?.credits, creditLimit]);
78
84
 
79
85
  // Get expiration date directly from RevenueCat (source of truth)
80
86
  const entitlementExpirationDate = premiumEntitlement?.expirationDate ?? null;