Skip to content

Commit 1479023

Browse files
committed
consistency
1 parent 9fa77ca commit 1479023

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

apps/sim/lib/billing/credits/balance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { member, organization, userStats } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
44
import { and, eq, sql } from 'drizzle-orm'
55
import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
6-
import { toDecimal, toFixedString, toNumber } from '@/lib/billing/utils/decimal'
6+
import { Decimal, toDecimal, toFixedString, toNumber } from '@/lib/billing/utils/decimal'
77

88
const logger = createLogger('CreditBalance')
99

@@ -162,7 +162,7 @@ export async function deductFromCredits(userId: string, cost: number): Promise<D
162162
creditsUsed = await atomicDeductUserCredits(userId, cost)
163163
}
164164

165-
const overflow = Math.max(0, cost - creditsUsed)
165+
const overflow = toNumber(Decimal.max(0, toDecimal(cost).minus(creditsUsed)))
166166

167167
if (creditsUsed > 0) {
168168
logger.info('Deducted credits atomically', {

0 commit comments

Comments
 (0)