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
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,79 @@
)
"
>
<span class="text-muted-foreground" aria-hidden="true">$</span>
<span v-if="prefix" class="text-muted-foreground" aria-hidden="true">
{{ prefix }}
</span>
<input
:id="fieldId"
:value="input"
type="text"
inputmode="decimal"
:inputmode="prefix ? 'decimal' : 'numeric'"
autocomplete="off"
:disabled="locked"
:aria-invalid="error ? true : undefined"
:aria-describedby="error ? errorId : undefined"
:aria-describedby="describedBy"
class="min-w-0 flex-1 border-none bg-transparent text-base text-foreground outline-none"
data-testid="add-credits-amount-input"
:data-testid="inputTestId"
@input="onInput"
/>
</div>
<p
:id="errorId"
:class="cn('m-0 min-h-5 text-destructive', ui.error)"
data-testid="add-credits-amount-error"
v-if="reserveNote || error || hint"
:id="noteId"
:class="
cn(
'm-0',
reserveNote && 'min-h-5',
hint && !error ? 'text-muted-foreground' : 'text-destructive',
ui.error
)
"
:data-testid="noteTestId"
aria-live="polite"
>
{{ error }}
{{ error ?? hint }}
</p>
</div>
</template>

<script setup lang="ts">
import { useId } from 'vue'
import { computed, useId } from 'vue'

import { cn } from '@comfyorg/tailwind-utils'

import type { AddCreditsUi } from './addCreditsPresentation'

