Skip to content

Conversation

@nickewansmith
Copy link
Contributor

@nickewansmith nickewansmith commented Oct 30, 2025

Description

Fixed the decimal precision issue for token amounts displayed in the Perps Close Position screen. The component now uses asset-specific szDecimals from market metadata to format position sizes correctly, ensuring proper display across different cryptocurrencies.

🐛 Problem
Previously, formatPositionSize was called without the szDecimals parameter, causing inconsistent decimal precision across different assets. This resulted in either too many or too few decimal places being displayed for token amounts (e.g., BTC showing too many decimals, DOGE showing unnecessary precision).

✅ Solution
Added usePerpsMarketData hook to fetch market metadata for the position's asset
Passed marketData?.szDecimals to both formatPositionSize calls:
Token amount display in PerpsAmountDisplay component
Token amount in the toggle container text
The formatting now respects asset-specific decimal precision

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-1922

Manual testing steps

Feature: Position Close Token Amount Formatting

  Background:
    Given the user has an open position
    And the user navigates to the Close Position screen

  Scenario: Display token amounts with asset-specific decimal precision
    Given the position is for <asset> with szDecimals of <decimals>
    When the close amount is calculated
    Then the token amount displays with <decimals> decimal places
    And no unnecessary trailing zeros are shown

  Scenario: Update token display when close percentage changes
    Given the position has specific szDecimals
    When the user adjusts the close percentage slider
    Then the token amount updates in real-time
    And maintains correct decimal precision

  Scenario: Handle missing market data gracefully
    Given the market data is unavailable
    When the close position screen loads
    Then the token amount displays with fallback formatting
    And the component does not crash

  Scenario: Format partial close amounts correctly
    Given the user selects a partial close percentage
    When the token amount is calculated
    Then the display uses asset-specific decimal precision
    And shows accurate fractional token amounts

Screenshots/Recordings

Before

After

Simulator Screenshot - iPhone 16 Pro - 2025-10-30 at 18 47 36

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.

Note

Uses asset-specific szDecimals from market data to format token amounts in Close Position and adds focused tests; minor key fix in error list rendering.

  • Perps Close Position (UI):
    • Integrate usePerpsMarketData(position.coin) and pass marketData?.szDecimals to formatPositionSize for tokenAmount and the toggle text.
    • Use stable keys for validation messages (error-${index}).
  • Tests:
    • Add comprehensive coverage for szDecimals/market data integration (varying assets/precisions, loading, errors, missing data, small/large sizes) and hook invocation with correct coin.

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

@github-actions
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.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Oct 30, 2025
@nickewansmith nickewansmith marked this pull request as ready for review October 30, 2025 23:54
@nickewansmith nickewansmith requested a review from a team as a code owner October 30, 2025 23:54
@nickewansmith nickewansmith added the team-perps Perps team label Oct 31, 2025
abretonc7s
abretonc7s previously approved these changes Oct 31, 2025
@nickewansmith nickewansmith added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Oct 31, 2025
@nickewansmith nickewansmith removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Oct 31, 2025
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Oct 31, 2025
@nickewansmith nickewansmith force-pushed the TAT-1922-too-many-decimals-displayed-for-tokens-in-close-screen branch from da23b77 to 89b30c3 Compare October 31, 2025 18:03
@nickewansmith nickewansmith removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Oct 31, 2025
@nickewansmith
Copy link
Contributor Author

@gambinish this was prev approved but i add sonar cloud updates that were blocking and also unrelated to the PR. Those were mostly removed after the rebase with main just now.

@sonarqubecloud
Copy link

Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stamping based on previous approval

@nickewansmith nickewansmith added this pull request to the merge queue Oct 31, 2025
Merged via the queue into main with commit 5648737 Oct 31, 2025
92 checks passed
@nickewansmith nickewansmith deleted the TAT-1922-too-many-decimals-displayed-for-tokens-in-close-screen branch October 31, 2025 18:55
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2025
@metamaskbot metamaskbot added the release-7.59.0 Issue or pull request that will be included in release 7.59.0 label Oct 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.59.0 Issue or pull request that will be included in release 7.59.0 size-M skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-earn team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants