Skip to content

fix(perps): Can't create a TP/SL with 6 decimals for PUMP#27901

Merged
abretonc7s merged 8 commits into
mainfrom
fix/perps/tat-2403-0325-1528
Mar 26, 2026
Merged

fix(perps): Can't create a TP/SL with 6 decimals for PUMP#27901
abretonc7s merged 8 commits into
mainfrom
fix/perps/tat-2403-0325-1528

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Description

PUMP TP/SL price inputs were blocked at 5 decimal places due to two independent hardcoded limits. PUMP trades at ~$0.00186, so valid trigger prices require 6 decimal places (e.g. 0.001234).

Root cause (two layers):

  1. PerpsTPSLView passed decimals={TP_SL_VIEW_CONFIG.KeypadDecimals} (hardcoded 5) to <Keypad> — the keypad rule silently dropped the 6th digit
  2. usePerpsTPSLForm called hasExceededSignificantFigures(sanitized) with default maxSigFigs=5countSignificantFigures("0.001234") returns 6 (counts all decimal digits including leading zeros), blocking the state update

Fix: Replace both hardcoded limits with values from DECIMAL_PRECISION_CONFIG:

  • keypadDecimals is now computed dynamically from currentPrice: floor(-log10(price)) + MaxSignificantFigures, clamped to [2, MaxPriceDecimals]
  • hasExceededSignificantFigures now uses MaxPriceDecimals (=6) as the limit in both TP and SL handlers

Changelog

CHANGELOG entry: Fixed TP/SL trigger price input for low-price assets (e.g. PUMP) now accepting up to 6 decimal places

Related issues

Fixes: TAT-2403

Manual testing steps

Feature: PUMP TP/SL trigger price decimal precision

  Scenario: User can enter a 6-decimal TP price for PUMP
    Given I have an open PUMP long position
    When I navigate to the TP/SL screen
    And I focus the Take Profit price input
    And I type "0.001234" via the keypad
    Then the Take Profit price input shows "0.001234"

Screenshots/Recordings

Before

before.mp4

After

after.mp4

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.

Validation Recipe

