Repository navigation
FRONT-3734 feat(billing): auto top-up card in the Add credits dialog #22421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dante01yoon
merged 4 commits into
main
from
jaewon/front-3650-add-credits-auto-top-up-link
Nov 1, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4397be2
feat(billing): link the Add credits dialog to auto top-up settings
dante01yoon f2af610
feat(billing): auto top-up card in the Add credits dialog, per the 1.…
dante01yoon 8354c68
feat(billing): match the auto top-up card to FRONT-3734
dante01yoon 9495c1b
fix(billing): space the legacy dialog's auto top-up card with a wrapp…
dante01yoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/platform/billing/components/TopUpAutoTopUpCard.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import type { AutoTopUpSetup } from '@comfyorg/ingest-types' | ||
|
Check warning on line 1 in src/platform/billing/components/TopUpAutoTopUpCard.test.ts
|
||
| import { render, screen } from '@testing-library/vue' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { computed } from 'vue' | ||
| import { createI18n } from 'vue-i18n' | ||
|
|
||
| import enMessages from '@/locales/en/main.json' | ||
| import { useTelemetry } from '@comfyorg/telemetry' | ||
| import { | ||
| autoTopUpCardState, | ||
| loadedAutoTopUp | ||
| } from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard' | ||
| import { | ||
| autoTopUpEnabledFact, | ||
| canManageAutoTopUpFact | ||
| } from '@/platform/billing/composables/__mocks__/useBillingCapabilities' | ||
| import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard' | ||
| import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' | ||
|
|
||
| import TopUpAutoTopUpCard from './TopUpAutoTopUpCard.vue' | ||
|
|
||
| vi.mock(import('@/platform/billing/composables/useBillingCapabilities')) | ||
| vi.mock(import('@/platform/billing/composables/useBillingAutoTopUpCard')) | ||
| vi.mock(import('@comfyorg/telemetry')) | ||
| vi.mock(import('@/platform/workspace/utils/platformLink'), () => ({ | ||
| platformLink: (path: string, correlationId?: string) => | ||
| `https://platform.test${path}?correlation_id=${correlationId}` | ||
| })) | ||
|
|
||
| const PROMPT = 'Running low on credits? Turn on auto top-up.' | ||
|
|
||
| type Served = { | ||
| enabled: boolean | ||
| canManage: boolean | ||
| setup: AutoTopUpSetup | null | ||
| card: ReturnType<typeof loadedAutoTopUp> | { kind: 'loading' | 'unavailable' } | ||
| } | ||
|
|
||
| const shown: Served = { | ||
| enabled: true, | ||
| canManage: true, | ||
| setup: { state: 'ready' }, | ||
| card: loadedAutoTopUp('off') | ||
| } | ||
|
|
||
| function renderCard(served: Partial<Served> = {}) { | ||
| const { enabled, canManage, setup, card } = { ...shown, ...served } | ||
| const capabilities = useBillingCapabilities() | ||
| capabilities.autoTopUpEnabled = autoTopUpEnabledFact(enabled) | ||
| capabilities.canManageAutoTopUp = canManageAutoTopUpFact(canManage) | ||
| capabilities.autoTopUpSetup = computed(() => setup) | ||
| autoTopUpCardState.value = card | ||
| render(TopUpAutoTopUpCard, { | ||
| global: { | ||
| plugins: [ | ||
| createI18n({ | ||
| legacy: false, | ||
| locale: 'en', | ||
| messages: { en: enMessages } | ||
| }) | ||
| ] | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| describe('TopUpAutoTopUpCard', () => { | ||
| it('offers a manager with auto top-up off to set it up on the billing site', () => { | ||
| renderCard() | ||
|
|
||
| expect(screen.getByText(PROMPT)).toBeInTheDocument() | ||
| expect(screen.getByRole('link', { name: 'Set up' })).toHaveAttribute( | ||
| 'href', | ||
| expect.stringContaining('https://platform.test/profile/billing') | ||
| ) | ||
| }) | ||
|
|
||
| it.for<{ name: string } & Partial<Served>>([ | ||
| { name: 'auto top-up is not served', enabled: false }, | ||
| { name: 'the viewer cannot manage it', canManage: false }, | ||
| { name: 'no setup is served', setup: null }, | ||
| { | ||
| name: 'setup is unavailable', | ||
| setup: { state: 'unavailable', reason: 'workspace_blocked' } | ||
| }, | ||
| { | ||
| name: 'setup is frozen by a past-due payment', | ||
| setup: { state: 'frozen', reason: 'payment_past_due' } | ||
| }, | ||
| { name: 'auto top-up is already on', card: loadedAutoTopUp('on') }, | ||
| { name: 'auto top-up has failed', card: loadedAutoTopUp('failed') }, | ||
| { name: 'the status is still loading', card: { kind: 'loading' } }, | ||
| { name: 'the status read failed', card: { kind: 'unavailable' } } | ||
| ])('shows nothing when $name', ({ name: _, ...served }) => { | ||
| renderCard(served) | ||
|
|
||
| expect(screen.queryByText(PROMPT)).toBeNull() | ||
| }) | ||
|
|
||
| it('stays shown while setup is frozen for another reason', () => { | ||
| renderCard({ setup: { state: 'frozen', reason: 'billing_paused' } }) | ||
|
|
||
| expect(screen.getByText(PROMPT)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('reads the auto top-up status only when the served facts allow setup', () => { | ||
| renderCard({ canManage: false }) | ||
| expect(useBillingAutoTopUpCard().ensureRead).not.toHaveBeenCalled() | ||
|
|
||
| renderCard() | ||
| expect(useBillingAutoTopUpCard().ensureRead).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('reports the hand-off to the billing site', async () => { | ||
| renderCard() | ||
|
|
||
| await userEvent.click(screen.getByRole('link', { name: 'Set up' })) | ||
|
|
||
| expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| operation: 'platform_handoff', | ||
| target: 'auto_top_up', | ||
| action: 'turn_on' | ||
| }) | ||
| ) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <template> | ||
| <section | ||
| v-if="visible" | ||
| class="flex items-center justify-between gap-4 rounded-2xl border border-border/60 p-4" | ||
| > | ||
| <p class="m-0 text-sm text-foreground"> | ||
| {{ $t('credits.topUp.autoTopUp.prompt') }} | ||
| </p> | ||
| <Button | ||
| as="a" | ||
| :href | ||
| target="_blank" | ||
| rel="noopener" | ||
| variant="secondary" | ||
| size="md" | ||
| class="shrink-0 no-underline" | ||
| @click="track" | ||
| > | ||
| {{ $t('credits.topUp.autoTopUp.setUp') }} | ||
| <i class="icon-[lucide--external-link]" aria-hidden="true" /> | ||
| </Button> | ||
| </section> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import Button from '@comfyorg/design-system/button/Button' | ||
| import { computed, watch } from 'vue' | ||
|
|
||
| import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard' | ||
| import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' | ||
| import { usePlatformHandoff } from '@/platform/billing/composables/usePlatformHandoff' | ||
|
|
||
| const { autoTopUpEnabled, canManageAutoTopUp, autoTopUpSetup } = | ||
| useBillingCapabilities() | ||
| const { state, ensureRead } = useBillingAutoTopUpCard() | ||
|
|
||
| const canSetUp = computed(() => { | ||
| if (!autoTopUpEnabled.value) return false | ||
| if (!canManageAutoTopUp.value) return false | ||
| const setup = autoTopUpSetup.value | ||
| if (setup === null || setup.state === 'unavailable') return false | ||
| return !(setup.state === 'frozen' && setup.reason === 'payment_past_due') | ||
| }) | ||
|
|
||
| watch( | ||
| canSetUp, | ||
| (allowed) => { | ||
| if (allowed) ensureRead() | ||
| }, | ||
| { immediate: true } | ||
| ) | ||
|
|
||
| const visible = computed(() => { | ||
| if (!canSetUp.value) return false | ||
| const read = state.value | ||
| return read.kind === 'loaded' && read.settings.status === 'off' | ||
| }) | ||
|
|
||
| const { href, track } = usePlatformHandoff('/profile/billing', { | ||
| target: 'auto_top_up', | ||
| action: 'turn_on' | ||
| }) | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.