Line data Source code
1 : <template>
2 : <div class="px-8">
3 : <h3 class="m-0 text-sm font-normal text-muted-foreground">
4 : {{ $t('credits.topUp.selectAmount') }}
5 : </h3>
6 : <div class="flex gap-2 pt-3">
7 0 : <Button
8 : v-for="amount in TOPUP_AMOUNT_PRESETS_USD"
9 : :key="amount"
10 : :autofocus="amount === 50"
11 : variant="secondary"
12 : size="lg"
13 : :aria-pressed="selectedPreset === amount"
14 : :class="
15 : cn(
16 : 'h-10 w-full text-base focus-visible:ring-ring',
17 : selectedPreset === amount && 'bg-muted'
18 : )
19 : "
20 : @click="emit('preset', amount)"
21 : >
22 : ${{ amount }}
23 : </Button>
24 : </div>
25 : <p
26 : v-if="planCreditCopy"
27 : class="m-0 pt-3 text-sm text-muted-foreground"
28 : data-testid="top-up-plan-credit-line"
29 : >
30 : {{ planCreditCopy }}
31 : </p>
32 : </div>
33 : <div class="flex gap-2 px-8 pt-8">
34 : <div
35 : class="flex min-w-0 flex-1 flex-col gap-3"
36 : data-testid="top-up-pay-amount"
37 : >
38 : <div class="text-sm text-muted-foreground">
39 : {{ $t('credits.topUp.youPay') }}
40 : </div>
41 : <FormNumberField
42 : class="w-full"
43 : :aria-label="$t('credits.topUp.youPay')"
44 : input-class="text-lg font-medium"
45 : :model-value="payAmount"
46 : :min="0"
47 : :max="maxAmount"
48 : :step="getStepAmount(payAmount)"
49 : :format-options="{ maximumFractionDigits: 0 }"
50 : @update:model-value="emit('payAmount', $event)"
51 : >
52 : <template #prefix>
53 : <span class="shrink-0 text-base font-semibold">$</span>
54 : </template>
55 : </FormNumberField>
56 : </div>
57 : <div class="flex min-w-0 flex-1 flex-col gap-3">
58 : <div class="text-sm text-muted-foreground">
59 : {{ $t('credits.topUp.youGet') }}
60 : </div>
61 : <FormNumberField
62 : :model-value="credits"
63 : class="w-full"
64 : :aria-label="$t('credits.topUp.youGet')"
65 : input-class="text-lg font-medium"
66 : :min="0"
67 : :max="maxCredits"
68 : :step="usdToCredits(getStepAmount(creditsToUsd(credits)))"
69 : :format-options="{ maximumFractionDigits: 0 }"
70 : @update:model-value="emit('credits', $event)"
71 : >
72 : <template #prefix>
73 : <i class="icon-[lucide--coins] text-credit" />
74 : </template>
75 : </FormNumberField>
76 : </div>
77 : </div>
78 : </template>
79 :
80 : <script setup lang="ts">
81 : import { TOPUP_AMOUNT_PRESETS_USD } from '@comfyorg/account-core/billing'
82 : import Button from '@comfyorg/design-system/button/Button'
83 : import { cn } from '@comfyorg/tailwind-utils'
84 :
85 : import { creditsToUsd, usdToCredits } from '@/base/credits/comfyCredits'
86 : import FormNumberField from '@/components/common/FormNumberField.vue'
87 :
88 : const {
89 : payAmount,
90 : credits,
91 : selectedPreset,
92 : maxAmount,
93 : maxCredits,
94 : planCreditCopy
95 : } = defineProps<{
96 : payAmount: number
97 : credits: number
98 : selectedPreset: number | null
99 : maxAmount: number
100 : maxCredits: number
101 : planCreditCopy: string | null
102 : }>()
103 :
104 0 : const emit = defineEmits<{
105 : preset: [amount: number]
106 : payAmount: [amount: number]
107 : credits: [amount: number]
108 : }>()
109 :
110 0 : function getStepAmount(currentAmount: number): number {
111 0 : if (currentAmount < 100) return 5
112 0 : if (currentAmount < 1000) return 50
113 0 : return 100
114 : }
115 : </script>
|