@umituz/react-native-subscription 2.17.7 → 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.7",
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",
@@ -47,13 +47,13 @@ export class CreditsRepository extends BaseRepository {
47
47
  }
48
48
  }
49
49
  const res = await initializeCreditsTransaction(db, this.getRef(db, userId), cfg, purchaseId);
50
- return {
51
- success: true,
50
+ return {
51
+ success: true,
52
52
  data: CreditsMapper.toEntity({
53
53
  ...res,
54
54
  purchasedAt: undefined,
55
55
  lastUpdatedAt: undefined,
56
- })
56
+ })
57
57
  };
58
58
  } catch (e: any) { return { success: false, error: { message: e.message, code: "INIT_ERR" } }; }
59
59
  }
@@ -57,7 +57,6 @@ export async function initializeCreditsTransaction(
57
57
  processedPurchases,
58
58
  };
59
59
 
60
- // Use merge:true to avoid overwriting other user fields
61
60
  transaction.set(creditsRef, creditsData, { merge: true });
62
61
 
63
62
  return { credits: newCredits };
@@ -64,14 +64,23 @@ export const useSubscriptionSettingsConfig = (
64
64
  const isPremium = !!premiumEntitlement || subscriptionActive;
65
65
 
66
66
  const dynamicCreditLimit = useMemo(() => {
67
- if (!premiumEntitlement?.productIdentifier) {
68
- return creditLimit;
69
- }
70
67
  const config = getCreditsConfig();
71
- const packageType = detectPackageType(premiumEntitlement.productIdentifier);
72
- const allocation = getCreditAllocation(packageType, config.packageAllocations);
73
- return allocation ?? creditLimit ?? config.creditLimit;
74
- }, [premiumEntitlement?.productIdentifier, creditLimit]);
68
+
69
+ if (premiumEntitlement?.productIdentifier) {
70
+ const packageType = detectPackageType(premiumEntitlement.productIdentifier);
71
+ const allocation = getCreditAllocation(packageType, config.packageAllocations);
72
+ if (allocation !== null) return allocation;
73
+ }
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;
80
+ }
81
+
82
+ return creditLimit ?? config.creditLimit;
83
+ }, [premiumEntitlement?.productIdentifier, credits?.credits, creditLimit]);
75
84
 
76
85
  // Get expiration date directly from RevenueCat (source of truth)
77
86
  const entitlementExpirationDate = premiumEntitlement?.expirationDate ?? null;