fix(billing): prefer funded balance over CNY in display fallback - #8412
Open
hakimonr wants to merge 2 commits into
Open
fix(billing): prefer funded balance over CNY in display fallback#8412hakimonr wants to merge 2 commits into
hakimonr wants to merge 2 commits into
Conversation
Problem: the CLI/TUI footer and /status always show the CNY entry
(¥0.00) even for USD-funded DeepSeek accounts. DisplayForCurrency("")
fell back to a legacy CNY-first pick, and DeepSeek now returns a zero CNY
entry alongside the funded USD entry in non-deterministic order, so the
status line deterministically showed ¥0.00. The serve diagnostics and
HTTP /status surfaces also ignored the display-currency preference
entirely.
Root cause: the CNY-first fallback in internal/billing/balance.go, and
CLI surfaces calling Display() without the resolved currency.
Fix: fall back to the entry with the largest funded balance instead of
CNY-first, and thread the explicit display currency into the serve
balance diagnostics and HTTP /status balance display. Explicit
preferences still win even when their own balance is zero.
Verification: go test ./internal/billing ./internal/cli ./internal/serve;
gofmt; go vet. New fixtures cover both entry orders, USD-only wallets,
unknown preferences, and malformed totals.
Refs: esengine#8107
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.
Fixes #8107
Problem
The CLI/TUI footer and
/statusalways show the CNY entry (¥0.00) for aDeepSeek account whose real (funded) balance is USD — even with
[desktop] currency = "USD"/language = "en"set.DisplayForCurrency("")fell back to a legacy CNY-first pick, and DeepSeek now returns a zero CNY
entry alongside the funded USD entry in non-deterministic order, so the
status line deterministically showed
¥0.00.The
servebalance diagnostics and the HTTP/statusbalance display alsoignored the display-currency preference entirely (
balance.Display()).Root cause
internal/billing/balance.go— a zero CNY entryalways wins over a funded USD entry.
Display()without the resolved currency(
internal/cli/serve_frontend.go,internal/serve/serve.go).Fix
internal/billing/balance.go: fall back to the entry with the largestfunded balance instead of CNY-first, so a zero CNY entry can never hide a
funded USD balance. Explicit preferences still win even when their own
balance is zero (e.g.
DisplayForCurrency("CNY")on a CNY 0.00 / USD 9.82wallet renders
¥0.00).internal/cli/serve_frontend.go+internal/serve/serve.go: threadthe explicit display currency into the balance readout
(
DisplayForCurrency(currency)), matching the TUI footer behavior.Verification
go test ./internal/billing ./internal/cli ./internal/serve— passgo vet ./internal/billing ./internal/cli ./internal/serve— cleangofmt— cleanwallets under every preference, unknown preferences, and malformed totals.
Related
the explicit currency — the funded-first fallback completes the picture
for auto/empty preferences)
Documentation-impact: none - display-only behavior change in the CLI status line and serve balance readout; no docs/*.md documents the CNY-first fallback, and the new fixtures cover the behavior in unit tests.