From bb70634a9635392b5da7d17bdc1b32a699acd762 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 16 Jun 2026 01:03:35 -0700 Subject: [PATCH] Remove recent billing list from balance popover. Keep the popover focused on balance summary and token usage without fetching usage records on open. Co-authored-by: Cursor --- src/components/BalanceRing.tsx | 87 ---------------------------------- src/index.css | 48 ------------------- 2 files changed, 135 deletions(-) diff --git a/src/components/BalanceRing.tsx b/src/components/BalanceRing.tsx index 7a1d4b6..cf68344 100644 --- a/src/components/BalanceRing.tsx +++ b/src/components/BalanceRing.tsx @@ -1,11 +1,8 @@ import { useEffect, useRef, useState, type CSSProperties } from 'react'; -import { getMyUsage } from '../api/client'; -import type { UsageRecord } from '../types'; const RING_R = 16; const CIRC = 2 * Math.PI * RING_R; const POPOVER_WIDTH = 260; -const RECENT_USAGE_LIMIT = 5; function formatYuan(cents: number) { return `¥${(cents / 100).toFixed(2)}`; @@ -24,30 +21,6 @@ function formatTokenCount(tokens: number) { return tokens.toLocaleString('zh-CN'); } -function formatTokenCompact(tokens: number) { - if (tokens >= 1_000) { - return `${(tokens / 1_000).toFixed(1).replace(/\.0$/, '')}k`; - } - return String(tokens); -} - -function formatUsageTime(ts: number) { - const date = new Date(ts); - const now = new Date(); - const isToday = - date.getFullYear() === now.getFullYear() && - date.getMonth() === now.getMonth() && - date.getDate() === now.getDate(); - const time = date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }); - if (isToday) return `今天 ${time}`; - return date.toLocaleString('zh-CN', { - month: 'numeric', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', - }); -} - type BalanceRingProps = { balanceCents: number; totalCreditCents?: number; @@ -63,9 +36,6 @@ export function BalanceRing({ }: BalanceRingProps) { const [open, setOpen] = useState(false); const [popoverStyle, setPopoverStyle] = useState({}); - const [usageRecords, setUsageRecords] = useState(null); - const [usageLoading, setUsageLoading] = useState(false); - const [usageError, setUsageError] = useState(null); const wrapRef = useRef(null); const total = Math.max(totalCreditCents ?? balanceCents, balanceCents, 0); @@ -78,7 +48,6 @@ export function BalanceRing({ const low = balanceCents > 0 && balanceCents <= 100; const empty = balanceCents <= 0; - const showRecentUsage = low || empty; useEffect(() => { if (!open) return; @@ -118,36 +87,6 @@ export function BalanceRing({ }; }, [open]); - useEffect(() => { - if (!open) return; - let cancelled = false; - setUsageLoading(true); - setUsageError(null); - void getMyUsage() - .then((records) => { - if (!cancelled) setUsageRecords(records); - }) - .catch((err) => { - if (!cancelled) { - setUsageError(err instanceof Error ? err.message : '加载失败'); - } - }) - .finally(() => { - if (!cancelled) setUsageLoading(false); - }); - return () => { - cancelled = true; - }; - }, [open, tokensUsed, balanceCents]); - - useEffect(() => { - if (open) return; - setUsageRecords(null); - setUsageError(null); - setUsageLoading(false); - }, [open]); - - const recentUsage = (usageRecords ?? []).slice(0, RECENT_USAGE_LIMIT); const centerLabel = total <= 0 ? '—' : empty ? '0%' : `${pct}%`; const ariaLabel = total > 0 ? `账户额度,剩余 ${pct}%` : '账户额度'; @@ -219,32 +158,6 @@ export function BalanceRing({

按人民币结算,每次对话按实际用量扣费

-
-
近期扣费
- {usageLoading ? ( -

加载中…

- ) : usageError ? ( -

{usageError}

- ) : recentUsage.length === 0 ? ( -

暂无扣费记录

- ) : ( -
    - {recentUsage.map((row) => ( -
  • - {formatUsageTime(row.createdAt)} - - 输入 {formatTokenCompact(row.inputTokens)} / 输出{' '} - {formatTokenCompact(row.outputTokens)} - - {formatYuan(row.costCents)} -
  • - ))} -
- )} -
-