fix(dashboard): cost displays follow wallet currency, not hardcoded USD#360
Merged
fix(dashboard): cost displays follow wallet currency, not hardcoded USD#360
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User reported: dashboard shows
session $0.5190while the same session in the CLI showssession ¥0.024. The dashboard was always rendering costs as USD viafmtUsd(), even though the CLI converts USD → CNY for CNY wallets viaformatCost()insrc/cli/ui/theme/tokens.ts.Fix
fmtCost(usd, currency, fractionDigits?)helper indashboard/src/lib/format.ts. Mirrors the CLI: CNY converts viaUSD_TO_CNY = 7.2, USD passes through, undefined defaults to CNY (matches CLI).overview.tscurrent-session cost + cost-trend day average threadc.balance?.currencyintofmtCost().chat.tsSideRail cost / budget rows and ChatStatusBar turn / session cost rows pull currency fromstats.balance[0].currency.fmtUsd()kept as-is forusage.tsClaude-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 dashboardcleannpx vitest run— 165/165 test files, 2425 tests pass/dashboardwith a CNY wallet, confirm session cost reads¥X.XXXXmatching the CLI