Skip to content

feat(client-utils): add createFormatters#9504

Open
n3ps wants to merge 5 commits into
mainfrom
n3ps/client-formatters
Open

feat(client-utils): add createFormatters#9504
n3ps wants to merge 5 commits into
mainfrom
n3ps/client-formatters

Conversation

@n3ps

@n3ps n3ps commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Explanation

createFormatters used for generic number, currency and Date formatting currently lives in @metamask/assets-controllers. This PR copies it into @metamask/client-utils.

Additionally add these format definitions used in the clients:

  • formatTokenAmount
  • formatPercentWithMinThreshold
  • formatCompact
  • formatDateTime

Follow-up PRs will update extension and mobile references, then deprecate the copy in assets-controllers.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Low Risk
Additive display-formatting utilities with no in-repo consumer migration in this PR; incorrect formatting could affect UX once clients adopt it, but there is no auth or transaction logic here.

Overview
Introduces createFormatters in @metamask/client-utils so extension and mobile can share locale-aware display formatting (moved from @metamask/assets-controllers; clients will switch in follow-ups).

The factory returns bound helpers for numbers, fiat, tokens, percents, compact notation, and date/time—including formatCurrencyWithMinThreshold, formatCurrencyTokenPrice, formatTokenQuantity, plus new formatTokenAmount, formatPercentWithMinThreshold, formatCompact, and formatDateTime. Implementation uses cached Intl formatters, treats non-finite values as empty strings, and falls back on invalid currency codes.

createFormatters and the Formatters type are exported from the package entrypoint; changelog and unit tests cover the new behavior.

Reviewed by Cursor Bugbot for commit 36d98a3. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy display formatters from assets-controllers into a new formatters/
folder in client-utils, baking in four extension-only helpers
(formatTokenAmount, formatPercentWithMinThreshold, formatCompact,
formatDateTime) so the factory covers the full client surface.

Co-authored-by: Cursor <cursoragent@cursor.com>
@n3ps n3ps requested review from a team as code owners July 14, 2026 14:07
@n3ps n3ps temporarily deployed to default-branch July 14, 2026 14:07 — with GitHub Actions Inactive
@n3ps n3ps enabled auto-merge July 14, 2026 14:07
n3ps and others added 4 commits July 14, 2026 10:12
Co-authored-by: Cursor <cursoragent@cursor.com>
…formatters

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.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.

1 participant