Skip to content

Commit a975b43

Browse files
gambinishabretonc7scortisikotommasinimetamaskbot
authored
fix: Navigation behavior from PerpsHomeScreenSearch (#22013)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Fixes incorrect search behavior from PerpsHomeView. We were handling two different search behaviors in PerpsHomeScree and PerpsMarketListView. Correct behavior is: 1. When search icon is pressed on the PerpsHomeView, it need to navigate to the PerpsMarketListView with search enabled. 2. On cancel, it should go back to the PerpsMarketListView 3. When search icon is pressed from PerpsMarketListView, we enable search as is currently does 4. When cancel is pressed it goes back to PerpsMarketListView This PR removes the multi-dimensional search from the PerpsHomeScreen view and instead navigates to the MarketListView as per the latest designs. ## **Changelog** CHANGELOG entry: Fixes search behavior in PerpsHomeScreen ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** https://github.com/user-attachments/assets/f747b86f-4080-44ab-9cdd-7a96add3b510 ## **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] > PerpsHomeView now navigates to PerpsMarketListView with search pre-opened on search tap, with minor header padding tweak, a new navigation param, and updated tests. > > - **Perps Home → Market List navigation** > - Replace in-place search in `PerpsHomeView` with navigation to `PerpsMarketListView` via `usePerpsNavigation.navigateToMarketList({ defaultSearchVisible: true, source: 'homescreen_tab', fromHome: true })`. > - Remove local search state and filtering from `PerpsHomeView`; call `usePerpsHomeData({})`. > - Header in `PerpsHomeHeader` is always rendered with `isSearchVisible: false` on Home. > - **Market List search handling** > - Refactor `handleSearchToggle` in `PerpsMarketListView` to `useCallback`; clears query on close and tracks event on open. > - **Header UI tweak** > - `PerpsMarketListHeader`: add `Platform`-specific padding for the search bar (`py-3` iOS, `py-1` Android); import `Platform`. Mark `onSearchClear` as unused. > - **Navigation types** > - Add `fromHome?: boolean` to `PerpsNavigationParamList['PerpsMarketListView']`. > - **Tests** > - `PerpsHomeView.test.tsx`: mock `navigateToMarketList` and assert navigation with `{ defaultSearchVisible: true, source: 'homescreen_tab', fromHome: true }`; remove assertions about HomeView search bar visibility; minor setup/mocks cleanup. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8218306. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Arthur Breton <arthur.breton@consensys.net> Co-authored-by: abretonc7s <107169956+abretonc7s@users.noreply.github.com> Co-authored-by: Curtis David <Curtis.David7@gmail.com> Co-authored-by: tommasini <46944231+tommasini@users.noreply.github.com> Co-authored-by: metamaskbot <metamaskbot@users.noreply.github.com> Co-authored-by: Borislav Grigorov <b.s.grigorov@gmail.com> Co-authored-by: Nicholas Smith <nick.smith@consensys.net>
1 parent 9f14e3e commit a975b43

File tree

5 files changed

+31
-41
lines changed

5 files changed

+31
-41
lines changed

app/components/UI/Perps/Views/PerpsHomeView/PerpsHomeView.test.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ jest.mock(
4141

4242
// Mock hooks (consolidated to avoid conflicts)
4343
const mockNavigateBack = jest.fn();
44+
const mockNavigateToMarketList = jest.fn();
4445
jest.mock('../../hooks', () => ({
4546
usePerpsHomeData: jest.fn(),
4647
usePerpsMeasurement: jest.fn(),
4748
usePerpsNavigation: jest.fn(() => ({
4849
navigateTo: jest.fn(),
4950
navigateToMarketDetails: jest.fn(),
50-
navigateToMarketList: jest.fn(),
51+
navigateToMarketList: mockNavigateToMarketList,
5152
navigateBack: mockNavigateBack,
5253
goBack: jest.fn(),
5354
})),
@@ -391,6 +392,7 @@ describe('PerpsHomeView', () => {
391392
beforeEach(() => {
392393
jest.clearAllMocks();
393394
mockNavigateBack.mockClear();
395+
mockNavigateToMarketList.mockClear();
394396
mockUsePerpsHomeData.mockReturnValue(mockDefaultData);
395397
});
396398

@@ -420,32 +422,23 @@ describe('PerpsHomeView', () => {
420422
expect(getByTestId('perps-home-search-toggle')).toBeTruthy();
421423
});
422424

423-
it('toggles search bar visibility when search button is pressed', () => {
425+
it('navigates to market list view with search enabled when search button is pressed', () => {
424426
// Arrange
425427
const { getByTestId, queryByTestId } = render(<PerpsHomeView />);
426428

427-
// Act - Initially search should not be visible
429+
// Assert - Search bar should not be visible initially
428430
expect(queryByTestId('perps-home-search-bar')).toBeNull();
429431

430-
// Press search toggle
432+
// Act - Press search toggle
431433
fireEvent.press(getByTestId('perps-home-search-toggle'));
432434

433-
// Assert - Search should now be visible
434-
expect(getByTestId('perps-home-search-bar')).toBeTruthy();
435-
});
436-
437-
it('hides search bar when toggle is pressed again', () => {
438-
// Arrange
439-
const { getByTestId, queryByTestId } = render(<PerpsHomeView />);
440-
441-
// Act - Open search
442-
fireEvent.press(getByTestId('perps-home-search-toggle'));
443-
expect(getByTestId('perps-home-search-bar')).toBeTruthy();
444-
445-
// Close search - when search is visible, the toggle becomes cancel button
446-
fireEvent.press(getByTestId('perps-home-search-close'));
447-
448-
// Assert - Search should be hidden
435+
// Assert - Should navigate to MarketListView with search enabled
436+
expect(mockNavigateToMarketList).toHaveBeenCalledWith({
437+
defaultSearchVisible: true,
438+
source: 'homescreen_tab',
439+
fromHome: true,
440+
});
441+
// Search bar should still not be visible in HomeView (navigation happens, component doesn't toggle search)
449442
expect(queryByTestId('perps-home-search-bar')).toBeNull();
450443
});
451444

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,13 @@ const PerpsHomeView = () => {
5757
// Use centralized navigation hook
5858
const perpsNavigation = usePerpsNavigation();
5959

60-
// Search state
61-
const [searchQuery, setSearchQuery] = useState('');
62-
const [isSearchVisible, setIsSearchVisible] = useState(false);
63-
6460
// Bottom sheet state and refs
6561
const [showCloseAllSheet, setShowCloseAllSheet] = useState(false);
6662
const [showCancelAllSheet, setShowCancelAllSheet] = useState(false);
6763
const closeAllSheetRef = useRef<BottomSheetRef>(null);
6864
const cancelAllSheetRef = useRef<BottomSheetRef>(null);
6965

70-
// Fetch all home screen data with search filtering
66+
// Fetch all home screen data
7167
const {
7268
positions,
7369
orders,
@@ -78,9 +74,7 @@ const PerpsHomeView = () => {
7874
recentActivity,
7975
sortBy,
8076
isLoading,
81-
} = usePerpsHomeData({
82-
searchQuery: isSearchVisible ? searchQuery : '',
83-
});
77+
} = usePerpsHomeData({});
8478

8579
// Determine if any data is loading for initial load tracking
8680
// Orders and activity load via WebSocket instantly, only track positions and markets
@@ -105,12 +99,13 @@ const PerpsHomeView = () => {
10599
});
106100

107101
const handleSearchToggle = useCallback(() => {
108-
setIsSearchVisible(!isSearchVisible);
109-
if (isSearchVisible) {
110-
// Clear search when hiding search bar
111-
setSearchQuery('');
112-
}
113-
}, [isSearchVisible]);
102+
// Navigate to MarketListView with search enabled
103+
perpsNavigation.navigateToMarketList({
104+
defaultSearchVisible: true,
105+
source: PerpsEventValues.SOURCE.HOMESCREEN_TAB,
106+
fromHome: true,
107+
});
108+
}, [perpsNavigation]);
114109

115110
const navigtateToTutorial = useCallback(() => {
116111
navigation.navigate(Routes.PERPS.TUTORIAL, {
@@ -186,10 +181,7 @@ const PerpsHomeView = () => {
186181
<SafeAreaView style={styles.container}>
187182
{/* Header - Using extracted component */}
188183
<PerpsHomeHeader
189-
isSearchVisible={isSearchVisible}
190-
searchQuery={searchQuery}
191-
onSearchQueryChange={setSearchQuery}
192-
onSearchClear={() => setSearchQuery('')}
184+
isSearchVisible={false}
193185
onBack={handleBackPress}
194186
onSearchToggle={handleSearchToggle}
195187
testID="perps-home"

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,21 @@ const PerpsMarketListView = ({
345345
// Use navigation hook for back button
346346
const handleBackPressed = perpsNavigation.navigateBack;
347347

348-
const handleSearchToggle = () => {
348+
const handleSearchToggle = useCallback(() => {
349+
// Toggle search visibility
349350
toggleSearchVisibility();
350351

351352
if (isSearchVisible) {
353+
// When disabling search, clear the query
352354
clearSearch();
353355
} else {
356+
// When enabling search, track the event
354357
track(MetaMetricsEvents.PERPS_UI_INTERACTION, {
355358
[PerpsEventProperties.INTERACTION_TYPE]:
356359
PerpsEventValues.INTERACTION_TYPE.SEARCH_CLICKED,
357360
});
358361
}
359-
};
362+
}, [isSearchVisible, toggleSearchVisibility, clearSearch, track]);
360363

361364
// Performance tracking: Measure screen load time until market data is displayed
362365
usePerpsMeasurement({

app/components/UI/Perps/components/PerpsMarketListHeader/PerpsMarketListHeader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Pressable,
66
Keyboard,
77
TextInput,
8+
Platform,
89
} from 'react-native';
910
import { useNavigation } from '@react-navigation/native';
1011
import { useStyles } from '../../../../../component-library/hooks';
@@ -96,7 +97,7 @@ const PerpsMarketListHeader: React.FC<PerpsMarketListHeaderProps> = ({
9697
flexDirection={BoxFlexDirection.Row}
9798
alignItems={BoxAlignItems.Center}
9899
style={styles.searchBarContainer}
99-
twClassName="flex-1 bg-muted rounded-lg px-3 py-1 mr-2"
100+
twClassName={`flex-1 bg-muted rounded-lg ${Platform.OS === 'ios' ? 'py-3' : 'py-1'} px-3 mr-2`}
100101
>
101102
<Icon
102103
name={IconName.Search}

app/components/UI/Perps/types/navigation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface PerpsNavigationParamList extends ParamListBase {
8282
| 'forex'
8383
| 'all'
8484
| 'stocks_and_commodities';
85+
fromHome?: boolean;
8586
};
8687

8788
PerpsMarketDetails: {

0 commit comments

Comments
 (0)