Skip to content

Commit 66e5e4a

Browse files
authored
fix: remove usePopularNetworks hook and replace with const (MetaMask#23525)
## **Description** PR to remove the usePopularNetworks hook in favor of constant list for trending. ## **Changelog** CHANGELOG entry: Removes usePopularNetworks hook and replace it with constant. ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/jira/software/c/projects/ASSETS/boards/1567?assignee=61a5edc8b0b630006a140ec1&selectedIssue=ASSETS-1916 ## **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** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] 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). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] 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] > Replaces the dynamic popular networks hook with a static TRENDING_NETWORKS_LIST used across trending UI and hooks, removes the hook/tests, and adds SEI to network constants. > > - **Trending networks source**: > - Introduce static `TRENDING_NETWORKS_LIST` in `app/components/UI/Trending/utils/trendingNetworksList.ts` with predefined `ProcessedNetwork` entries (incl. Solana/Tron guards). > - Add `SEI` to `NetworkToCaipChainId` (`app/components/UI/NetworkMultiSelector/NetworkMultiSelector.constants.ts`). > - **Hook and component updates**: > - Replace `usePopularNetworks` with `TRENDING_NETWORKS_LIST` in: > - `useTrendingRequest.ts` > - `useSearchRequest.ts` > - `TrendingTokenNetworkBottomSheet.tsx` > - **Removals**: > - Delete `usePopularNetworks` hook and its tests. > - **Tests**: > - Update tests to mock `TRENDING_NETWORKS_LIST` and expectations in: > - `TrendingTokenNetworkBottomSheet.test.tsx` > - `TrendingTokenRowItem.test.tsx` > - `useTrendingRequest.test.ts` > - `useSearchRequest.test.ts` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 02a7160. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent b63b52f commit 66e5e4a

11 files changed

Lines changed: 196 additions & 577 deletions

File tree

app/components/UI/NetworkMultiSelector/NetworkMultiSelector.constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ export enum NetworkToCaipChainId {
3838
LOCALHOST = 'eip155:1337',
3939
ETHEREUM_SEPOLIA = 'eip155:11155111',
4040
LINEA_SEPOLIA = 'eip155:59141',
41+
SEI = 'eip155:1329',
4142
}

app/components/UI/Trending/components/TrendingTokenRowItem/TrendingTokenRowItem.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import renderWithProvider from '../../../../../util/test/renderWithProvider';
44
import TrendingTokenRowItem from './TrendingTokenRowItem';
55
import type { TrendingAsset } from '@metamask/assets-controllers';
66

7+
// Mock the trendingNetworksList module to avoid getNetworkImageSource errors
8+
jest.mock('../../utils/trendingNetworksList', () => ({
9+
TRENDING_NETWORKS_LIST: [],
10+
}));
11+
712
const mockNavigate = jest.fn();
813

914
jest.mock('@react-navigation/native', () => ({

app/components/UI/Trending/components/TrendingTokensBottomSheet/TrendingTokenNetworkBottomSheet.test.tsx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,33 @@ jest.mock('../../../../../util/networks', () => ({
1515
mockGetNetworkImageSource(params),
1616
}));
1717

18-
const mockNetworks: ProcessedNetwork[] = [
19-
{
20-
id: 'eip155:1',
21-
name: 'Ethereum Mainnet',
22-
caipChainId: 'eip155:1' as CaipChainId,
23-
imageSource: {
24-
uri: 'https://example.com/ethereum.png',
25-
} as ImageSourcePropType,
26-
isSelected: false,
27-
},
28-
{
29-
id: 'eip155:137',
30-
name: 'Polygon',
31-
caipChainId: 'eip155:137' as CaipChainId,
32-
imageSource: {
33-
uri: 'https://example.com/polygon.png',
34-
} as ImageSourcePropType,
35-
isSelected: false,
36-
},
37-
];
38-
39-
const mockUsePopularNetworks = jest.fn(() => mockNetworks);
18+
// Mock the TRENDING_NETWORKS_LIST constant
19+
jest.mock('../../utils/trendingNetworksList', () => {
20+
const mockNetworks: ProcessedNetwork[] = [
21+
{
22+
id: 'eip155:1',
23+
name: 'Ethereum Mainnet',
24+
caipChainId: 'eip155:1' as CaipChainId,
25+
imageSource: {
26+
uri: 'https://example.com/ethereum.png',
27+
} as ImageSourcePropType,
28+
isSelected: false,
29+
},
30+
{
31+
id: 'eip155:137',
32+
name: 'Polygon',
33+
caipChainId: 'eip155:137' as CaipChainId,
34+
imageSource: {
35+
uri: 'https://example.com/polygon.png',
36+
} as ImageSourcePropType,
37+
isSelected: false,
38+
},
39+
];
4040

41-
jest.mock('../../hooks/usePopularNetworks/usePopularNetworks', () => ({
42-
usePopularNetworks: () => mockUsePopularNetworks(),
43-
}));
41+
return {
42+
TRENDING_NETWORKS_LIST: mockNetworks,
43+
};
44+
});
4445

4546
let storedOnClose: (() => void) | undefined;
4647

@@ -209,7 +210,6 @@ describe('TrendingTokenNetworkBottomSheet', () => {
209210
storedOnClose = undefined;
210211
mockOnClose.mockClear();
211212
mockOnOpenBottomSheet.mockClear();
212-
mockUsePopularNetworks.mockReturnValue(mockNetworks);
213213
mockGetNetworkImageSource.mockImplementation(
214214
(params: { chainId: string }) => {
215215
if (params.chainId === 'eip155:1') {

app/components/UI/Trending/components/TrendingTokensBottomSheet/TrendingTokenNetworkBottomSheet.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Avatar, {
1919
import { strings } from '../../../../../../locales/i18n';
2020
import { ProcessedNetwork } from '../../../../hooks/useNetworksByNamespace/useNetworksByNamespace';
2121
import { CaipChainId } from '@metamask/utils';
22-
import { usePopularNetworks } from '../../hooks/usePopularNetworks/usePopularNetworks';
22+
import { TRENDING_NETWORKS_LIST } from '../../utils/trendingNetworksList';
2323

2424
export enum NetworkOption {
2525
AllNetworks = 'all',
@@ -51,7 +51,7 @@ const TrendingTokenNetworkBottomSheet: React.FC<
5151
}) => {
5252
const sheetRef = useRef<BottomSheetRef>(null);
5353
const { colors } = useTheme();
54-
const networks = usePopularNetworks();
54+
const networks = TRENDING_NETWORKS_LIST;
5555

5656
// Default to "All networks" if no selection
5757
const [selectedNetwork, setSelectedNetwork] = useState<

0 commit comments

Comments
 (0)