Line data Source code
1 : import type { AutoReloadSettings } from '@comfyorg/ingest-types'
2 :
3 : export type AutoTopUpBannerKind = 'autoTopUpFailed' | 'autoTopUpOff'
4 :
5 : export interface AutoTopUpBannerInput {
6 : enabled: boolean
7 : canManageAutoTopUp: boolean
8 : isPaused: boolean
9 : hasActivePlan: boolean
10 : status: AutoReloadSettings['status'] | null
11 : disabledReason: string | null
12 : }
13 :
14 : /** The auto top-up banner for a served failed auto top-up, shown only to who can manage it on an active plan. */
15 7 : export function deriveAutoTopUpBanner(
16 : input: AutoTopUpBannerInput
17 : ): AutoTopUpBannerKind | null {
18 7 : if (!input.enabled || !input.canManageAutoTopUp) return null
19 7 : if (input.isPaused || !input.hasActivePlan) return null
20 4 : if (input.status !== 'failed') return null
21 7 : return input.disabledReason === 'consecutive_declines'
22 : ? 'autoTopUpOff'
23 : : 'autoTopUpFailed'
24 : }
|