Skip to content

refactor: migrate formatters to @metamask/client-utils - #33733

Merged
vinnyhoward merged 2 commits into
mainfrom
refactor-tmcu-1164-introduce-client-utils
Jul 24, 2026
Merged

refactor: migrate formatters to @metamask/client-utils#33733
vinnyhoward merged 2 commits into
mainfrom
refactor-tmcu-1164-introduce-client-utils

Conversation

@vinnyhoward

@vinnyhoward vinnyhoward commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

Introduces @metamask/client-utils — the shared package for activity-redesign code across MetaMask clients (formatters + transaction mappers) — and migrates the first consumer: useFormatters now imports createFormatters from @metamask/client-utils instead of @metamask/assets-controllers.

Why: Extension has already migrated onto this package to reduce duplicated LOC (metamask-extension #44366, #44624). This PR is the mobile equivalent of extension #44624 and establishes the dependency so follow-up PRs can migrate the activity mappers

Notes for reviewers:

  • The installed implementations are logic-identical for all 7 existing formatter functions (including the RangeError fallback for invalid currency codes); @metamask/client-utils additionally exposes formatDateTime, formatTokenAmount, formatPercentWithMinThreshold, and formatCompact.
  • All of the package's dependencies dedupe against versions mobile already ships (single new lockfile entry, ~120 KiB); the existing @metamask/transaction-controller: 69.0.0 resolution flattens its transaction-controller requirement.
  • No behavior change intended: existing useFormatters unit tests (18) and consumer suites (Assets Balance components, assets-list selector — 98 tests) pass unchanged.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-1164

Manual testing steps

Feature: Locale-aware formatters via @metamask/client-utils

  Scenario: user views fiat balances on the wallet home
    Given the wallet is unlocked with a funded account
    When user opens the wallet home
    Then the account group balance shows locale-formatted fiat (e.g. "$1,234.56", and "$" never "US$" for USD)

  Scenario: user opens the Ramp buy flow
    Given user navigates to Buy and reaches the Build Quote screen
    When user views quick amount chips, provider limits, and payment method modals
    Then all currency and token amounts render identically to before this change

  Scenario: user switches device locale
    Given the app language is set to German (or another comma-decimal locale)
    When user views the wallet home balance
    Then fiat amounts use the locale's separators (e.g. "1.234,56")

Screenshots/Recordings

~

Before

~

After

~

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Low Risk
Import-path and dependency swap with intended identical formatter behavior; no auth or transaction logic changes in this diff.

Overview
Adds @metamask/client-utils and switches useFormatters so createFormatters is imported from that package instead of @metamask/assets-controllers, matching the extension’s shared activity/formatters stack.

useFormatters still memoizes formatters from the device locale via I18n; only the dependency source changes. @metamask/assets-controllers remains in the app for other imports (e.g. IPFS helpers). Lockfile picks up client-utils with deduped transitive deps.

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

@vinnyhoward vinnyhoward added the team-mobile-ux Mobile UX team label Jul 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamask-ci

metamask-ci Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Pre-merge author checklist has unchecked items (e.g. "I've tested on Android"). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

@socket-security

socket-security Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​metamask/​client-utils@​1.2.1771007795100

View full report

@vinnyhoward
vinnyhoward marked this pull request as ready for review July 23, 2026 20:32
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeSwap, SmokeStake, SmokeWalletPlatform, SmokeMoney, SmokePerps, SmokeMultiChainAPI, SmokePredictions, SmokeSeedlessOnboarding, SmokeBrowser, SmokeSnaps
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: high
  • AI Confidence: 100%
click to see 🤖 AI reasoning details

E2E Test Selection:
Hard rule (global-infrastructure-change): Global infrastructure changed: app/components/hooks/useFormatters.ts. Running all tests.

Performance Test Selection:
The change is a pure dependency migration of the createFormatters import from @metamask/assets-controllers to @metamask/client-utils. This is a refactoring with no performance implications - the formatter function behavior is identical, just sourced from a different package. No performance-sensitive code paths are affected.

View GitHub Actions results

@github-actions github-actions Bot added the risk:low AI analysis: low risk label Jul 23, 2026
@sonarqubecloud

Copy link
Copy Markdown

@vinnyhoward
vinnyhoward added this pull request to the merge queue Jul 24, 2026
Merged via the queue into main with commit ca38156 Jul 24, 2026
219 of 242 checks passed
@vinnyhoward
vinnyhoward deleted the refactor-tmcu-1164-introduce-client-utils branch July 24, 2026 22:10
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 24, 2026
@metamask-ci metamask-ci Bot added the release-8.6.0 Issue or pull request that will be included in release 8.6.0 label Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-8.6.0 Issue or pull request that will be included in release 8.6.0 risk:low AI analysis: low risk size-XS team-mobile-ux Mobile UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants