Skip to content

fix(dashboard): cost displays follow wallet currency, not hardcoded USD#360

Merged
esengine merged 1 commit intomainfrom
fix-dashboard-cost-currency
May 7, 2026
Merged

fix(dashboard): cost displays follow wallet currency, not hardcoded USD#360
esengine merged 1 commit intomainfrom
fix-dashboard-cost-currency

Conversation

@esengine
Copy link
Copy Markdown
Owner

@esengine esengine commented May 7, 2026

Summary

User reported: dashboard shows session $0.5190 while the same session in the CLI shows session ¥0.024. The dashboard was always rendering costs as USD via fmtUsd(), even though the CLI converts USD → CNY for CNY wallets via formatCost() in src/cli/ui/theme/tokens.ts.

Fix

  • New fmtCost(usd, currency, fractionDigits?) helper in dashboard/src/lib/format.ts. Mirrors the CLI: CNY converts via USD_TO_CNY = 7.2, USD passes through, undefined defaults to CNY (matches CLI).
  • overview.ts current-session cost + cost-trend day average thread c.balance?.currency into fmtCost().
  • chat.ts SideRail cost / budget rows and ChatStatusBar turn / session cost rows pull currency from stats.balance[0].currency.
  • Existing fmtUsd() kept as-is for usage.ts Claude-equivalent comparisons — those are intentionally USD because Claude's API is USD-priced regardless of the user's wallet.

Test plan

  • npx tsc --noEmit -p dashboard clean
  • npx vitest run — 165/165 test files, 2425 tests pass
  • Manual: open /dashboard with a CNY wallet, confirm session cost reads ¥X.XXXX matching the CLI

CLI shows session cost in the wallet's currency (¥ for CNY wallets,
$ for USD), but the dashboard always used `fmtUsd()` which prints
the raw stored USD with a `$`. CNY users saw `$0.5190` in the
dashboard for the same session that read `¥0.024` in the CLI — both
the symbol AND the magnitude diverged because no conversion happened.

- New `fmtCost(usd, currency, fractionDigits?)` helper in
  `dashboard/src/lib/format.ts`. Mirrors the CLI's `formatCost()` —
  CNY converts via `USD_TO_CNY = 7.2`, USD passes through, undefined
  defaults to CNY.
- `overview.ts` current-session cost + cost-trend day average now
  thread `c.balance?.currency` into `fmtCost()`.
- `chat.ts` SideRail cost / budget rows and ChatStatusBar
  turn / session cost rows pull currency from `stats.balance[0]`.
- Existing `fmtUsd()` kept as-is for places where USD is intentional
  (Claude-equivalent comparisons in usage.ts) — those stay USD because
  Claude's API is USD-priced regardless of the user's wallet.
@esengine esengine merged commit 62813e3 into main May 7, 2026
3 checks passed
@esengine esengine deleted the fix-dashboard-cost-currency branch May 7, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant