Skip to content

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

Open
abretonc7s wants to merge 4 commits intomainfrom
fix/perps/tat-2399-0325-1840
Open

fix(perps): Missing 1 decimal on price input when using preset on limit price#27907
abretonc7s wants to merge 4 commits intomainfrom
fix/perps/tat-2399-0325-1840

Conversation

@abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Mar 25, 2026

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

See .task/fix/tat-2399-0325-1840/artifacts/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 limit-order price preset calculation/rounding, which can affect the exact order price submitted (especially for low-priced assets). Scope is small and covered by new unit tests and added stable testIDs.

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

Adds explicit testIDs for each preset button (including percentage presets) and extends PerpsLimitPriceBottomSheet tests to assert correct precision for XRP-range prices.

Written by Cursor Bugbot for commit 80a6f4f. 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
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.
@github-actions
Copy link
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - draft PR

All E2E tests pre-selected.

View GitHub Actions results

@abretonc7s
Copy link
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
@github-actions
Copy link
Contributor

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

@sonarqubecloud
Copy link

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

Labels

DO-NOT-MERGE Pull requests that should not be merged size-S team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant