From ad6f34fe6864d96e5dcc0b5f249c14c6a0a27ba2 Mon Sep 17 00:00:00 2001
From: dante01yoon
Date: Mon, 2 Nov 2026 09:12:13 -0500
Subject: [PATCH] [backport core/1.60] M4 feat(billing): use the served top-up
minimum and maximum in Add credits (#22435)
Rebuilt from the pre-SDK head of #22435 (43e9a6bcdb, net of its last
main merge f710711926): commits 4e232e0128, 0feb35b405 and 83c507a7c6.
(cherry picked from commit 43e9a6bcdb54fa371a3d340babf5a70c425f0193)
---
.../billing/components/TopUpAmountFields.vue | 25 ++++--
...TopUpCreditsDialogContentWorkspace.test.ts | 87 +++++++++++++++++++
.../TopUpCreditsDialogContentWorkspace.vue | 40 +++++++--
src/platform/billing/composables/types.ts | 8 ++
.../composables/useWorkspaceBilling.ts | 4 +
5 files changed, 149 insertions(+), 15 deletions(-)
diff --git a/src/platform/billing/components/TopUpAmountFields.vue b/src/platform/billing/components/TopUpAmountFields.vue
index 2386300e1f4..6f2683443bb 100644
--- a/src/platform/billing/components/TopUpAmountFields.vue
+++ b/src/platform/billing/components/TopUpAmountFields.vue
@@ -64,7 +64,7 @@
:aria-label="$t('credits.topUp.youGet')"
input-class="text-lg font-medium"
:min="0"
- :max="usdToCredits(maxAmount)"
+ :max="maxCredits"
:step="usdToCredits(getStepAmount(creditsToUsd(credits)))"
:format-options="{ maximumFractionDigits: 0 }"
@update:model-value="emit('credits', $event)"
@@ -85,14 +85,21 @@ import { cn } from '@comfyorg/tailwind-utils'
import { creditsToUsd, usdToCredits } from '@/base/credits/comfyCredits'
import FormNumberField from '@/components/common/FormNumberField.vue'
-const { payAmount, credits, selectedPreset, maxAmount, planCreditCopy } =
- defineProps<{
- payAmount: number
- credits: number
- selectedPreset: number | null
- maxAmount: number
- planCreditCopy: string | null
- }>()
+const {
+ payAmount,
+ credits,
+ selectedPreset,
+ maxAmount,
+ maxCredits,
+ planCreditCopy
+} = defineProps<{
+ payAmount: number
+ credits: number
+ selectedPreset: number | null
+ maxAmount: number
+ maxCredits: number
+ planCreditCopy: string | null
+}>()
const emit = defineEmits<{
preset: [amount: number]
diff --git a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts
index 9651ead93f6..f351cec8c2f 100644
--- a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts
+++ b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts
@@ -758,6 +758,93 @@ describe('TopUpCreditsDialogContentWorkspace', () => {
).not.toBeInTheDocument()
})
+ const SERVED_MINIMUM: Partial = {
+ minTopupCents: 2_500,
+ minTopupCredits: 5_275
+ }
+ const SERVED_MAXIMUM: Partial = {
+ maxTopupCents: 5_000,
+ maxTopupCredits: 10_550
+ }
+
+ it.for<{
+ name: string
+ balance: Partial
+ preset: string
+ message: RegExp
+ }>([
+ {
+ name: 'below the served minimum',
+ balance: SERVED_MINIMUM,
+ preset: '$10',
+ message: /5,275 credits minimum/
+ },
+ {
+ name: 'above the served maximum',
+ balance: SERVED_MAXIMUM,
+ preset: '$100',
+ message: /10,550 credits maximum/
+ }
+ ])(
+ 'blocks an amount $name and names the bound',
+ async ({ balance, preset, message }) => {
+ renderWithBalance(balance)
+
+ await userEvent.click(screen.getByRole('button', { name: preset }))
+
+ expect(screen.getByRole('button', { name: 'Add credits' })).toBeDisabled()
+ expect(screen.getByText(message)).toBeVisible()
+ }
+ )
+
+ it.for<{ name: string; balance: Partial; preset: string }>([
+ { name: 'at the served minimum', balance: SERVED_MINIMUM, preset: '$25' },
+ { name: 'above $5 when no minimum is served', balance: {}, preset: '$10' },
+ {
+ name: 'above $5 when the minimum has no served credits',
+ balance: { minTopupCents: 2_500 },
+ preset: '$10'
+ },
+ { name: 'at the served maximum', balance: SERVED_MAXIMUM, preset: '$50' },
+ {
+ name: 'under $10,000 when no maximum is served',
+ balance: {},
+ preset: '$100'
+ },
+ {
+ name: 'under $10,000 when the maximum has no served credits',
+ balance: { maxTopupCents: 5_000 },
+ preset: '$100'
+ }
+ ])('allows an amount $name', async ({ balance, preset }) => {
+ renderWithBalance(balance)
+
+ await userEvent.click(screen.getByRole('button', { name: preset }))
+
+ expect(screen.getByRole('button', { name: 'Add credits' })).toBeEnabled()
+ expect(screen.queryByText(/credits minimum/)).not.toBeInTheDocument()
+ })
+
+ it.for<{ name: string; balance: Partial; cap: string }>([
+ {
+ name: 'the served maximum credits',
+ balance: SERVED_MAXIMUM,
+ cap: '10550'
+ },
+ {
+ name: '$10,000 in credits when no maximum is served',
+ balance: {},
+ cap: '2110000'
+ }
+ ])('caps the credits input at $name', ({ balance, cap }) => {
+ renderWithBalance(balance)
+
+ expect(screen.getByRole('spinbutton', { name: 'Credits' })).toHaveAttribute(
+ 'aria-valuemax',
+ cap
+ )
+ })
+
describe('without a default payment method', () => {
const checkoutUrl = 'https://checkout.stripe.com/c/pay/cs_test'
diff --git a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue
index d0a09dbe95b..967aa735abc 100644
--- a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue
+++ b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue
@@ -143,7 +143,8 @@
:pay-amount
:credits="creditsModel"
:selected-preset
- :max-amount="MAX_AMOUNT"
+ :max-amount="maxTopup.usd"
+ :max-credits="maxTopup.credits"
:plan-credit-copy
@preset="handlePresetClick"
@pay-amount="handlePayAmountChange"
@@ -171,7 +172,7 @@
{{
$t('credits.topUp.minRequired', {
- credits: formatNumber(usdToCredits(MIN_AMOUNT))
+ credits: formatNumber(minTopup.credits)
})
}}
@@ -182,7 +183,7 @@
{{
$t('credits.topUp.maxAllowed', {
- credits: formatNumber(usdToCredits(MAX_AMOUNT))
+ credits: formatNumber(maxTopup.credits)
})
}}
{{ $t('credits.topUp.needMore') }}
@@ -596,8 +597,35 @@ const creditsModel = computed({
}
})
+function servedBoundOr(
+ fallbackUsd: number,
+ cents: number | undefined,
+ credits: number | undefined
+) {
+ return cents === undefined || credits === undefined
+ ? { usd: fallbackUsd, credits: usdToCredits(fallbackUsd) }
+ : { usd: cents / 100, credits }
+}
+
+const minTopup = computed(() =>
+ servedBoundOr(
+ MIN_AMOUNT,
+ balance.value?.minTopupCents,
+ balance.value?.minTopupCredits
+ )
+)
+const maxTopup = computed(() =>
+ servedBoundOr(
+ MAX_AMOUNT,
+ balance.value?.maxTopupCents,
+ balance.value?.maxTopupCredits
+ )
+)
+
const isValidAmount = computed(
- () => payAmount.value >= MIN_AMOUNT && payAmount.value <= MAX_AMOUNT
+ () =>
+ payAmount.value >= minTopup.value.usd &&
+ payAmount.value <= maxTopup.value.usd
)
const negativeBalanceCredits = computed(() => {
@@ -608,8 +636,8 @@ const negativeBalanceCredits = computed(() => {
return centsToCredits(-cents)
})
-const isBelowMin = computed(() => payAmount.value < MIN_AMOUNT)
-const showCeilingWarning = computed(() => payAmount.value >= MAX_AMOUNT)
+const isBelowMin = computed(() => payAmount.value < minTopup.value.usd)
+const showCeilingWarning = computed(() => payAmount.value >= maxTopup.value.usd)
const displayTotal = computed(() =>
n(payAmount.value, {
diff --git a/src/platform/billing/composables/types.ts b/src/platform/billing/composables/types.ts
index 447df37b43c..12174dd8d29 100644
--- a/src/platform/billing/composables/types.ts
+++ b/src/platform/billing/composables/types.ts
@@ -115,6 +115,14 @@ export interface BalanceInfo {
cloudCreditBalanceMicros?: number
/** Server-suggested top-up that covers a negative balance; null otherwise. */
suggestedTopupAmountCents?: number | null
+ /** Served `min_topup_cents`. Absent when the balance response omits it. */
+ minTopupCents?: number
+ /** Served `min_topup_credits`. Absent when the balance response omits it. */
+ minTopupCredits?: number
+ /** Served `max_topup_cents`. Absent when the balance response omits it. */
+ maxTopupCents?: number
+ /** Served `max_topup_credits`. Absent when the balance response omits it. */
+ maxTopupCredits?: number
/** Served `low_balance`. Absent when the balance response omits it. */
lowBalance?: boolean
}
diff --git a/src/platform/billing/composables/useWorkspaceBilling.ts b/src/platform/billing/composables/useWorkspaceBilling.ts
index 46135814ef3..fe82119b25f 100644
--- a/src/platform/billing/composables/useWorkspaceBilling.ts
+++ b/src/platform/billing/composables/useWorkspaceBilling.ts
@@ -261,6 +261,10 @@ export function useWorkspaceBilling(): WorkspaceBilling {
prepaidBalanceMicros: data.prepaid_balance_micros ?? 0,
cloudCreditBalanceMicros: data.cloud_credit_balance_micros ?? 0,
suggestedTopupAmountCents: data.suggested_topup_amount_cents,
+ minTopupCents: data.min_topup_cents,
+ minTopupCredits: data.min_topup_credits,
+ maxTopupCents: data.max_topup_cents,
+ maxTopupCredits: data.max_topup_credits,
lowBalance: data.low_balance
}
})