Skip to content

Conversation

abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Oct 17, 2025

Description

This PR fixes two currency formatting issues in the Perps feature that were introduced in PR #20971:

  1. 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.

  2. 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:

  1. PR fix(perps): adjust decimals logic accross perps codebase #20971 changed formatPerpsFiat to default stripTrailingZeros: true for crypto token flexibility, but this broke fiat currency displays which should always show 2 decimal places.
  2. Components were using || '0' fallbacks instead of the semantic constants defined in perpsConfig.ts (FALLBACK_DATA_DISPLAY = '--', FALLBACK_PRICE_DISPLAY = '$---').

Solutions:

  1. Added stripTrailingZeros: false to PRICE_RANGES_MINIMAL_VIEW configuration template in formatUtils.ts (1 line change instead of modifying 9 call sites).
  2. Replaced all 5 hardcoded '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

Feature: Perps Currency Formatting

  Scenario: user views account balances with proper formatting
    Given user is on the Perps Positions view with account data

    When user views the account summary section
    Then total balance should display with exactly 2 decimal places (e.g., "$13.40" not "$13.4")
    And available balance should display with exactly 2 decimal places
    And margin used should display with exactly 2 decimal places

  Scenario: user views unavailable balance data
    Given user is on the Perps Positions view without account data

    When balances are unavailable or loading
    Then balance fields should display "--" instead of "$0.00"

  Scenario: user views transaction details with proper formatting
    Given user navigates to a transaction detail view

    When viewing entry price and fee information
    Then prices should display with proper formatting and trailing zeros
    And unavailable prices should show "$---" instead of "$0.00"
    And unavailable fees should show "--" instead of "$0.00"

  Scenario: user views balance in tab control bar
    Given user is on the Perps tab view

    When viewing available balance in the control bar
    Then balance should display with exactly 2 decimal places

Screenshots/Recordings

Before

  • Available balance shows "$13.4" instead of "$13.40"
  • Total balance shows "$1,250" instead of "$1,250.00"
  • Unavailable data shows "$0.00" (looks like legitimate data)

After

  • Available balance correctly shows "$13.40"
  • Total balance correctly shows "$1,250.00"
  • Unavailable data clearly shows "--" or "$---" (distinguishable from real data)

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Technical Details

Files Changed:

  1. app/components/UI/Perps/utils/formatUtils.ts

    • Added stripTrailingZeros: false to PRICE_RANGES_MINIMAL_VIEW configuration (line 339)
  2. app/components/UI/Perps/Views/PerpsPositionsView/PerpsPositionsView.tsx

    • Replaced 3 hardcoded '0' fallbacks with conditional rendering using PERPS_CONSTANTS.FALLBACK_DATA_DISPLAY
    • Locations: totalBalance (line 176-180), availableBalance (line 189-193), marginUsed (line 202-206)
  3. app/components/UI/Perps/Views/PerpsTransactionsView/PerpsPositionTransactionView.tsx

    • Replaced 2 hardcoded '0' fallbacks with semantic constants
    • Entry price uses PERPS_CONSTANTS.FALLBACK_PRICE_DISPLAY (line 106-108)
    • Fee uses PERPS_CONSTANTS.FALLBACK_DATA_DISPLAY (line 116-120)

Impact:

  • Affected Components: 3 files, 6 total changes
  • Lines Changed: ~15 lines (minimal diff)
  • Test Coverage: ESLint passes on all modified files
  • User-Facing Impact: Improved clarity and consistency in currency displays across all Perps views

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.

  • Formatting utils:
    • Revamp formatPerpsFiat defaults to use PRICE_RANGES_MINIMAL_VIEW with fiat-style stripping; add fiatStyleStripping option and adjust strip precedence.
    • Define PRICE_RANGES_MINIMAL_VIEW to preserve 2 decimals and strip only .00; tweak post-processing and range handling.
  • UI updates (null-safe + fallbacks):
    • Use explicit undefined/null checks before formatting and show semantic fallbacks from PERPS_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).
  • Tests:
    • Update expectations to reflect fiat-style decimals (e.g., $7.50, $10.50) and new minimal-view behavior in formatUtils.test.ts and order transaction tests.

Written by Cursor Bugbot for commit 4564f68. This will update automatically on new commits. Configure here.

@abretonc7s abretonc7s requested a review from a team as a code owner October 17, 2025 14:28
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

cursor[bot]

This comment was marked as outdated.

@abretonc7s abretonc7s changed the title fix(perps): balance display without full deicmals fix(perps): balance display without full decimals Oct 17, 2025
@github-actions github-actions bot added size-M and removed size-S labels Oct 17, 2025
cursor[bot]

This comment was marked as outdated.

@gambinish gambinish changed the title fix(perps): balance display without full decimals fix(perps): balance display without full decimals cp-7.58.0 Oct 17, 2025
cursor[bot]

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants