Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -3632,10 +3632,12 @@
"credits": {
"addCredits": "Add credits",
"available": "Available",
"availableUntil": "Available until {date}",
"inUse": "In use now",
"overdrawn": "Your runs used {count} more credit than you had. | Your runs used {count} more credits than you had.",
"plan": "Plan",
"planOfPool": "{remaining} of {total}",
"planUsed": "{percent}% used",
"planTooltip": "Credits included with your plan. They refill each billing period.",
"rateInfo": "About credits",
"rateTooltip": "Credits pay for runs. {credits} credits = $1.",
Expand All @@ -3644,14 +3646,20 @@
"topUpTooltip": "Credits you added. They're used once plan credits run out.",
"unavailable": "Couldn't load your balance."
},
"footer": {
"messageSupport": "Message support",
"partnerNodesPricing": "Partner Nodes pricing"
},
"handoff": {
"member": {
"action": "View usage",
"label": "Usage"
},
"owner": {
"action": "Open billing",
"label": "Payment methods, invoices, and usage"
"label": "Payment methods, invoices, and usage",
"line": "Manage everything else about billing on {platform}",
"platform": "platform.comfy.org"
}
},
"loadError": "We couldn't load your plan.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const activeFacts: CreditsCardFacts = {
planKind: 'active',
billingStatus: 'paid',
planPoolCredits: 1000,
renewalDate: null
renewalDate: null,
endDate: null
}

