Skip to content

fix(perps): Missing 1 decimal on price input when using preset on limit price#27907

Merged
abretonc7s merged 5 commits into
mainfrom
fix/perps/tat-2399-0325-1840
Mar 26, 2026
Merged

fix(perps): Missing 1 decimal on price input when using preset on limit price#27907
abretonc7s merged 5 commits into
mainfrom
fix/perps/tat-2399-0325-1840

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Description

Limit price presets (Mid, Bid, Ask, -1%, -2%) hardcoded formatWithSignificantDigits(value, 4) — 4 significant digits. For XRP-range prices (~$2.34), this truncated values to 3 decimal places ($2.342) instead of the expected 4 ($2.3418). Fixed by using DECIMAL_PRECISION_CONFIG.MaxSignificantFigures (= 5), matching the HyperLiquid API limit and the PRICE_RANGES_UNIVERSAL display config. Also added testIDs to all preset buttons for automated testing.

Changelog

CHANGELOG entry: Fixed limit price preset buttons (Mid, Bid, Ask, percentage) truncating one decimal place for low-price assets like XRP

Related issues

Fixes: TAT-2399

Manual testing steps

Feature: Limit price preset decimal precision
  Scenario: Mid preset shows correct decimals for XRP
    Given I am on the XRP Long Limit order screen
    When I open the limit price bottom sheet
    And I press the Mid preset button
    Then the limit price shows 4 decimal places (e.g., $2.3418)

  Scenario: All presets show correct decimals
    Given I am on the XRP Long Limit order screen
    When I press each preset (Mid, Bid, -1%, -2%)
    Then each preset value has 4 decimal places

  Scenario: Ask preset works for short orders
    Given I am on the XRP Short Limit order screen
    When I press the Ask preset button
    Then the limit price shows 4 decimal places

Screenshots/Recordings

Before

Bug confirmed via CDP eval: formatWithSignificantDigits(2.3418, 4)2.342 (3 decimals instead of 4)

After

after.mp4

Validation Recipe

Automated validation recipe (validate-recipe.sh)
{
  "pr": "27907",
  "title": "Limit price presets use correct decimal precision (5 sig figs)",
  "jira": "TAT-2399",
  "acceptance_criteria": [
    "Tapping any limit price preset populates the value with market-correct decimal precision",
    "Validated on XRP (reported case) and SOL (different price range)",
    "All five presets covered: Mid, Bid, Ask, -1%, -2%",
    "No regression to manual limit price entry"
  ],
  "validate": {
    "static": ["yarn lint:tsc"],
    "runtime": {
      "pre_conditions": ["wallet.unlocked", "perps.feature_enabled"],
      "steps": [
        {"id": "nav_xrp", "description": "Navigate to XRP market details", "action": "flow_ref", "ref": "market-discovery", "params": {"symbol": "XRP"}},
        {"id": "press_long", "action": "press", "test_id": "perps-market-details-long-button"},
        {"id": "wait_form", "action": "wait_for", "test_id": "perps-order-header-order-type-button"},
        {"id": "press_order_type", "action": "press", "test_id": "perps-order-header-order-type-button"},
        {"id": "wait_type_sheet", "action": "wait_for", "test_id": "perps-order-type-limit"},
        {"id": "press_limit", "action": "press", "test_id": "perps-order-type-limit"},
        {"id": "wait_limit_form", "action": "wait_for", "test_id": "perps-order-view-limit-price-row"},
        {"id": "press_price_row", "action": "press", "test_id": "perps-order-view-limit-price-row"},
        {"id": "wait_price_sheet", "action": "wait_for", "test_id": "keypad-delete-button"},
        {"id": "press_mid_xrp", "action": "press", "test_id": "perps-limit-price-preset-mid"},
        {"id": "wait_mid", "action": "wait", "ms": 500},
        {"id": "check_mid_xrp", "description": "Assert Mid preset >= 4 decimals for XRP", "action": "eval_sync", "expression": "...", "assert": {"operator": "gt", "field": "decimals", "value": 3}},
        {"id": "press_bid_xrp", "action": "press", "test_id": "perps-limit-price-preset-bid"},
        {"id": "check_bid_xrp", "description": "Assert Bid >= 4 decimals", "action": "eval_sync", "assert": {"operator": "gt", "field": "decimals", "value": 3}},
        {"id": "press_pct_minus1_xrp", "action": "press", "test_id": "perps-limit-price-preset--1"},
        {"id": "check_pct_minus1_xrp", "description": "Assert -1% >= 4 decimals", "action": "eval_sync", "assert": {"operator": "gt", "field": "decimals", "value": 3}},
        {"id": "press_pct_minus2_xrp", "action": "press", "test_id": "perps-limit-price-preset--2"},
        {"id": "check_pct_minus2_xrp", "description": "Assert -2% >= 4 decimals", "action": "eval_sync", "assert": {"operator": "gt", "field": "decimals", "value": 3}},
        {"id": "nav_sol", "action": "flow_ref", "ref": "market-discovery", "params": {"symbol": "SOL"}},
        {"id": "check_mid_sol", "description": "SOL no-regression check", "action": "eval_sync", "assert": {"operator": "eq", "field": "isValid", "value": true}},
        {"id": "nav_short_xrp", "action": "flow_ref", "ref": "market-discovery", "params": {"symbol": "XRP"}},
        {"id": "check_ask_xrp", "description": "Assert Ask >= 4 decimals", "action": "eval_sync", "assert": {"operator": "gt", "field": "decimals", "value": 3}}
      ]
    }
  }
}