Automated validation recipe (validate-recipe.sh)
{
  "pr": "27901",
  "title": "PUMP TP/SL trigger price accepts up to 6 decimal places",
  "jira": "TAT-2403",
  "acceptance_criteria": [
    "TP/SL trigger price input for PUMP accepts up to 6 decimal places (e.g. 0.001234)",
    "Decimal precision is dynamically driven by market price — not a hardcoded global constant",
    "Other markets (e.g. BTC) are unaffected — basic TP/SL via presets still works"
  ],
  "validate": {
    "static": ["yarn lint:tsc"],
    "runtime": {
      "pre_conditions": ["wallet.unlocked"],
      "steps": [
        { "id": "open_pump_position", "action": "flow_ref", "ref": "trade-open-market",
          "params": { "symbol": "PUMP", "side": "long", "usdAmount": "11" } },
        { "id": "wait_position_fill", "action": "wait_for",
          "expression": "Engine.context.PerpsController.getPositions().then(function(ps){var p=ps.filter(function(x){return x.symbol==='PUMP'});return JSON.stringify({count:p.length})})",
          "assert": { "operator": "gt", "field": "count", "value": 0 },
          "timeout_ms": 20000, "poll_ms": 1000 },
        { "id": "create_tpsl_preset", "action": "flow_ref", "ref": "tpsl-create",
          "params": { "symbol": "PUMP", "tpPreset": "25", "slPreset": "-10" } },
        { "id": "nav_tpsl_for_6dec_test", "action": "navigate", "target": "PerpsTPSL",
          "params": { "asset": "PUMP", "currentPrice": 0.00185, "direction": "long" } },
        { "id": "wait_tpsl_screen", "action": "wait_for", "route": "PerpsTPSL" },
        { "id": "focus_tp_input", "action": "eval_sync",
          "expression": "(function(){var hook=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;var found=null;function walk(f){if(!f)return;var props=f.memoizedProps;if(props&&props.testID===\"perps-tpsl-tp-input\"){found=f;return;}walk(f.child);if(!found)walk(f.sibling);}if(hook&&hook.renderers){hook.renderers.forEach(function(v,k){var roots=hook.getFiberRoots?hook.getFiberRoots(k):null;if(roots)roots.forEach(function(r){if(!found)walk(r.current);});})}if(!found)return \"not-found\";var cur=found.child;while(cur){if(cur.tag===5&&cur.stateNode){var pub=cur.stateNode.canonical&&cur.stateNode.canonical.publicInstance;if(pub&&pub.focus){pub.focus();return \"focused\";}return \"no-focus-method\";}cur=cur.child;}return \"no-host\";})()",
          "assert": { "operator": "eq", "value": "focused" } },
        { "id": "clear_tp_keypad", "action": "clear_keypad", "count": 8 },
        { "id": "type_6decimal_tp_price", "action": "type_keypad", "value": "0.001234" },
        { "id": "assert_tp_6decimal_value", "action": "eval_sync",
          "expression": "(function(){var hook=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;var found=null;function walk(f){if(!f)return;var props=f.memoizedProps;if(props&&props.testID===\"perps-tpsl-tp-input\"){found=f;return;}walk(f.child);if(!found)walk(f.sibling);}if(hook&&hook.renderers){hook.renderers.forEach(function(v,k){var roots=hook.getFiberRoots?hook.getFiberRoots(k):null;if(roots)roots.forEach(function(r){if(!found)walk(r.current);});})}if(!found)return JSON.stringify({v:\"not-found\"});return JSON.stringify({v:found.memoizedProps&&found.memoizedProps.value||\"no-value\"});})()",
          "assert": { "field": "v", "operator": "contains", "value": "001234" } },
        { "id": "check_no_blocking_errors", "action": "log_watch",
          "window_seconds": 3, "must_not_appear": ["TypeError", "RangeError"] },
        { "id": "screenshot_6decimals", "action": "screenshot", "filename": "pump-tpsl-6-decimals.png" },
        { "id": "cleanup_close_pump", "action": "flow_ref", "ref": "trade-close-position",
          "params": { "symbol": "PUMP" } }
      ]
    }
  }
}

Note

Low Risk
Low risk UI/input-validation change limited to TP/SL price entry and rounding; main risk is unintended precision/rounding differences for some markets when entering prices via keypad or percentage conversions.

Overview
Fixes TP/SL trigger price entry for very low-priced perps assets by removing hardcoded 5-decimal limits.

PerpsTPSLView now computes keypadDecimals dynamically from currentPrice (clamped by DECIMAL_PRECISION_CONFIG) and only applies it to price inputs (percentage inputs keep existing precision). usePerpsTPSLForm updates price validation and all RoE→price rounding to use DECIMAL_PRECISION_CONFIG.MaxPriceDecimals, and adds tests ensuring 6-decimal TP/SL prices (e.g. 0.001234) are accepted.

Written by Cursor Bugbot for commit 620a45c. 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.

PUMP trades at ~$0.002, requiring 6 decimal places for valid trigger
prices. Two independent hardcoded limits were blocking the 6th digit:

1. PerpsTPSLView passed decimals={TP_SL_VIEW_CONFIG.KeypadDecimals} (=5)
   to <Keypad>. Fixed: compute keypadDecimals dynamically from currentPrice
   using floor(-log10(price)) + MaxSignificantFigures, clamped to
   [2, MaxPriceDecimals].

2. usePerpsTPSLForm called hasExceededSignificantFigures(sanitized) with
   default maxSigFigs=5. countSignificantFigures counts all decimal digits
   including leading zeros, so "0.001234" scored 6 > 5 and was blocked.
   Fixed: pass MaxPriceDecimals (=6) as the limit.

