Line data Source code
1 : <template>
2 : <section
3 0 : v-if="visible"
4 : class="flex items-center justify-between gap-4 rounded-2xl border border-border/60 p-4"
5 : >
6 : <p class="m-0 text-sm text-foreground">
7 : {{ $t('credits.topUp.autoTopUp.prompt') }}
8 : </p>
9 : <Button
10 : v-bind="button"
11 : variant="secondary"
12 : size="md"
13 : class="shrink-0 no-underline"
14 : @click="open"
15 : >
16 : {{ $t('credits.topUp.autoTopUp.setUp') }}
17 : <i class="icon-[lucide--external-link]" aria-hidden="true" />
18 : </Button>
19 : </section>
20 : </template>
21 :
22 : <script setup lang="ts">
23 : import { canSetUpAutoTopUp } from '@comfyorg/account-core/billing'
24 : import Button from '@comfyorg/design-system/button/Button'
25 : import { computed, watch } from 'vue'
26 :
27 : import { useBillingAutoTopUpCard } from '@/platform/billing/legacy160/platform/billing/composables/useBillingAutoTopUpCard'
28 : import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
29 : import { usePlatformBillingLink } from '@/platform/billing/composables/usePlatformHandoff'
30 : import { platformAutoTopUpPath } from '@/platform/billing/platformAutoTopUpPath'
31 :
32 0 : const { autoTopUpEnabled, canManageAutoTopUp, autoTopUpSetup } =
33 : useBillingCapabilities()
34 0 : const { state, ensureRead } = useBillingAutoTopUpCard()
35 :
36 0 : const canSetUp = computed(() =>
37 : canSetUpAutoTopUp({
38 : autoTopUpEnabled: autoTopUpEnabled.value,
39 : canManageAutoTopUp: canManageAutoTopUp.value,
40 : setup: autoTopUpSetup.value
41 : })
42 : )
43 :
44 0 : watch(
45 : canSetUp,
46 : (allowed) => {
47 0 : if (allowed) ensureRead()
48 : },
49 : { immediate: true }
50 : )
51 :
52 0 : const { button, open } = usePlatformBillingLink(
53 : platformAutoTopUpPath('turn_on'),
54 : {
55 : target: 'auto_top_up',
56 : action: 'turn_on'
57 : }
58 : )
59 :
60 0 : const visible = computed(() => {
61 0 : if (!canSetUp.value) return false
62 0 : const read = state.value
63 0 : return read.kind === 'loaded' && read.settings.status === 'off'
64 : })
65 : </script>
|