Skip to content

streamsService.ts's deriveMockMetrics formats USDC totals with a third independent hardcoded "en-US" locale #1063

Description

@mikewheeleer

Description

src/lib/api/streamsService.ts has its own locally-defined formatUsdc, used by deriveMockMetrics to build the dashboard's treasury metrics:

function formatUsdc(amount: number): string {
  return `${new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(
    amount,
  )} USDC`;
}
...
export async function getTreasuryMetrics(): Promise<Metric[]> {
  if (isMockMode()) {
    return deriveMockMetrics(seededStreamRecords);
  }
  ...

Issue #727 already tracks a hardcoded-en-US formatUsdc duplicate in src/lib/recentStreamMapper.ts. This is a third, independent copy of the same pattern in a different file: streamsService.ts's formatUsdc hardcodes "en-US" in its own Intl.NumberFormat call rather than using the app's shared locale-aware formatter (src/lib/formatters.ts). Since getTreasuryMetrics() (which calls deriveMockMetrics whenever VITE_USE_MOCKS is enabled) feeds the dashboard's "Active Streams" / "Total Streaming" / "Withdrawable" metric cards, a non-US locale user running in mock mode sees US-formatted thousands separators here even after the recentStreamMapper.ts copy from #727 is fixed, because this is a wholly separate function.

Requirements

  • streamsService.ts's formatUsdc must use the app's shared locale-resolution approach from src/lib/formatters.ts instead of hardcoding "en-US", consistent with the fix required for recentStreamMapper.ts in Add idempotency-key support to the contracts write endpoints #727.
  • Preserve the existing maximumFractionDigits: 0 formatting behavior and the "USDC" suffix.

Suggested execution

  1. Import the shared locale-aware number formatter from src/lib/formatters.ts into streamsService.ts and use it inside formatUsdc, replacing the hardcoded "en-US" Intl.NumberFormat call.
  2. Consider consolidating all three formatUsdc-shaped functions (formatters.ts's canonical one, recentStreamMapper.ts's, and this one) into a single shared implementation to prevent a fourth copy from appearing later.
  3. Add a test asserting getTreasuryMetrics() in mock mode produces locale-aware output when navigator.language is set to a non-US locale.

Acceptance criteria

  • streamsService.ts's formatUsdc no longer hardcodes "en-US".
  • Mock-mode treasury metrics render locale-aware thousands separators.
  • A test covers a non-US locale.

Security notes

None; i18n correctness fix.

Guidelines

  • Minimum 95% test coverage
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    GRANTFOX OSSGrantFox open-source campaign taskMAYBE REWARDEDMay be rewarded under the GrantFox campaignOfficial Campaign | FWC26GrantFox FWC26 official campaignbugSomething isn't workingfrontendi18n

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions