Skip to content

Commit 587b966

Browse files
fix: Close all orders/positions bottom sheet dismissal (MetaMask#22216)
## **Description** Bug was reported where dismissing the close all positions/orders bottom sheet was dismissing the bottom sheet, but the overlay would persist. This made the PerpsHomeScreenView non-interactive and blocked users. This PR introduces a fix where we properly dismiss the bottom sheet both via close icon press, as well as externally by pressing the overlay outside of the sheet. ## **Changelog** CHANGELOG entry: Fix to close all positions/orders bottom sheet ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2021 ## **Manual testing steps** ```gherkin Feature: Close All and Cancel All bottom sheet overlay dismissal Scenario: user dismisses Close All bottom sheet by pressing overlay Given user is on PerpsHomeScreen with open positions And Close All bottom sheet is displayed with overlay When user presses outside the bottom sheet on the overlay Then the bottom sheet dismisses with animation And the overlay is removed And PerpsHomeScreen becomes interactive Scenario: user dismisses Close All bottom sheet by pressing Keep Positions Given user is on PerpsHomeScreen with open positions And Close All bottom sheet is displayed with overlay When user presses "Keep Positions" button Then the bottom sheet dismisses with animation And the overlay is removed And PerpsHomeScreen becomes interactive Scenario: user dismisses Cancel All bottom sheet by pressing overlay Given user is on PerpsHomeScreen with open orders And Cancel All bottom sheet is displayed with overlay When user presses outside the bottom sheet on the overlay Then the bottom sheet dismisses with animation And the overlay is removed And PerpsHomeScreen becomes interactive Scenario: user dismisses Cancel All bottom sheet by pressing Keep Orders Given user is on PerpsHomeScreen with open orders And Cancel All bottom sheet is displayed with overlay When user presses "Keep Orders" button Then the bottom sheet dismisses with animation And the overlay is removed And PerpsHomeScreen becomes interactive ``` ## **Screenshots/Recordings** https://github.com/user-attachments/assets/381fcd6c-acd7-4f71-aa29-a4fb2f27450d ## **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] > Properly closes the bottom sheet and removes the overlay when dismissed via overlay tap, close icon, or "Keep" buttons for Close All Positions and Cancel All Orders. > > - **Perps**: > - **`PerpsCancelAllOrdersView`**: > - Add `handleKeepButtonPress` to correctly close when used as overlay; wire to footer `keep_orders` button. > - Pass `onClose` to `BottomSheet` when `externalSheetRef` is provided; update all instances (empty/content states). > - **`PerpsCloseAllPositionsView`**: > - Add `handleKeepButtonPress` to correctly close when used as overlay; wire to footer `keep_positions` button. > - Pass `onClose` to `BottomSheet` when `externalSheetRef` is provided; update all instances (loading/empty/content states). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 232ec94. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: abretonc7s <107169956+abretonc7s@users.noreply.github.com>
1 parent 4e9972e commit 587b966

2 files changed

Lines changed: 51 additions & 9 deletions

File tree

app/components/UI/Perps/Views/PerpsCancelAllOrdersView/PerpsCancelAllOrdersView.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,22 @@ const PerpsCancelAllOrdersView: React.FC<PerpsCancelAllOrdersViewProps> = ({
177177
}
178178
}, [navigation, externalSheetRef, sheetRef, onExternalClose]);
179179

