Skip to content
Open
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
8 changes: 3 additions & 5 deletions desktop-tauri/mobile/src/core/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { apiCall } from './client'
import { locale } from './i18n'
import type { UsageQueryRow } from '../../../ui-shared/usage-query-state'

/* ─── 会话与账号 ─────────────────────────────────────────── */

Expand Down Expand Up @@ -154,12 +155,10 @@ export function clearAccountRateLimits(

/* ─── 账号余额与额度 ─────────────────────────────────────── */

export type UsageRow = {
id?: string
/** 服务端把余额读数放在 `usage` 里;保留少量旧字段兼容老快照。 */
export type UsageRow = UsageQueryRow & {
provider?: string
name?: string
ok?: boolean
error?: string | null
summary?: string | null
balance?: string | number | null
remaining?: string | number | null
Expand All @@ -175,7 +174,6 @@ export type UsageRow = {
remaining?: string | number | null
unit?: string | null
}>
[key: string]: unknown
}

export type UsageSnapshot = {
Expand Down
11 changes: 11 additions & 0 deletions desktop-tauri/mobile/src/core/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ export function formatNumber(num?: number | null): string {
return Math.round(num).toLocaleString(numberLocaleTag())
}

/** 余额和额度保留最多两位小数;请求次数等计数继续走 formatNumber。 */
export function formatUsageNumber(num?: number | null): string {
if (num === undefined || num === null || !Number.isFinite(num)) return '0'
const rounded = Number(num.toFixed(2))
if (rounded === 0 && num !== 0) {
const threshold = (0.01).toLocaleString(numberLocaleTag())
return num < 0 ? `>-${threshold}` : `<${threshold}`
}
return (Object.is(rounded, -0) ? 0 : rounded).toLocaleString(numberLocaleTag())
}

export function formatPercent(ratioOrPercent?: number | null, isRatio = false): string {
if (ratioOrPercent === undefined || ratioOrPercent === null || !Number.isFinite(ratioOrPercent)) {
return '0%'
Expand Down
Loading