Commit dee9a46
authored
fix(perps): Missing 1 decimal on price input when using preset on limit price (#27907)
## **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](https://consensyssoftware.atlassian.net/browse/TAT-2399)
## **Manual testing steps**
```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
```
## **Screenshots/Recordings**
### **Before**
Bug confirmed via CDP eval: `formatWithSignificantDigits(2.3418, 4)` →
`2.342` (3 decimals instead of 4)
### **After**
https://github.com/user-attachments/assets/72b3617e-afdf-49c1-bbbb-2b96e176668d
## **Validation Recipe**
<details>
<summary>Automated validation recipe (validate-recipe.sh)</summary>
```json
{
"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`
</details>
## **Pre-merge author checklist**
- [x] I've followed MetaMask Contributor Docs and Coding Standards
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [ ] I've documented my code using JSDoc format if applicable
- [x] 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.
<!-- CURSOR_SUMMARY -->
---
> [!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 `testID`s for each preset button (including dynamic % presets)
and extends `PerpsLimitPriceBottomSheet` tests to assert the correct
decimal precision for XRP-range prices.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ecb689b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 3e1b3d4 commit dee9a46
3 files changed
Lines changed: 81 additions & 5 deletions
File tree
- app/components/UI/Perps
- components/PerpsLimitPriceBottomSheet
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
554 | 558 | | |
555 | 559 | | |
556 | 560 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
531 | 594 | | |
532 | 595 | | |
533 | 596 | | |
| |||
Lines changed: 14 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
374 | 375 | | |
375 | 376 | | |
376 | 377 | | |
| 378 | + | |
377 | 379 | | |
378 | 380 | | |
379 | 381 | | |
380 | 382 | | |
381 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
382 | 387 | | |
383 | 388 | | |
384 | 389 | | |
| |||
394 | 399 | | |
395 | 400 | | |
396 | 401 | | |
| 402 | + | |
397 | 403 | | |
398 | 404 | | |
399 | 405 | | |
400 | 406 | | |
401 | 407 | | |
402 | 408 | | |
403 | 409 | | |
404 | | - | |
| 410 | + | |
405 | 411 | | |
406 | 412 | | |
407 | 413 | | |
| |||
417 | 423 | | |
418 | 424 | | |
419 | 425 | | |
| 426 | + | |
420 | 427 | | |
421 | 428 | | |
422 | 429 | | |
| |||
425 | 432 | | |
426 | 433 | | |
427 | 434 | | |
428 | | - | |
| 435 | + | |
429 | 436 | | |
430 | 437 | | |
431 | 438 | | |
| |||
446 | 453 | | |
447 | 454 | | |
448 | 455 | | |
| 456 | + | |
449 | 457 | | |
450 | 458 | | |
451 | 459 | | |
452 | 460 | | |
453 | 461 | | |
454 | 462 | | |
455 | 463 | | |
456 | | - | |
| 464 | + | |
457 | 465 | | |
458 | 466 | | |
459 | 467 | | |
| |||
469 | 477 | | |
470 | 478 | | |
471 | 479 | | |
| 480 | + | |
472 | 481 | | |
473 | 482 | | |
474 | 483 | | |
| |||
477 | 486 | | |
478 | 487 | | |
479 | 488 | | |
480 | | - | |
| 489 | + | |
481 | 490 | | |
482 | 491 | | |
483 | 492 | | |
| |||
0 commit comments