Skip to content

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

Merged
sirmalloc merged 2 commits into
sirmalloc:mainfrom
mhriemers:fix/extra-usage-currency
Jun 14, 2026
Merged

sirmalloc merged 2 commits into
sirmalloc:mainfrom
mhriemers:fix/extra-usage-currency

Conversation

@mhriemers

Copy link
Copy Markdown
Contributor

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>
sirmalloc added a commit that referenced this pull request Jun 14, 2026
… is set (#416)

* fix: treat enabled extra usage without a monthly limit as complete usage data

Accounts with extra usage enabled but no monthly limit configured
(monthly_limit: null) never receive extraUsageLimit/extraUsageUtilization
from the usage API. hasRequiredUsageField treated those absent fields as
incomplete data on every fetch - including successful ones - so cached
data was never accepted, the fetch loop re-fetched each cycle, and the
extra usage widgets surfaced the cached lock error as a permanent
[Timeout].

Extend the existing extraUsageEnabled === false special case to any
response where the extra usage state is known: once the API has told us
whether extra usage is enabled, absent detail fields are conclusive and
refetching cannot produce them.

Fixes #413

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: drop currency from no-limit fixture to stay order-independent of #418

Once #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>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Matthew Breedlove <sirmalloc@gmail.com>
@sirmalloc
sirmalloc merged commit 2d85849 into sirmalloc:main Jun 14, 2026
3 checks passed
@sirmalloc

Copy link
Copy Markdown
Owner

Thanks for this, it'll be published in the next release.

tahodev pushed a commit to tahodev/ccstatusline that referenced this pull request Oct 20, 2026
… is set (sirmalloc#416)

* fix: treat enabled extra usage without a monthly limit as complete usage data

Accounts with extra usage enabled but no monthly limit configured
(monthly_limit: null) never receive extraUsageLimit/extraUsageUtilization
from the usage API. hasRequiredUsageField treated those absent fields as
incomplete data on every fetch - including successful ones - so cached
data was never accepted, the fetch loop re-fetched each cycle, and the
extra usage widgets surfaced the cached lock error as a permanent
[Timeout].

Extend the existing extraUsageEnabled === false special case to any
response where the extra usage state is known: once the API has told us
whether extra usage is enabled, absent detail fields are conclusive and
refetching cannot produce them.

Fixes sirmalloc#413

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: drop currency from no-limit fixture to stay order-independent of 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>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Matthew Breedlove <sirmalloc@gmail.com>
tahodev pushed a commit to tahodev/ccstatusline that referenced this pull request Oct 20, 2026
…rmalloc#418)

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>
Co-authored-by: Matthew Breedlove <sirmalloc@gmail.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

2 participants