Fixes: TAT-2403
@abretonc7s abretonc7s added the type-bug Something isn't working label Mar 25, 2026
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 25, 2026
@metamaskbot metamaskbot removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 25, 2026
@abretonc7s abretonc7s marked this pull request as ready for review March 25, 2026 12:55
@abretonc7s abretonc7s requested a review from a team as a code owner March 25, 2026 12:55
@abretonc7s abretonc7s removed the DO-NOT-MERGE Pull requests that should not be merged label Mar 25, 2026
Comment thread app/components/UI/Perps/hooks/usePerpsTPSLForm.ts
Update all roundToSignificantFigures calls in usePerpsTPSLForm to use
DECIMAL_PRECISION_CONFIG.MaxPriceDecimals (6) instead of the default
MaxSignificantFigures (5), matching the hasExceededSignificantFigures
validation limit already updated in this PR.
@github-actions github-actions Bot added size-M risk-low Low testing needed · Low bug introduction risk and removed size-S labels Mar 25, 2026
Comment thread app/components/UI/Perps/Views/PerpsTPSLView/PerpsTPSLView.tsx Outdated
keypadDecimals is price-based (e.g. 2 for BTC at ~$50k), but the
shared Keypad instance was applying it to both price and percentage
inputs. Switch to MaxSignificantFigures for percentage-focused inputs
so RoE % inputs always allow up to 5 decimal places.
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 26, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread app/components/UI/Perps/Views/PerpsTPSLView/PerpsTPSLView.tsx
@github-actions github-actions Bot added risk-low Low testing needed · Low bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 26, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 26, 2026
@abretonc7s abretonc7s enabled auto-merge March 26, 2026 05:01
@github-actions github-actions Bot added risk-low Low testing needed · Low bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 92%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are entirely contained within the Perps TP/SL (Take Profit/Stop Loss) feature:

  1. PerpsTPSLView.tsx: Adds dynamic keypad decimal precision computation based on current asset price using DECIMAL_PRECISION_CONFIG constants. This fixes a bug where low-value assets (e.g., PUMP at ~$0.002) couldn't enter valid trigger prices because the keypad didn't allow enough decimal places. The formula floor(-log10(price)) + MaxSignificantFigures clamped to [2, MaxPriceDecimals] is applied only when the focused input is a price field (not percentage fields).

  2. usePerpsTPSLForm.ts: Replaces hardcoded "5 significant figures" with DECIMAL_PRECISION_CONFIG.MaxPriceDecimals constant in all roundToSignificantFigures and hasExceededSignificantFigures calls throughout the TP/SL form hook. This ensures consistency between the view's decimal precision and the form's validation logic.

  3. usePerpsTPSLForm.test.ts: Adds two unit tests verifying that 6-decimal prices (e.g., '0.001234') are accepted for low-price assets like PUMP.

Tag selection rationale:

  • SmokePerps: Primary tag — changes directly affect the Perps TP/SL view and form hook
  • SmokeWalletPlatform: Required per SmokePerps tag description (Perps is a section inside Trending tab)
  • SmokeConfirmations: Required per SmokePerps tag description (Add Funds deposits are on-chain transactions)

No shared components, navigation, controllers, or infrastructure are affected. Risk is low as this is a targeted bug fix for decimal precision in a specific Perps sub-feature.

Performance Test Selection:
The changes involve a simple mathematical computation (Math.floor(-Math.log10(currentPrice))) for decimal precision and constant substitutions. There is no impact on rendering performance, list loading, state management, or any other performance-sensitive area. No performance tests are warranted.

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

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.60%. Comparing base (eb330c5) to head (620a45c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
app/components/UI/Perps/hooks/usePerpsTPSLForm.ts 62.50% 2 Missing and 1 partial ⚠️
...nts/UI/Perps/Views/PerpsTPSLView/PerpsTPSLView.tsx 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27901      +/-   ##
==========================================
- Coverage   82.60%   82.60%   -0.01%     
==========================================
  Files        4839     4839              
  Lines      124418   124420       +2     
  Branches    27726    27728       +2     
==========================================
- Hits       102774   102773       -1     
  Misses      14580    14580              
- Partials     7064     7067       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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 d0b494f Mar 26, 2026
104 checks passed
@abretonc7s abretonc7s deleted the fix/perps/tat-2403-0325-1528 branch March 26, 2026 14:19
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.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.72.0 Issue or pull request that will be included in release 7.72.0 risk-low Low testing needed · Low bug introduction risk size-M team-perps Perps team type-bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants