Skip to content

fix(desktop): use balance currency as session currency source, prevent ¥→$ flip after first turn / 修复成本符号显示不正确#4504

Closed
JesonChou wants to merge 1 commit into
esengine:main-v2from
JesonChou:fix/4500-session-currency-overwrite
Closed

fix(desktop): use balance currency as session currency source, prevent ¥→$ flip after first turn / 修复成本符号显示不正确#4504
JesonChou wants to merge 1 commit into
esengine:main-v2from
JesonChou:fix/4500-session-currency-overwrite

Conversation

@JesonChou

@JesonChou JesonChou commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #4500.

Status bar session cost shows ¥ at startup, then flips to $ after the first conversation turn and never recovers.

Root cause: sessionCurrency was hardcoded to "¥" in initialState, but usage events from the backend carry "$" (DeepSeek pricing config has Currency: "$"). The reducer unconditionally replaced the value:

const sessionCurrency = e.usage?.currency || s.sessionCurrency || "¥";
//                      ^^^^^^^^^^^^^^^^^^
//                      "$" from DeepSeek pricing, overwrites "¥" every turn

A naive priority swap would freeze ¥ forever, breaking USD-billing users.

Solution

Three-tier fallback, with the balance endpoint as the source of truth. Once set, sessionCurrency is never overwritten:

Balance (real billing currency — most reliable)
  ↓ fallback
Usage event (model pricing config)
  ↓ fallback
"¥" (default)

The balance endpoint already receives per-currency data from DeepSeek ("CNY", "USD"). A new Currency() method exposes the raw symbol, piped through BalanceInfo to the frontend.

Scenario coverage

User Balance Source Result
Chinese UI, CNY billing "¥" balance endpoint Stays ¥
English UI, USD billing "$" balance endpoint Stays $
No balance endpoint first usage event Stays as set
Nothing available default ¥

Files changed

File +/− What
internal/billing/balance.go +18/−5 Currency() method + primaryInfo helper
desktop/app.go +4/−2 BalanceInfo.Currency field
desktop/frontend/src/lib/types.ts +2/−1 BalanceInfo.currency field
desktop/frontend/src/lib/useController.ts +4/−4 空初始值 + balance 优先 + reset 保留

Verification

  • ✅ 25 frontend test suites — zero failures
  • ✅ Go internal/billing + desktop compile cleanly

@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 15, 2026
@JesonChou JesonChou changed the title fix(desktop): use balance currency as session currency source, prevent ¥→$ flip after first turn fix(desktop): use balance currency as session currency source, prevent ¥→$ flip after first turn / 修复成本符号显示不正确 Jun 15, 2026
@JesonChou JesonChou force-pushed the fix/4500-session-currency-overwrite branch from b0d4833 to 538bd59 Compare June 15, 2026 09:37
@SivanCola

Copy link
Copy Markdown
Collaborator

Thanks @JesonChou. We are closing this PR as superseded by #4329, which is now the canonical integration route for the cost/currency/status-bar work.

Your contribution is recorded in #4329: you diagnosed the session currency flip from ¥ to $ after the first conversation turn, proposed balance currency as the preferred source of truth, and tightened the reducer fallback behavior so user-visible billing currency stays stable.

You are acknowledged in #4329 as a repository co-contributor for this work.

@SivanCola SivanCola closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 货币单位错误

2 participants