Full recipe: .task/fix/tat-2399-0325-1840/artifacts/recipe.json

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and Coding Standards
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable
  • I've documented my code using JSDoc format if applicable
  • I've applied the right labels on the PR

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

Medium Risk
Touches perps limit order price entry; while the change is small, it affects how preset prices are computed and could impact order placement values if incorrect.

Overview
Fixes limit-price preset buttons (Mid/Bid/Ask and +/- % presets) to format using DECIMAL_PRECISION_CONFIG.MaxSignificantFigures instead of hardcoded 4 significant digits, preventing truncation for low-priced assets (e.g., XRP).

Adds testIDs for each preset button (including dynamic % presets) and extends PerpsLimitPriceBottomSheet tests to assert the correct decimal precision for XRP-range prices.

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

@abretonc7s abretonc7s added DO-NOT-MERGE Pull requests that should not be merged team-perps Perps team labels Mar 25, 2026
@github-actions

Copy link
Copy Markdown
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.

Limit price presets hardcoded 4 significant digits, truncating XRP-range
prices to 3 decimals ($2.342) instead of 4 ($2.3418). Use
DECIMAL_PRECISION_CONFIG.MaxSignificantFigures (5) to match the
HyperLiquid API limit and PRICE_RANGES_UNIVERSAL display config.

Also adds testIDs to all preset buttons for automated testing.
@abretonc7s

Copy link
Copy Markdown
Contributor Author

TAT-2399: Missing 1 decimal on price input when using preset on limit price

Summary

Limit price presets (Mid, Bid, Ask, -1%, -2%) used formatWithSignificantDigits(value, 4) — hardcoded to 4 significant digits. For XRP-range prices (~$2.34), this truncated the value to 3 decimal places ($2.342) instead of the expected 4 ($2.3418). Fixed by using DECIMAL_PRECISION_CONFIG.MaxSignificantFigures (= 5), matching the HyperLiquid API limit and the PRICE_RANGES_UNIVERSAL display format.

Root cause

File: app/components/UI/Perps/components/PerpsLimitPriceBottomSheet/PerpsLimitPriceBottomSheet.tsx

All 5 preset button handlers called formatWithSignificantDigits(value, 4) with a hardcoded 4 for significant digits. The correct value is DECIMAL_PRECISION_CONFIG.MaxSignificantFigures (= 5), which is the HyperLiquid API limit and matches PRICE_RANGES_UNIVERSAL.

For XRP at $2.3418 (1 integer digit):

  • Bug (4 sig figs): decimals = 4 - 1 = 3$2.342 (missing 1 decimal)
  • Fix (5 sig figs): decimals = 5 - 1 = 4$2.3418 (correct)

Reproduction commit

SHA: 5e6dff0974 — added DevLogger BUG_MARKER in the Mid preset handler.

Metro log excerpt:

(NOBRIDGE) DEBUG  [PR-27907] BUG_MARKER: preset sig figs=4, price=1.42265, result=1.423, decimals=3

Confirmed: 3 decimals instead of expected 4 for XRP-range price.

Changes

