Skip to content

Commit 5218dd4

Browse files
authored
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 d17603e. * cleanup
1 parent 07e7040 commit 5218dd4

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

apps/sim/lib/billing/calculations/usage-monitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function checkUsageStatus(userId: string): Promise<UsageData> {
3535
: 0
3636

3737
return {
38-
percentUsed: Math.min(Math.round((currentUsage / 1000) * 100), 100),
38+
percentUsed: Math.min((currentUsage / 1000) * 100, 100),
3939
isWarning: false,
4040
isExceeded: false,
4141
currentUsage,
@@ -69,7 +69,7 @@ export async function checkUsageStatus(userId: string): Promise<UsageData> {
6969
)
7070

7171
// Calculate percentage used
72-
const percentUsed = Math.min(Math.floor((currentUsage / limit) * 100), 100)
72+
const percentUsed = Math.min((currentUsage / limit) * 100, 100)
7373

7474
// Check org-level cap for team/enterprise pooled usage
7575
let isExceeded = currentUsage >= limit

apps/sim/lib/billing/core/billing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export async function getSimplifiedBillingSummary(
267267
}
268268

269269
const overageAmount = Math.max(0, currentUsage - basePrice)
270-
const percentUsed = usageData.limit > 0 ? Math.round((currentUsage / usageData.limit) * 100) : 0
270+
const percentUsed = usageData.limit > 0 ? (currentUsage / usageData.limit) * 100 : 0
271271

272272
// Calculate days remaining in billing period
273273
const daysRemaining = usageData.billingPeriodEnd

apps/sim/lib/billing/core/usage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function getUserUsageData(userId: string): Promise<UsageData> {
8686
}
8787
}
8888

89-
const percentUsed = limit > 0 ? Math.min(Math.floor((currentUsage / limit) * 100), 100) : 0
89+
const percentUsed = limit > 0 ? Math.min((currentUsage / limit) * 100, 100) : 0
9090
const isWarning = percentUsed >= 80
9191
const isExceeded = currentUsage >= limit
9292

0 commit comments

Comments
 (0)