From 5218dd41b98da00243e2ad5526d723e8ca52a55f Mon Sep 17 00:00:00 2001 From: Waleed Date: Mon, 8 Sep 2025 10:46:23 -0700 Subject: [PATCH] fix(notifications): increase precision on billing calculations (#1283) * update infra and remove railway * fix(notifications): increase precision on billing calculations * Revert "update infra and remove railway" This reverts commit d17603e8440a100d9d5a13fa8f5993e6dbfc1da0. * cleanup --- apps/sim/lib/billing/calculations/usage-monitor.ts | 4 ++-- apps/sim/lib/billing/core/billing.ts | 2 +- apps/sim/lib/billing/core/usage.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/sim/lib/billing/calculations/usage-monitor.ts b/apps/sim/lib/billing/calculations/usage-monitor.ts index 0c8155611b..aec227abee 100644 --- a/apps/sim/lib/billing/calculations/usage-monitor.ts +++ b/apps/sim/lib/billing/calculations/usage-monitor.ts @@ -35,7 +35,7 @@ export async function checkUsageStatus(userId: string): Promise { : 0 return { - percentUsed: Math.min(Math.round((currentUsage / 1000) * 100), 100), + percentUsed: Math.min((currentUsage / 1000) * 100, 100), isWarning: false, isExceeded: false, currentUsage, @@ -69,7 +69,7 @@ export async function checkUsageStatus(userId: string): Promise { ) // Calculate percentage used - const percentUsed = Math.min(Math.floor((currentUsage / limit) * 100), 100) + const percentUsed = Math.min((currentUsage / limit) * 100, 100) // Check org-level cap for team/enterprise pooled usage let isExceeded = currentUsage >= limit diff --git a/apps/sim/lib/billing/core/billing.ts b/apps/sim/lib/billing/core/billing.ts index c1e650b7f0..8e83594c03 100644 --- a/apps/sim/lib/billing/core/billing.ts +++ b/apps/sim/lib/billing/core/billing.ts @@ -267,7 +267,7 @@ export async function getSimplifiedBillingSummary( } const overageAmount = Math.max(0, currentUsage - basePrice) - const percentUsed = usageData.limit > 0 ? Math.round((currentUsage / usageData.limit) * 100) : 0 + const percentUsed = usageData.limit > 0 ? (currentUsage / usageData.limit) * 100 : 0 // Calculate days remaining in billing period const daysRemaining = usageData.billingPeriodEnd diff --git a/apps/sim/lib/billing/core/usage.ts b/apps/sim/lib/billing/core/usage.ts index ba2519d362..edf24b542c 100644 --- a/apps/sim/lib/billing/core/usage.ts +++ b/apps/sim/lib/billing/core/usage.ts @@ -86,7 +86,7 @@ export async function getUserUsageData(userId: string): Promise { } } - const percentUsed = limit > 0 ? Math.min(Math.floor((currentUsage / limit) * 100), 100) : 0 + const percentUsed = limit > 0 ? Math.min((currentUsage / limit) * 100, 100) : 0 const isWarning = percentUsed >= 80 const isExceeded = currentUsage >= limit