fix(perps): correct amount reset when balance changes and simplify setAmount cp-7.65.0#25759
fix(perps): correct amount reset when balance changes and simplify setAmount cp-7.65.0#25759michalconsensys merged 2 commits intomainfrom
Conversation
…tAmount Co-authored-by: Cursor <cursoragent@cursor.com>
|
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. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: The hook is used by PerpsOrderContext which powers the PerpsOrderView for perpetuals trading. Per the tag descriptions:
The change is isolated to the Perps feature and doesn't affect other wallet functionality. Risk is medium because while the change is localized, it affects order form state management which is critical for trading operations. Performance Test Selection: |
|



Description
What is the reason for the change?
When the user changed the payment token or when the effective balance dropped, the Perps order form was resetting the amount to max whenever the current amount was greater than the new max. That logic could also run when the user had intentionally set the amount to 0 or left it empty (e.g. initial value 10), and
setAmountwas forcing empty values to'0', which made it harder to preserve the intended initial amount.What is the improvement/solution?
useEffectthat reacts tobalanceForMax/maxPossibleAmount/orderForm.amount: only reset the amount when it actually exceeds the new max. IfcurrentAmount === 0,maxPossibleAmount === 0, orcurrentAmount < maxPossibleAmount, we return early and do not overwrite the form amount.setAmount, pass through theamountstring as-is and remove the|| '0'fallback so the form can keep an empty or user-chosen initial value (e.g. 10) without being forced to'0'.Changelog
CHANGELOG entry: Fixed Perps order form so the amount is only reset when it exceeds the new max after changing payment token or balance, and no longer overwrites an initial or empty amount.
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
No visible change
After
No visible change
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Small, localized change to UI state synchronization logic; primary risk is subtle regressions in amount clamping behavior when balances update.
Overview
Adjusts the Perps order form auto-clamp logic so
orderForm.amountis only reset when it actually exceeds the newly computedmaxPossibleAmountafter balance/payment-token changes.This refactors the
useEffectto parse the current amount directly, early-return for zero/under-max cases, and then set the amount toMath.floor(maxPossibleAmount)only when clamping is required.Written by Cursor Bugbot for commit 9d6f45b. This will update automatically on new commits. Configure here.