File Description
PerpsLimitPriceBottomSheet.tsx Changed 4DECIMAL_PRECISION_CONFIG.MaxSignificantFigures in all 5 preset handlers; added DECIMAL_PRECISION_CONFIG import; added testIDs to all preset buttons
Perps.testIds.ts Added PRESET_MID, PRESET_BID, PRESET_ASK, PRESET_PERCENT selector constants
PerpsLimitPriceBottomSheet.test.tsx Added 4 test cases verifying 5 sig figs for XRP-range prices (Mid, Bid, Ask, -1%)

Test plan

Automated

  • Unit tests: 48/48 passed (4 new for decimal precision)
  • Lint (ESLint): Clean
  • Type check (tsc): Clean
  • Recipe validation: 50/50 steps passed — tested Mid, Bid, -1%, -2% on XRP (4 decimals), Mid on SOL (regression check), Ask on XRP short (4 decimals)

Manual (Gherkin)

Feature: Limit price preset decimal precision
  Scenario: Mid preset shows correct decimals for XRP
    Given I am on the XRP Long Limit order screen
    When I open the limit price bottom sheet
    And I press the Mid preset button
    Then the limit price shows 4 decimal places (e.g., $2.3418)

  Scenario: All presets show correct decimals
    Given I am on the XRP Long Limit order screen
    When I press each preset (Mid, Bid, -1%, -2%)
    Then each preset value has 4 decimal places

  Scenario: Ask preset works for short orders
    Given I am on the XRP Short Limit order screen
    When I press the Ask preset button
    Then the limit price shows 4 decimal places

Evidence

  • before.mp4: Skipped — recipe requires testIDs added in the fix. Bug confirmed via CDP eval in step 7.
  • after.mp4: .task/fix/tat-2399-0325-1840/artifacts/after.mp4 — full recipe execution showing all presets with correct decimal precision.
  • Screenshots: xrp-preset-decimals.png, sol-preset-decimals.png, xrp-ask-preset-decimals.png in artifacts dir.

Ticket

@abretonc7s abretonc7s marked this pull request as ready for review March 25, 2026 11:39
@abretonc7s abretonc7s requested a review from a team as a code owner March 25, 2026 11:39
@abretonc7s abretonc7s removed the DO-NOT-MERGE Pull requests that should not be merged label Mar 26, 2026
@github-actions github-actions Bot added the risk-low Low testing needed · Low bug introduction risk label Mar 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: low
  • AI Confidence: 95%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are narrowly scoped to the Perps feature's PerpsLimitPriceBottomSheet component:

  1. PerpsLimitPriceBottomSheet.tsx: Two types of changes:

    • Added testID attributes to preset price buttons (Mid, Bid, Ask, percentage presets) — purely for testability, no functional impact
    • Changed hardcoded 4 significant figures to DECIMAL_PRECISION_CONFIG.MaxSignificantFigures (5) — a bug fix for decimal precision in limit price display
  2. Perps.testIds.ts: Added new test selector IDs (PRESET_MID, PRESET_BID, PRESET_ASK, PRESET_PERCENT) — no functional impact

  3. PerpsLimitPriceBottomSheet.test.tsx: Added unit tests for the decimal precision fix (TAT-2399)

Tag selection rationale:

  • SmokePerps: Primary tag — changes directly affect the Perps limit price bottom sheet, which is core perpetuals trading functionality
  • SmokeWalletPlatform: Required per SmokePerps description — Perps is a section inside the Trending tab, so changes to Perps views affect Trending
  • SmokeConfirmations: Required per SmokePerps description — Add Funds deposits are on-chain transactions

The risk is low as this is a targeted bug fix (decimal precision) and testID additions with no architectural changes, no shared component modifications, and no impact on navigation or other features.

Performance Test Selection:
The decimal precision change in PerpsLimitPriceBottomSheet affects how prices are formatted and displayed in the Perps trading interface. While the change is minor (4 vs 5 significant figures), it touches the Perps market loading and order execution flow. Running @PerformancePreps is a conservative measure to ensure the formatting change doesn't introduce any unexpected rendering overhead, though the actual performance impact is expected to be negligible.

View GitHub Actions results

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@abretonc7s abretonc7s added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit dee9a46 Mar 26, 2026
100 checks passed
@abretonc7s abretonc7s deleted the fix/perps/tat-2399-0325-1840 branch March 26, 2026 22:35
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
@metamaskbot metamaskbot added the release-7.73.0 Issue or pull request that will be included in release 7.73.0 label Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.73.0 Issue or pull request that will be included in release 7.73.0 risk-low Low testing needed · Low bug introduction risk size-S team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants