Skip to content

Reuse one USD currency formatter - #870

Open
gemdev111 wants to merge 4 commits into
mainfrom
refactor/reuse-usd-currency-formatter
Open

Reuse one USD currency formatter#870
gemdev111 wants to merge 4 commits into
mainfrom
refactor/reuse-usd-currency-formatter

Conversation

@gemdev111

Copy link
Copy Markdown
Collaborator

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.

  • iOS: CurrencyFormatter.usd in Formatters, declared next to the existing ValueFormatter.full / .short / .auto
  • Android: the four inline constructions become file-level values, matching the ten call sites that already hold one — CurrencyFormatter builds its DecimalFormat lazily per instance, so a per-row instance rebuilt it on every row

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.
@gemdev111 gemdev111 self-assigned this Aug 11, 2026
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.

2 participants