Expand AITURK Turkish settings and desktop surfaces for beta 5
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { type BillingCopy, DEFAULT_BILLING_COPY } from './copy'
|
||||
import type { BillingStateResponse } from './types'
|
||||
import { EMPTY_BILLING_VALUE } from './use-billing-state'
|
||||
|
||||
@@ -49,22 +50,23 @@ export function initialAutoReloadAmount(...candidates: Array<null | string | und
|
||||
export function validateAutoReloadInputs(
|
||||
thresholdRaw: string,
|
||||
reloadToRaw: string,
|
||||
bounds: Pick<BillingStateResponse, 'max_usd' | 'min_usd'>
|
||||
bounds: Pick<BillingStateResponse, 'max_usd' | 'min_usd'>,
|
||||
copy: BillingCopy = DEFAULT_BILLING_COPY
|
||||
): { error?: string; values?: { reloadTo: string; threshold: string } } {
|
||||
const threshold = validateBillingAmount('Threshold', thresholdRaw, bounds)
|
||||
const threshold = validateBillingAmount(copy.threshold, thresholdRaw, bounds, copy)
|
||||
|
||||
if (threshold.error || threshold.amount == null) {
|
||||
return { error: threshold.error }
|
||||
}
|
||||
|
||||
const reloadTo = validateBillingAmount('Reload-to', reloadToRaw, bounds)
|
||||
const reloadTo = validateBillingAmount(copy.reloadLabel, reloadToRaw, bounds, copy)
|
||||
|
||||
if (reloadTo.error || reloadTo.amount == null) {
|
||||
return { error: reloadTo.error }
|
||||
}
|
||||
|
||||
if (reloadTo.amount <= threshold.amount) {
|
||||
return { error: 'Reload-to amount must be greater than the threshold.' }
|
||||
return { error: copy.reloadGreater }
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -78,30 +80,31 @@ export function validateAutoReloadInputs(
|
||||
export function validateBillingAmount(
|
||||
label: string,
|
||||
raw: string,
|
||||
bounds: Pick<BillingStateResponse, 'max_usd' | 'min_usd'>
|
||||
bounds: Pick<BillingStateResponse, 'max_usd' | 'min_usd'>,
|
||||
copy: BillingCopy = DEFAULT_BILLING_COPY
|
||||
): { amount?: number; error?: string } {
|
||||
const cleaned = raw.trim().replace(/^\$/, '').trim()
|
||||
|
||||
if (!cleaned || !/^\d+(\.\d{1,2})?$/.test(cleaned)) {
|
||||
return { error: `${label}: enter a dollar amount with at most 2 decimal places.` }
|
||||
return { error: copy.invalidAmount(label) }
|
||||
}
|
||||
|
||||
const amount = Number(cleaned)
|
||||
|
||||
if (!(amount > 0)) {
|
||||
return { error: `${label}: amount must be greater than $0.` }
|
||||
return { error: copy.positiveAmount(label) }
|
||||
}
|
||||
|
||||
const min = parseAmount(bounds.min_usd)
|
||||
|
||||
if (min != null && amount < min) {
|
||||
return { error: `${label}: minimum is ${formatMoney(min)}.` }
|
||||
return { error: copy.minAmount(label, formatMoney(min)) }
|
||||
}
|
||||
|
||||
const max = parseAmount(bounds.max_usd)
|
||||
|
||||
if (max != null && amount > max) {
|
||||
return { error: `${label}: maximum is ${formatMoney(max)}.` }
|
||||
return { error: copy.maxAmount(label, formatMoney(max)) }
|
||||
}
|
||||
|
||||
return { amount }
|
||||
|
||||
Reference in New Issue
Block a user