feat(client-utils): add createFormatters#9504
Open
n3ps wants to merge 5 commits into
Open
Conversation
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>
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>
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.
Explanation
createFormattersused 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:
formatTokenAmountformatPercentWithMinThresholdformatCompactformatDateTimeFollow-up PRs will update extension and mobile references, then deprecate the copy in
assets-controllers.References
Checklist
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
createFormattersin@metamask/client-utilsso 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 newformatTokenAmount,formatPercentWithMinThreshold,formatCompact, andformatDateTime. Implementation uses cachedIntlformatters, treats non-finite values as empty strings, and falls back on invalid currency codes.createFormattersand theFormatterstype 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.