Skip to content

Commit 8166eae

Browse files
fix(perps): use existing position leverage as fallback for initial leverage (MetaMask#23619)
## **Description** This PR fixes an issue where the `PerpsOrderProvider` would not properly initialize leverage when modifying an existing position. Previously, if `initialLeverage` was not explicitly provided via navigation params, the form would not fall back to the existing position's leverage value, which could lead to incorrect leverage initialization when modifying positions. ## **Changelog** CHANGELOG entry: Fixed leverage initialization when modifying existing perpetual positions ## **Related issues** Fixes: Jira Task: https://consensyssoftware.atlassian.net/browse/TAT-2201 ## **Manual testing steps** ```gherkin Feature: Perps order form leverage initialization Scenario: user modifies existing position with leverage Given user has an existing perpetual position with 5x leverage And user navigates to modify the position Then the order form should display 5x leverage as the initial value even when the internet connection is lost ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** No visible change ### **After** No visible change ## **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. ## **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] > Fallback to `existingPosition.leverage.value` when `initialLeverage` is undefined in `PerpsOrderProvider` initialization. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 49f8fee. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5988b41 commit 8166eae

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

app/components/UI/Perps/contexts/PerpsOrderContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const PerpsOrderProvider = ({
3434
initialAsset,
3535
initialDirection,
3636
initialAmount,
37-
initialLeverage,
37+
initialLeverage: initialLeverage ?? existingPosition?.leverage?.value,
3838
initialType,
3939
});
4040

0 commit comments

Comments
 (0)