const { input, error, locked, label, ui } = defineProps<{
const {
input,
label,
error,
hint,
prefix,
locked,
reserveNote,
inputTestId,
noteTestId,
ui
} = defineProps<{
input: string
error: string | undefined
locked: boolean
label: string
error?: string
hint?: string
prefix?: string
locked: boolean
/** Keeps the note line's height so an error does not shift the layout. */
reserveNote?: boolean
inputTestId: string
noteTestId: string
ui: AddCreditsUi
}>()

const emit = defineEmits<{ type: [input: string] }>()

const fieldId = useId()
const errorId = useId()
const noteId = useId()
const describedBy = computed(() => (error || hint ? noteId : undefined))

function onInput(event: Event) {
if (event.target instanceof HTMLInputElement) emit('type', event.target.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
:error="amountError"
:locked="view.locked"
:label="translate('customAmountLabel')"
prefix="$"
reserve-note
input-test-id="add-credits-amount-input"
note-test-id="add-credits-amount-error"
:ui
@type="emit('type', $event)"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
</div>

<template v-if="checked">
<AddCreditsAutoTopUpField
name="threshold"
<AddCreditsAmountField
input-test-id="add-credits-auto-top-up-threshold"
note-test-id="add-credits-auto-top-up-threshold-note"
:input="input.threshold"
:label="translate('autoTopUp.threshold')"
:error="messageFor('threshold')"
Expand All @@ -33,8 +34,9 @@
:ui
@type="emit('edit', 'threshold', $event)"
/>
<AddCreditsAutoTopUpField
name="target"
<AddCreditsAmountField
input-test-id="add-credits-auto-top-up-target"
note-test-id="add-credits-auto-top-up-target-note"
:input="input.target"
:label="translate('autoTopUp.target')"
:error="messageFor('target')"
Expand All @@ -56,9 +58,10 @@
@update:model-value="emit('edit', 'limitOn', $event)"
/>
</div>
<AddCreditsAutoTopUpField
<AddCreditsAmountField
v-if="input.limitOn"
name="limit"
input-test-id="add-credits-auto-top-up-limit"
note-test-id="add-credits-auto-top-up-limit-note"
prefix="$"
:input="input.limit"
:label="translate('autoTopUp.limit')"
Expand Down Expand Up @@ -112,7 +115,7 @@ import Checkbox from '@comfyorg/design-system/checkbox/Checkbox'
import Switch from '@comfyorg/design-system/switch/Switch'
import { cn } from '@comfyorg/tailwind-utils'

import AddCreditsAutoTopUpField from './AddCreditsAutoTopUpField.vue'
import AddCreditsAmountField from './AddCreditsAmountField.vue'
import type { AddCreditsFormat, AddCreditsUi } from './addCreditsPresentation'
import type { AutoTopUpEdit } from './useAddCreditsAutoTopUp'
import {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import type {
import {
autoTopUpActivationFor,
autoTopUpTargetFor,
CREDITS_PER_USD,
parseAutoTopUpForm,
startAutoTopUpForm,
validateAutoTopUp
} from '@comfyorg/account-core/billing'

import { centsToCredits } from '#/billing/tab/creditsCardCopy'

export type AddCreditsAutoTopUpRequest =
| { readonly kind: 'not_offered' }
| { readonly kind: 'unchecked' }
Expand All @@ -33,7 +34,7 @@ export function useAddCreditsAutoTopUp(
const edits = shallowRef<Partial<AutoTopUpFormInput>>({})

const creditsPicked = computed(() =>
Math.round(((toValue(amountCents) ?? 0) * CREDITS_PER_USD) / 100)
centsToCredits(toValue(amountCents) ?? 0)
)

const input = computed<AutoTopUpFormInput>(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import enMessages from '@/locales/en/main.json' with { type: 'json' }
import { readAutoTopUpActivation } from '@/platform/billing/addCredits/autoTopUpActivation'
import { billingApi } from '@/platform/billing/api/billingApi'
import {
autoTopUpCardState,
autoTopUpCard,
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 { useBillingSdkStore } from '@/platform/billing/sdk/billingSdkStore'
import { setLocalBillingWebEnabled } from '@/platform/billing/localBillingWebEnabled'
Expand Down Expand Up @@ -185,7 +186,9 @@ function renderDialog({
capabilities.autoTopUpEnabled = autoTopUpEnabledFact(true)
capabilities.canManageAutoTopUp = canManageAutoTopUpFact(true)
capabilities.autoTopUpSetup = computed(() => ({ state: 'ready' }))
autoTopUpCardState.value = loadedAutoTopUp('off')
vi.mocked(useBillingAutoTopUpCard).mockReturnValue(
autoTopUpCard(loadedAutoTopUp('off'))
)
vi.mocked(useBillingSdkStore().readPaymentMethods).mockResolvedValue({
status: 'ok',
value: []
Expand Down
4 changes: 2 additions & 2 deletions src/platform/billing/components/TopUpAutoTopUpCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createI18n } from 'vue-i18n'
import enMessages from '@/locales/en/main.json'
import { useTelemetry } from '@comfyorg/telemetry'
import {
autoTopUpCardState,
autoTopUpCard,
loadedAutoTopUp
} from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard'
import {
Expand Down Expand Up @@ -64,7 +64,7 @@ function renderCard(served: Partial<Served> = {}) {
capabilities.autoTopUpEnabled = autoTopUpEnabledFact(enabled)
capabilities.canManageAutoTopUp = canManageAutoTopUpFact(canManage)
capabilities.autoTopUpSetup = computed(() => setup)
autoTopUpCardState.value = card
vi.mocked(useBillingAutoTopUpCard).mockReturnValue(autoTopUpCard(card))
render(TopUpAutoTopUpCard, {
global: {
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ import type { CreateTopupResponse } from '@comfyorg/billing-core'
import { billingOperation } from '@/platform/billing/composables/billingOperationTestUtils'
import type { BillingOperation } from '@/platform/billing/composables/billingOperationTestUtils'
import {
autoTopUpCardState,
autoTopUpCard,
loadedAutoTopUp
} from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard'
import {
autoTopUpEnabledFact,
canManageAutoTopUpFact
} from '@/platform/billing/composables/__mocks__/useBillingCapabilities'
import { useBillingAutoTopUpCard } from '@/platform/billing/legacy160/platform/billing/composables/useBillingAutoTopUpCard'
import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
import { mockBillingContext } from '@/utils/__tests__/mockBillingContext'

Expand Down Expand Up @@ -2669,7 +2670,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => {
capabilities.autoTopUpSetup = computed(() => ({
state: 'ready' as const
}))
autoTopUpCardState.value = loadedAutoTopUp('off')
vi.mocked(useBillingAutoTopUpCard).mockReturnValue(
autoTopUpCard(loadedAutoTopUp('off'))
)
})

it('sits above Add credits on the amount step', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { onTestFinished, vi } from 'vitest'
import { computed, shallowRef } from 'vue'
import { vi } from 'vitest'
import { computed } from 'vue'

import type { AutoReloadSettings } from '@comfyorg/billing-core'
import type { useBillingAutoTopUpCard as realUseBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard'
Expand Down Expand Up @@ -38,21 +38,18 @@ export function loadedAutoTopUp(
return { kind: 'loaded', settings: { ...offSettings, status } }
}

export const autoTopUpCardState = shallowRef<AutoTopUpCardState>({
kind: 'loading'
})

const card: AutoTopUpCard = {
scope: computed(() => 'workspace-test'),
state: computed(() => autoTopUpCardState.value),
isReady: computed(() => autoTopUpCardState.value.kind !== 'loading'),
ensureRead: vi.fn(),
retry: vi.fn(async () => undefined)
export function autoTopUpCard(
state: AutoTopUpCardState = { kind: 'loading' }
): AutoTopUpCard {
return {
scope: computed(() => 'workspace-test'),
state: computed(() => state),
isReady: computed(() => state.kind !== 'loading'),
ensureRead: vi.fn(),
retry: vi.fn(async () => undefined)
}
}

export const useBillingAutoTopUpCard = vi.fn(() => {
onTestFinished(() => {
autoTopUpCardState.value = { kind: 'loading' }
})
return card
})
const card = autoTopUpCard()

export const useBillingAutoTopUpCard = vi.fn(() => card)
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { reportError } from '@comfyorg/telemetry/reportError'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { activateBillingScope } from '@/platform/billing/__tests__/activateBillingScope'
import {
autoTopUpCardState,
autoTopUpCard,
loadedAutoTopUp
} from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard'
import {
autoTopUpEnabledFact,
canManageAutoTopUpFact
} from '@/platform/billing/composables/__mocks__/useBillingCapabilities'
import { useAddCreditsAutoTopUpOffer } from '@/platform/billing/composables/useAddCreditsAutoTopUpOffer'
import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard'
import { setLocalBillingWebEnabled } from '@/platform/billing/localBillingWebEnabled'
import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
import { useBillingSdkStore } from '@/platform/billing/sdk/billingSdkStore'
Expand Down Expand Up @@ -66,7 +67,9 @@ function offerFor({
capabilities.autoTopUpEnabled = autoTopUpEnabledFact(rollout)
capabilities.canManageAutoTopUp = canManageAutoTopUpFact(true)
capabilities.autoTopUpSetup = computed(() => ({ state: 'ready' }))
autoTopUpCardState.value = loadedAutoTopUp(status)
vi.mocked(useBillingAutoTopUpCard).mockReturnValue(
autoTopUpCard(loadedAutoTopUp(status))
)
const scope = effectScope()
onTestFinished(() => scope.stop())
return scope.run(useAddCreditsAutoTopUpOffer)!
Expand Down
Loading