const SUBSCRIBE_NOTE =
Expand Down Expand Up @@ -108,7 +109,7 @@ describe('BillingCreditsCard', () => {
case: 'a paused plan keeps the real balance and empties the plan line',
facts: { billingStatus: 'paused', planKind: 'paused' },
available: '1,477',
plan: '0 of 1,000 Refills when the payment goes through',
plan: '0 of 1,000',
topUp: '633',
inUse: false,
addCredits: true,
Expand Down Expand Up @@ -223,15 +224,86 @@ describe('BillingCreditsCard', () => {
)
})

it('ends the plan line with the renewal date', () => {
renderCard({
...activeFacts,
renewalDate: '2026-10-01T00:00:00Z'
})
it.for<{
case: string
facts: Partial<CreditsCardFacts>
amount: string
date: string
used: string | null
meter: string | null
}>([
{
case: 'an active plan refills on its renewal date',
facts: { renewalDate: '2026-10-01T00:00:00Z' },
amount: '844 of 1,000',
date: 'Refills October 1, 2026',
used: '16% used',
meter: '16'
},
{
case: 'an ending plan is available until its end date',
facts: {
planKind: 'ending',
renewalDate: '2026-10-01T00:00:00Z',
endDate: '2026-12-31T12:00:00Z'
},
amount: '844 of 1,000',
date: 'Available until December 31, 2026',
used: '16% used',
meter: '16'
},
{
case: 'a plan with no known total shows no meter',
facts: { planPoolCredits: null, renewalDate: '2026-10-01T00:00:00Z' },
amount: '844',
date: 'Refills October 1, 2026',
used: null,
meter: null
},
{
case: 'a paused plan keeps the pool but shows no usage',
facts: {
billingStatus: 'paused',
planKind: 'paused',
renewalDate: '2026-10-01T00:00:00Z'
},
amount: '0 of 1,000',
date: 'Refills when the payment goes through',
used: null,
meter: null
},
{
case: 'used-up plan credits fill the meter',
facts: { balance: balanceOf({ effective: 300, plan: 0, topUp: 300 }) },
amount: '0 of 1,000',
date: '',
used: '100% used',
meter: '100'
}
])('splits the plan cell for $case', (row) => {
renderCard({ ...activeFacts, ...row.facts })

expect(screen.getByTestId('billing-credits-plan').textContent.trim()).toBe(
'844 of 1,000 Refills October 1, 2026'
row.amount
)
expect(
screen.queryByTestId('billing-credits-plan-date')?.textContent.trim() ??
''
).toBe(row.date)
expect(
screen.queryByTestId('billing-credits-plan-used')?.textContent.trim() ??
null
).toBe(row.used)
expect(
screen.queryByRole('meter')?.getAttribute('aria-valuenow') ?? null
).toBe(row.meter)
})

it('shows nothing under the amount without a date or a total', () => {
renderCard({ ...activeFacts, planPoolCredits: null })

expect(screen.queryByTestId('billing-credits-plan-date')).toBeNull()
expect(screen.queryByRole('meter')).toBeNull()
})

it('waits for the payment instead of a renewal date on a paused plan', () => {
Expand All @@ -242,9 +314,10 @@ describe('BillingCreditsCard', () => {
renewalDate: '2026-11-23T00:00:00Z'
})

expect(screen.getByTestId('billing-credits-plan').textContent.trim()).toBe(
'0 of 1,000 Refills when the payment goes through'
)
expect(
screen.getByTestId('billing-credits-plan-date').textContent.trim()
).toBe('Refills when the payment goes through')
expect(screen.queryByRole('meter')).toBeNull()
})

it('puts the credits title above a 12px card', () => {
Expand All @@ -263,9 +336,7 @@ describe('BillingCreditsCard', () => {
'text-2xl',
'font-medium'
)
expect(screen.getByTestId('billing-credits-plan')).toHaveClass(
'font-semibold'
)
expect(screen.getByText('844')).toHaveClass('font-semibold')
})

it('asks for the balance again from Try again', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,7 @@
</div>

<div v-if="state.kind === 'plan'" class="flex border-t border-card">
<div class="flex flex-1 flex-col gap-2 border-r border-card px-5 py-4">
<span class="flex items-center gap-1 text-sm text-muted-foreground">
{{ $t('workspacePanel.billingTab.credits.plan') }}
<Button
:tooltip="$t('workspacePanel.billingTab.credits.planTooltip')"
:aria-label="$t('workspacePanel.billingTab.credits.planTooltip')"
variant="muted-textonly"
size="icon-sm"
>
<i class="icon-[lucide--info] size-3.5" aria-hidden="true" />
</Button>
</span>
<span
class="text-sm font-semibold text-foreground"
data-testid="billing-credits-plan"
>
{{ planLine() }}
</span>
</div>
<BillingCreditsPlanCell :plan="state" />
<div class="flex flex-1 items-start justify-between gap-4 px-5 py-4">
<div class="flex flex-col gap-2">
<span class="flex items-center gap-1 text-sm text-muted-foreground">
Expand Down Expand Up @@ -149,10 +131,10 @@ import { useI18n } from 'vue-i18n'
import {
CREDITS_PER_USD,
centsToCredits,
formatCredits,
formatCreditsFromCents
} from '@/base/credits/comfyCredits'
import Button from '@/components/ui/button/Button.vue'
import BillingCreditsPlanCell from '@/platform/billing/components/billingTab/BillingCreditsPlanCell.vue'
import type { CreditsCardState } from '@/platform/billing/components/billingTab/creditsCard'

const {
Expand All @@ -172,7 +154,7 @@ const emit = defineEmits<{
addCredits: []
}>()

const { t, d, locale } = useI18n()
const { locale } = useI18n()

const WHOLE = { maximumFractionDigits: 0 }

Expand All @@ -184,34 +166,6 @@ function credits(cents: number) {
})
}

function planAmount(cents: number, poolCredits: number | null) {
if (poolCredits === null) return credits(cents)
return t('workspacePanel.billingTab.credits.planOfPool', {
remaining: credits(cents),
total: formatCredits({
value: poolCredits,
locale: locale.value,
numberOptions: WHOLE
})
})
}

function longDate(raw: string | null): string {
const date = raw ? new Date(raw) : null
if (!date || Number.isNaN(date.getTime())) return ''
return d(date, { year: 'numeric', month: 'long', day: 'numeric' })
}

function planLine() {
if (state.kind !== 'plan') return ''
const amount = planAmount(state.planCents, state.planPoolCredits)
if (state.refillAwaitsPayment)
return `${amount} ${t('subscription.refillsAfterPayment')}`
const date = longDate(state.renewalDate)
if (!date) return amount
return `${amount} ${t('subscription.refillsDate', { date })}`
}

const overdrawnCredits = computed(() =>
state.kind === 'unavailable' ? 0 : centsToCredits(-state.availableCents)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<template>
<div class="flex flex-1 flex-col gap-2 border-r border-card px-5 py-4">
<span class="flex items-center gap-1 text-sm text-muted-foreground">
{{ $t('workspacePanel.billingTab.credits.plan') }}
<Button
:tooltip="$t('workspacePanel.billingTab.credits.planTooltip')"
:aria-label="$t('workspacePanel.billingTab.credits.planTooltip')"
variant="muted-textonly"
size="icon-sm"
>
<i class="icon-[lucide--info] size-3.5" aria-hidden="true" />
</Button>
</span>
<i18n-t
v-if="planTotal"
keypath="workspacePanel.billingTab.credits.planOfPool"
tag="span"
class="text-sm text-muted-foreground"
data-testid="billing-credits-plan"
>
<template #remaining>
<span class="font-semibold text-foreground">
{{ credits(plan.planCents) }}
</span>
</template>
<template #total>{{ planTotal }}</template>
</i18n-t>
<span
v-else
class="text-sm font-semibold text-foreground"
data-testid="billing-credits-plan"
>
{{ credits(plan.planCents) }}
</span>
<div
v-if="planDateLine || planUsedPercent !== null"
class="flex flex-col gap-2 pt-2"
>
<div
class="flex items-center justify-between gap-2 text-sm text-muted-foreground"
>
<span data-testid="billing-credits-plan-date">
{{ planDateLine }}
</span>
<span
v-if="planUsedPercent !== null"
data-testid="billing-credits-plan-used"
>
{{
$t('workspacePanel.billingTab.credits.planUsed', {
percent: planUsedPercent
})
}}
</span>
</div>
<div
v-if="planUsedPercent !== null"
role="meter"
:aria-label="$t('workspacePanel.billingTab.credits.plan')"
aria-valuemin="0"
aria-valuemax="100"
:aria-valuenow="planUsedPercent"
class="h-1 overflow-hidden rounded-full bg-accent"
>
<div
class="h-full rounded-full bg-foreground"
:style="{ width: `${planUsedPercent}%` }"
/>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import { clamp } from 'es-toolkit'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

import {
centsToCredits,
formatCredits,
formatCreditsFromCents
} from '@/base/credits/comfyCredits'
import Button from '@/components/ui/button/Button.vue'
import type { PlanCreditsState } from '@/platform/billing/components/billingTab/creditsCard'
import { useLongDate } from '@/platform/billing/composables/useLongDate'

const { plan } = defineProps<{ plan: PlanCreditsState }>()

const { t, locale } = useI18n()
const { longDate } = useLongDate()

const WHOLE = { maximumFractionDigits: 0 }

const PLAN_DATE_KEY = {
refills: 'subscription.refillsDate',
availableUntil: 'workspacePanel.billingTab.credits.availableUntil'
} as const

function credits(cents: number) {
return formatCreditsFromCents({
cents,
locale: locale.value,
numberOptions: WHOLE
})
}

const planTotal = computed(() =>
plan.planPoolCredits
? formatCredits({
value: plan.planPoolCredits,
locale: locale.value,
numberOptions: WHOLE
})
: null
)

const planUsedPercent = computed(() => {
if (!plan.showUsage || !plan.planPoolCredits) return null
const remaining = centsToCredits(plan.planCents) / plan.planPoolCredits
return Math.round(clamp(1 - remaining, 0, 1) * 100)
})

const planDateLine = computed(() => {
if (plan.planDate.kind === 'afterPayment')
return t('subscription.refillsAfterPayment')
const date = longDate(plan.planDate.date)
return date ? t(PLAN_DATE_KEY[plan.planDate.kind], { date }) : ''
})
</script>
Loading
Loading