Commit 4f4f756
authored
fix(perps): limit price percentage buttons now compound on current price (#29373)
## **Description**
Pressing `-1%` or `-2%` in the "Set limit price" modal only changed the
displayed price on the first press. Subsequent presses had no effect.
Root cause: `calculatePriceForPercentage` always used the live market
price as the base. Every press returned the same calculated value, so
React skipped the state update entirely.
Fix: use the currently displayed `limitPrice` as the base for each
calculation, falling back to market price only when the field is empty.
Each press now compounds correctly ($78,181 → $77,399 → $76,625 → …).
Regression introduced in #24069 (TAT-2114).
## **Changelog**
CHANGELOG entry: Fixed a bug where the -1%/-2% limit price preset
buttons only applied on the first press.
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-3097
## **Manual testing steps**
\`\`\`gherkin
Feature: Limit price percentage presets
Scenario: User presses -1% multiple times
Given user is on the order form with direction set to Long
When user taps "Limit" order type and opens the limit price modal
And user taps the "-1%" button once
Then limit price decreases by 1% from market price
When user taps the "-1%" button again
Then limit price decreases by another 1% from the previous value
When user taps the "-1%" button a third time
Then limit price decreases by another 1% again (compounds correctly)
\`\`\`
## **Screenshots/Recordings**
### **Before**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/e3a9de99-a0ba-4f65-a0fb-f163021acef4
### **After**
[<!-- [screenshots/recordings] -->
](https://github.com/user-attachments/assets/4fb3e130-b802-477c-af0d-5e664dc93556)
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
#### Performance checks (if applicable)
- [x] I've tested on Android
- Ideally on a mid-range device; emulator is acceptable
- [x] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [x] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
## **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]
> **Low Risk**
> Small, localized change to UI price calculation logic with added test
coverage; minimal risk beyond preset price behavior.
>
> **Overview**
> Fixes the limit-price percentage preset calculation in
`PerpsLimitPriceBottomSheet` so `%` buttons compound off the *currently
entered* `limitPrice` (sanitized/parsed), falling back to `currentPrice`
only when no limit is set.
>
> Adds a regression test (TAT-3097) asserting the percentage calculation
uses `limitPrice` as the BigNumber base when it’s already populated,
preventing the “only first press works” bug from returning.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
699decd. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 8cdc767 commit 4f4f756
2 files changed
Lines changed: 38 additions & 6 deletions
File tree
- app/components/UI/Perps/components/PerpsLimitPriceBottomSheet
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
514 | 545 | | |
515 | 546 | | |
516 | 547 | | |
| |||
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
| 288 | + | |
288 | 289 | | |
289 | 290 | | |
290 | 291 | | |
| |||
293 | 294 | | |
294 | 295 | | |
295 | 296 | | |
296 | | - | |
297 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
298 | 301 | | |
299 | 302 | | |
300 | 303 | | |
| |||
304 | 307 | | |
305 | 308 | | |
306 | 309 | | |
307 | | - | |
308 | | - | |
309 | 310 | | |
310 | 311 | | |
311 | | - | |
| 312 | + | |
312 | 313 | | |
313 | 314 | | |
314 | 315 | | |
| |||
0 commit comments