Skip to content

fix: format extra usage in the currency reported by the usage API#418

Open
mhriemers wants to merge 1 commit into
sirmalloc:mainfrom
mhriemers:fix/extra-usage-currency
Open

fix: format extra usage in the currency reported by the usage API#418
mhriemers wants to merge 1 commit into
sirmalloc:mainfrom
mhriemers:fix/extra-usage-currency

Conversation

@mhriemers
Copy link
Copy Markdown

Summary

Fixes #415 — the usage API reports the account's billing currency (extra_usage.currency, e.g. "EUR"), but ExtraUsageRemaining always formatted with a hardcoded $, so non-USD accounts see their budget with the wrong symbol.

Changes

  • Parse the field end-to-end: currency added to UsageApiResponseSchema, CachedUsageDataSchema, both parse functions, USAGE_DATA_FIELDS / pickDefinedUsageFields in the prefetch merge, and the UsageData / RenderUsageData types (as extraUsageCurrency)
  • New shared formatter src/widgets/shared/currency.ts: formatUsageCurrency() uses Intl-based currency formatting with the en-US locale, falling back to USD when the code is absent or invalid — so output for USD accounts is byte-for-byte unchanged ($3,894.00)
  • ExtraUsageRemaining formats with the reported currency: an EUR account now sees Overage Left: €3,894.00

Testing

  • New currency.test.ts (default, known codes, invalid-code fallback)
  • New EUR case in ExtraUsageRemaining.test.ts
  • currency: 'EUR' added to the usage-fetch API fixture, asserting it parses through to extraUsageCurrency
  • Full suite: 1397 tests pass, bun run lint clean

Related to but distinct from #387 (cents/dollars math). Related: #413/#416, #414/#417.

🤖 Generated with Claude Code

The usage API reports the account's billing currency
(extra_usage.currency, e.g. "EUR"), but ExtraUsageRemaining always
formatted with a hardcoded dollar sign, showing non-USD budgets with
the wrong symbol.

Parse the currency field through the API response schema, file cache,
and prefetch merge, and format the remaining budget with
Intl-based currency formatting (falling back to USD when the field is
absent or invalid, preserving current output for USD accounts).

Fixes sirmalloc#415

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mhriemers added a commit to mhriemers/ccstatusline that referenced this pull request Jun 4, 2026
…sirmalloc#418

Once sirmalloc#418 teaches the parser about extra_usage.currency, a fixture
carrying the field would add extraUsageCurrency to the parsed result
and break this test's expectation depending on merge order. The field
is irrelevant to what this test covers (monthly_limit: null handling).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

Extra usage widgets hardcode $ instead of using the API's currency field

1 participant