180+
// Wrapper for "Keep Orders" button that properly handles overlay dismissal
181+
const handleKeepButtonPress = useCallback(() => {
182+
if (externalSheetRef) {
183+
// When used as overlay, close the sheet properly to remove overlay
184+
handleClose();
185+
} else {
186+
// When used as standalone screen, use hook's navigation
187+
handleKeepOrders();
188+
}
189+
}, [externalSheetRef, handleClose, handleKeepOrders]);
190+
180191
const footerButtons = useMemo(
181192
() => [
182193
{
183194
label: strings('perps.cancel_all_modal.keep_orders'),
184-
onPress: handleKeepOrders,
195+
onPress: handleKeepButtonPress,
185196
variant: ButtonVariants.Secondary,
186197
size: ButtonSize.Lg,
187198
disabled: isCanceling,
@@ -197,13 +208,17 @@ const PerpsCancelAllOrdersView: React.FC<PerpsCancelAllOrdersViewProps> = ({
197208
danger: true,
198209
},
199210
],
200-
[handleKeepOrders, handleCancelAll, isCanceling],
211+
[handleKeepButtonPress, handleCancelAll, isCanceling],
201212
);
202213

203214
// Show empty state if no orders (WebSocket data loads instantly, no loading state needed)
204215
if (!orders || orders.length === 0) {
205216
return (
206-
<BottomSheet ref={sheetRef} shouldNavigateBack={!externalSheetRef}>
217+
<BottomSheet
218+
ref={sheetRef}
219+
shouldNavigateBack={!externalSheetRef}
220+
onClose={externalSheetRef ? onExternalClose : undefined}
221+
>
207222
<BottomSheetHeader onClose={handleClose}>
208223
<Text variant={TextVariant.HeadingMD}>
209224
{strings('perps.cancel_all_modal.title')}
@@ -219,7 +234,11 @@ const PerpsCancelAllOrdersView: React.FC<PerpsCancelAllOrdersViewProps> = ({
219234
}
220235

221236
return (
222-
<BottomSheet ref={sheetRef} shouldNavigateBack={!externalSheetRef}>
237+
<BottomSheet
238+
ref={sheetRef}
239+
shouldNavigateBack={!externalSheetRef}
240+
onClose={externalSheetRef ? onExternalClose : undefined}
241+
>
223242
<BottomSheetHeader onClose={handleClose}>
224243
<Text variant={TextVariant.HeadingMD}>
225244
{strings('perps.cancel_all_modal.title')}

app/components/UI/Perps/Views/PerpsCloseAllPositionsView/PerpsCloseAllPositionsView.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,22 @@ const PerpsCloseAllPositionsView: React.FC<PerpsCloseAllPositionsViewProps> = ({
204204
}
205205
}, [navigation, externalSheetRef, sheetRef, onExternalClose]);
206206

207+
// Wrapper for "Keep Positions" button that properly handles overlay dismissal
208+
const handleKeepButtonPress = useCallback(() => {
209+
if (externalSheetRef) {
210+
// When used as overlay, close the sheet properly to remove overlay
211+
handleClose();
212+
} else {
213+
// When used as standalone screen, use hook's navigation
214+
handleKeepPositions();
215+
}
216+
}, [externalSheetRef, handleClose, handleKeepPositions]);
217+
207218
const footerButtons = useMemo(
208219
() => [
209220
{
210221
label: strings('perps.close_all_modal.keep_positions'),
211-
onPress: handleKeepPositions,
222+
onPress: handleKeepButtonPress,
212223
variant: ButtonVariants.Secondary,
213224
size: ButtonSize.Lg,
214225
disabled: isClosing,
@@ -224,13 +235,17 @@ const PerpsCloseAllPositionsView: React.FC<PerpsCloseAllPositionsViewProps> = ({
224235
danger: true,
225236
},
226237
],
227-
[handleKeepPositions, handleCloseAll, isClosing],
238+
[handleKeepButtonPress, handleCloseAll, isClosing],
228239
);
229240

230241
// Show loading state while fetching positions
231242
if (isInitialLoading) {
232243
return (
233-
<BottomSheet ref={sheetRef} shouldNavigateBack={!externalSheetRef}>
244+
<BottomSheet
245+
ref={sheetRef}
246+
shouldNavigateBack={!externalSheetRef}
247+
onClose={externalSheetRef ? onExternalClose : undefined}
248+
>
234249
<BottomSheetHeader onClose={handleClose}>
235250
<Text variant={TextVariant.HeadingMD}>
236251
{strings('perps.close_all_modal.title')}
@@ -249,7 +264,11 @@ const PerpsCloseAllPositionsView: React.FC<PerpsCloseAllPositionsViewProps> = ({
249264
// Show empty state if no positions
250265
if (!positions || positions.length === 0) {
251266
return (
252-
<BottomSheet ref={sheetRef} shouldNavigateBack={!externalSheetRef}>
267+
<BottomSheet
268+
ref={sheetRef}
269+
shouldNavigateBack={!externalSheetRef}
270+
onClose={externalSheetRef ? onExternalClose : undefined}
271+
>
253272
<BottomSheetHeader onClose={handleClose}>
254273
<Text variant={TextVariant.HeadingMD}>
255274
{strings('perps.close_all_modal.title')}
@@ -265,7 +284,11 @@ const PerpsCloseAllPositionsView: React.FC<PerpsCloseAllPositionsViewProps> = ({
265284
}
266285

267286
return (
268-
<BottomSheet ref={sheetRef} shouldNavigateBack={!externalSheetRef}>
287+
<BottomSheet
288+
ref={sheetRef}
289+
shouldNavigateBack={!externalSheetRef}
290+
onClose={externalSheetRef ? onExternalClose : undefined}
291+
>
269292
<BottomSheetHeader onClose={handleClose}>
270293
<Text variant={TextVariant.HeadingMD}>
271294
{strings('perps.close_all_modal.title')}

0 commit comments

Comments
 (0)