refactor(money): consolidate fiat appreciation formatting - #1208
Merged
Conversation
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.
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.
What
Consolidate the fiat appreciation/depreciation sign convention into one shared helper,
Fiat.formattedAppreciation()(incore/money), used by both the balance header (CurrencyAppreciationLabel) and the per-token cards.+$0.00for a zero change, normalizing a rounds-to-zero amount to a positive zero first — fixes the+-$0.00double sign a negative-zero value produced (the formatter renders-0.0as-$0.00while>= 0is true, andtoDouble()rounds to the currency precision).+, losses keep the formatter's own-.Also
Dropped the stray space that
extraPrefixinserted at the source inFiat.formatted("+ $"→"+$"). The four intentional callers that wanted the space now bake it into their prefix string:extraPrefix = "- "extraPrefix = "~ "extraPrefix = "+ "Tests updated:
FiatTests(rawformatted()primitive →~$10.00 USD) and the withdrawal receipt test (caller keeps its space →- $0.50).Note
services/opencode/.../Fiat.ktis shared-logic parity territory — the change here is display-only (formatting), no math/quark behavior change.