Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update: credit conversion rate from 210 to 211 credits per USD
- Update CREDITS_PER_USD constant and all dependent calculations
- Update test expectations to match new conversion rate
- Update subscription conversion comments and test values
  • Loading branch information
christian-byrne committed Dec 9, 2025
commit 3cf8c9d155e52b59664da56ab2c294012d30a27c
4 changes: 2 additions & 2 deletions src/base/credits/comfyCredits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const formatNumber = ({
return new Intl.NumberFormat(locale, merged).format(value)
}

export const CREDITS_PER_USD = 210
export const CREDITS_PER_USD = 211
export const COMFY_CREDIT_RATE_CENTS = CREDITS_PER_USD / 100 // credits per cent

export const usdToCents = (usd: number): number => Math.round(usd * 100)
Expand Down Expand Up @@ -93,7 +93,7 @@ export const formatCreditsFromUsd = ({
})

// Special conversion for subscription backend data
// Backend sends values as "micros" but they are really in a special format where 210 units = 1 credit
// Backend sends values as "micros" but they are really in a special format where 211 units = 1 credit
export const formatCreditsFromSubscriptionMicros = ({
micros,
locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useSubscriptionCredits() {

const formatBalance = (maybeMicros?: number) => {
// Backend returns special units despite the *_micros naming convention.
// 210 units = 1 credit (different from standard conversion)
// 211 units = 1 credit (different from standard conversion)
const micros = maybeMicros ?? 0
const amount = formatCreditsFromSubscriptionMicros({
micros,
Expand Down
16 changes: 8 additions & 8 deletions tests-ui/tests/base/credits/comfyCredits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {

describe('comfyCredits helpers', () => {
test('exposes the fixed conversion rate', () => {
expect(CREDITS_PER_USD).toBe(210)
expect(COMFY_CREDIT_RATE_CENTS).toBeCloseTo(2.1) // credits per cent
expect(CREDITS_PER_USD).toBe(211)
expect(COMFY_CREDIT_RATE_CENTS).toBeCloseTo(2.11) // credits per cent
})

test('converts between USD and cents', () => {
Expand All @@ -27,20 +27,20 @@ describe('comfyCredits helpers', () => {
})

test('converts cents to credits and back', () => {
expect(centsToCredits(100)).toBe(210) // 100 cents = 210 credits
expect(creditsToCents(210)).toBe(100) // 210 credits = 100 cents
expect(centsToCredits(100)).toBe(211) // 100 cents = 211 credits
expect(creditsToCents(211)).toBe(100) // 211 credits = 100 cents
})

test('converts USD to credits and back', () => {
expect(usdToCredits(1)).toBe(210) // 1 USD = 210 credits
expect(creditsToUsd(210)).toBe(1) // 210 credits = 1 USD
expect(usdToCredits(1)).toBe(211) // 1 USD = 211 credits
expect(creditsToUsd(211)).toBe(1) // 211 credits = 1 USD
})

test('formats credits and USD values using en-US locale', () => {
const locale = 'en-US'
expect(formatCredits({ value: 1234.567, locale })).toBe('1,234.57')
expect(formatCreditsFromCents({ cents: 100, locale })).toBe('210.00')
expect(formatCreditsFromUsd({ usd: 1, locale })).toBe('210.00')
expect(formatCreditsFromCents({ cents: 100, locale })).toBe('211.00')
expect(formatCreditsFromUsd({ usd: 1, locale })).toBe('211.00')
expect(formatUsd({ value: 4.2, locale })).toBe('4.20')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('useSubscriptionCredits', () => {
})

it('should format amount_micros correctly', () => {
authStore.balance = { amount_micros: 210 } as any
authStore.balance = { amount_micros: 211 } as any
const { totalCredits } = useSubscriptionCredits()
expect(totalCredits.value).toBe('1.00 Credits')
})
Expand All @@ -104,7 +104,7 @@ describe('useSubscriptionCredits', () => {
throw new Error('Formatting error')
})

authStore.balance = { amount_micros: 210 } as any
authStore.balance = { amount_micros: 211 } as any
const { totalCredits } = useSubscriptionCredits()
expect(totalCredits.value).toBe('0.00 Credits')
formatSpy.mockRestore()
Expand All @@ -119,7 +119,7 @@ describe('useSubscriptionCredits', () => {
})

it('should format cloud_credit_balance_micros correctly', () => {
authStore.balance = { cloud_credit_balance_micros: 420 } as any
authStore.balance = { cloud_credit_balance_micros: 422 } as any
const { monthlyBonusCredits } = useSubscriptionCredits()
expect(monthlyBonusCredits.value).toBe('2.00 Credits')
})
Expand All @@ -133,7 +133,7 @@ describe('useSubscriptionCredits', () => {
})

it('should format prepaid_balance_micros correctly', () => {
authStore.balance = { prepaid_balance_micros: 630 } as any
authStore.balance = { prepaid_balance_micros: 633 } as any
const { prepaidCredits } = useSubscriptionCredits()
expect(prepaidCredits.value).toBe('3.00 Credits')
})
Expand Down
Loading