Reuse one USD currency formatter - #870
Open
gemdev111 wants to merge 4 commits into
Open
Conversation
Twelve files each built CurrencyFormatter(type: .currency, currencyCode: Currency.usd.rawValue), two of them inside computed properties. The package already names its shared formatters, BigNumberFormatter.standard and PercentFormatter.signed, so USD now has one too. It is a computed property rather than a stored constant: the initialiser defaults locale to Locale.current and keeps it, so a stored one would freeze formatting at first access and go stale when the region changes.
CurrencyFormatter builds its DecimalFormat lazily and caches it on the instance, so constructing one per call throws that cache away every time. Four call sites did: the transaction subtitle inside a composable, the trigger order labels, and both perpetual branches of the per-transaction value getter. They now use a file level formatter like ProviderExtras and AmountAutocloseSheet already do. Every remaining USD formatter in the app is held in a property, a remember, or a one off constant.
gemcoder21
approved these changes
Aug 11, 2026
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.
The USD formatter was constructed inline on both platforms — 12 identical call sites on iOS, and four on Android that built a new instance inside transaction rows. Both apps now reuse a single formatter.
CurrencyFormatter.usdin Formatters, declared next to the existingValueFormatter.full/.short/.autoCurrencyFormatterbuilds itsDecimalFormatlazily per instance, so a per-row instance rebuilt it on every row