fix(perps): balance display without full decimals cp-7.58.0 #21355
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.
Description
This PR fixes two currency formatting issues in the Perps feature that were introduced in PR #20971:
Missing Trailing Zeros: Fiat currency values were displaying without trailing zeros (e.g., "$13.40" showing as "$13.4", "$1,250.00" showing as "$1,250"). This violated standard fiat currency formatting conventions.
Misleading Zero Fallbacks: Several components were using hardcoded
'0'
fallbacks instead of semantic constants, making "$0.00" look like legitimate data when it actually represented unavailable/loading state.Root Causes:
formatPerpsFiat
to defaultstripTrailingZeros: true
for crypto token flexibility, but this broke fiat currency displays which should always show 2 decimal places.|| '0'
fallbacks instead of the semantic constants defined inperpsConfig.ts
(FALLBACK_DATA_DISPLAY = '--'
,FALLBACK_PRICE_DISPLAY = '$---'
).Solutions:
stripTrailingZeros: false
toPRICE_RANGES_MINIMAL_VIEW
configuration template informatUtils.ts
(1 line change instead of modifying 9 call sites).'0'
fallbacks with conditional rendering using appropriate semantic constants.Changelog
CHANGELOG entry: Fixed fiat currency formatting to always display two decimal places and use semantic fallback indicators for unavailable data
Related issues
Fixes: [Internal issue - currency formatting regression after PR #20971]
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Technical Details
Files Changed:
app/components/UI/Perps/utils/formatUtils.ts
stripTrailingZeros: false
toPRICE_RANGES_MINIMAL_VIEW
configuration (line 339)app/components/UI/Perps/Views/PerpsPositionsView/PerpsPositionsView.tsx
'0'
fallbacks with conditional rendering usingPERPS_CONSTANTS.FALLBACK_DATA_DISPLAY
app/components/UI/Perps/Views/PerpsTransactionsView/PerpsPositionTransactionView.tsx
'0'
fallbacks with semantic constantsPERPS_CONSTANTS.FALLBACK_PRICE_DISPLAY
(line 106-108)PERPS_CONSTANTS.FALLBACK_DATA_DISPLAY
(line 116-120)Impact:
Note
Restores fiat-style formatting (preserve 2 decimals, strip only .00 when configured) and replaces hardcoded '0' fallbacks with semantic placeholders across Perps views, plus updates tests.
formatPerpsFiat
defaults to usePRICE_RANGES_MINIMAL_VIEW
with fiat-style stripping; addfiatStyleStripping
option and adjust strip precedence.PRICE_RANGES_MINIMAL_VIEW
to preserve 2 decimals and strip only.00
; tweak post-processing and range handling.undefined/null
checks before formatting and show semantic fallbacks fromPERPS_CONSTANTS
in:PerpsOrderView
(limitPrice
,marginRequired
),PerpsPositionsView
(balances),PerpsPositionTransactionView
(entry price, fees),PerpsLimitPriceBottomSheet
(current price),PerpsOpenOrderCard
(TP/SL),PerpsPositionCard
(TP/SL, liquidation price),PerpsTPSLBottomSheet
(entry/current/liquidation prices),PerpsTabControlBar
(balance uses minimal view ranges).$7.50
,$10.50
) and new minimal-view behavior informatUtils.test.ts
and order transaction tests.Written by Cursor Bugbot for commit 4564f68. This will update automatically on new commits. Configure here.