From e85b9b986a7d660bb1bf9e315f6f0be56532b063 Mon Sep 17 00:00:00 2001 From: john Date: Fri, 28 Aug 2026 17:37:26 +0800 Subject: [PATCH] feat(h5): show subscription quota totals in balance popover Display plan total, remaining, and used amounts with plain comma-separated numbers so H5 balance details match backend token accounting. Co-authored-by: Cursor --- src/components/BalanceRing.tsx | 222 ++++++++++++++++++--------------- 1 file changed, 124 insertions(+), 98 deletions(-) diff --git a/src/components/BalanceRing.tsx b/src/components/BalanceRing.tsx index 09ff773..1f9e2b9 100644 --- a/src/components/BalanceRing.tsx +++ b/src/components/BalanceRing.tsx @@ -11,22 +11,13 @@ function formatYuan(cents: number) { return `¥${(cents / 100).toFixed(2)}`; } -function formatTokenCount(tokens: number) { - if (tokens >= 100_000) { - return `${(tokens / 10_000).toFixed(1).replace(/\.0$/, '')} 万`; - } - if (tokens >= 10_000) { - return `${(tokens / 10_000).toFixed(2).replace(/\.?0+$/, '')} 万`; - } - if (tokens >= 1_000) { - return `${(tokens / 1_000).toFixed(1).replace(/\.0$/, '')}k`; - } - return tokens.toLocaleString('zh-CN'); +function formatQuotaAmount(tokens: number) { + return tokens.toLocaleString('en-US'); } -function formatCallsApprox(tokens: number) { - const calls = Math.floor(tokens / 3000); - return `约 ${calls} 次`; +function formatTokenQuota(limit: number, used: number) { + const remaining = Math.max(0, limit - used); + return { total: limit, remaining, used }; } function formatImageQuota(sub: ActiveSubscription) { @@ -39,6 +30,59 @@ function formatImageQuota(sub: ActiveSubscription) { return { unlimited: false, remaining, total, used }; } +type QuotaUsageRowsProps = { + totalLabel: string; + totalValue: string; + remainingValue: string; + usedValue: string; + total: number; + remaining: number; + used: number; +}; + +function QuotaUsageRows({ + totalLabel, + totalValue, + remainingValue, + usedValue, + total, + remaining, + used, +}: QuotaUsageRowsProps) { + return ( + <> +
+ {totalLabel} + {totalValue} +
+
+ + + {remainingValue} +
+
+ + + {usedValue} +
+