Skip to content

refactor(money): consolidate fiat appreciation formatting - #1208

Merged
bmc08gt merged 1 commit into
code/cashfrom
refactor/appreciation-format
Aug 10, 2026
Merged

refactor(money): consolidate fiat appreciation formatting#1208
bmc08gt merged 1 commit into
code/cashfrom
refactor/appreciation-format

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

What

Consolidate the fiat appreciation/depreciation sign convention into one shared helper, Fiat.formattedAppreciation() (in core/money), used by both the balance header (CurrencyAppreciationLabel) and the per-token cards.

  • Always shows +$0.00 for a zero change, normalizing a rounds-to-zero amount to a positive zero first — fixes the +-$0.00 double sign a negative-zero value produced (the formatter renders -0.0 as -$0.00 while >= 0 is true, and toDouble() rounds to the currency precision).
  • Gains get +, losses keep the formatter's own -.

Also

Dropped the stray space that extraPrefix inserted at the source in Fiat.formatted ("+ $""+$"). The four intentional callers that wanted the space now bake it into their prefix string:

  • withdrawal fee → extraPrefix = "- "
  • buy/sell receipt approx → extraPrefix = "~ "
  • market-cap change → extraPrefix = "+ "

Tests updated: FiatTests (raw formatted() primitive → ~$10.00 USD) and the withdrawal receipt test (caller keeps its space → - $0.50).

Note

services/opencode/.../Fiat.kt is shared-logic parity territory — the change here is display-only (formatting), no math/quark behavior change.

Extract the appreciation sign convention into one shared helper,
`Fiat.formattedAppreciation()` (core/money), used by both the balance
header (CurrencyAppreciationLabel) and the per-token cards:

- Always shows "+$0.00" for a zero change, normalizing a rounds-to-zero
  amount to a positive zero first — fixes the "+-$0.00" double sign that
  a negative-zero value produced (formatter renders -0.0 as "-$0.00"
  while `>= 0` is true).
- Gains get "+", losses keep the formatter's own "-".

Also drop the stray space `extraPrefix` inserted at the source in
`Fiat.formatted` ("+ $" -> "+$"); the four intentional callers that
wanted the space (fee "- ", approx "~ ", market-cap "+ ") now bake it
into their prefix string. Tests updated accordingly.
@github-actions github-actions Bot added type: refactor Code restructuring, no behavior change area: payments Payments, transfers, intents, billing area: network gRPC, connectivity, API, exchange rates area: tokens Token accounts, balances, token info labels Aug 10, 2026
@bmc08gt
bmc08gt merged commit c33c2ef into code/cash Aug 10, 2026
3 of 4 checks passed
@bmc08gt
bmc08gt deleted the refactor/appreciation-format branch August 10, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: network gRPC, connectivity, API, exchange rates area: payments Payments, transfers, intents, billing area: tokens Token accounts, balances, token info type: refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant