From 00e2bae835ec13312879b521fa5f5760b615ac61 Mon Sep 17 00:00:00 2001 From: Salim TOUBAL Date: Fri, 24 Jan 2025 19:00:05 +0100 Subject: [PATCH] fix: fix network filter on edit network (#29898) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** After editing a popular network name, MetaMask switched to that network, but the token list is not updated, still showing the tokens from the previously selected network. (and the view is on "Popular Networks") [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29898?quickstart=1) ## **Related issues** Fixes: #29866 ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** https://github.com/user-attachments/assets/ed9a942f-f508-4197-a1a1-077e0e24274f ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/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. --- .../networks-tab/networks-form/networks-form.test.js | 10 +++++++++- .../networks-tab/networks-form/networks-form.tsx | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.test.js b/ui/pages/settings/networks-tab/networks-form/networks-form.test.js index 9840fe979c4b..522e48b43151 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.test.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.test.js @@ -12,13 +12,20 @@ import { } from '../../../../../shared/constants/network'; import * as fetchWithCacheModule from '../../../../../shared/lib/fetch-with-cache'; import { mockNetworkState } from '../../../../../test/stub/networks'; -import { addNetwork, updateNetwork } from '../../../../store/actions'; +import { + addNetwork, + setTokenNetworkFilter, + updateNetwork, +} from '../../../../store/actions'; import { NetworksForm } from './networks-form'; jest.mock('../../../../../ui/store/actions', () => ({ ...jest.requireActual('../../../../../ui/store/actions'), updateNetwork: jest.fn().mockReturnValue(jest.fn().mockResolvedValue()), addNetwork: jest.fn().mockReturnValue(jest.fn().mockResolvedValue()), + setTokenNetworkFilter: jest + .fn() + .mockReturnValue(jest.fn().mockResolvedValue()), })); const renderComponent = (props) => { @@ -442,6 +449,7 @@ describe('NetworkForm Component', () => { replacementSelectedRpcEndpointIndex: undefined, }, ); + expect(setTokenNetworkFilter).toHaveBeenCalledTimes(1); }); }); }); diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.tsx b/ui/pages/settings/networks-tab/networks-form/networks-form.tsx index db3a86ce0ed4..4d61c2e7c55a 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.tsx +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.tsx @@ -32,6 +32,7 @@ import { getNetworkConfigurationsByChainId } from '../../../../../shared/modules import { addNetwork, setEditedNetwork, + setTokenNetworkFilter, showDeprecatedNetworkModal, toggleNetworkMenu, updateNetwork, @@ -66,6 +67,7 @@ import { DropdownEditor, DropdownEditorStyle, } from '../../../../components/multichain/dropdown-editor/dropdown-editor'; +import { getTokenNetworkFilter } from '../../../../selectors'; import { useSafeChains, rpcIdentifierUtility } from './use-safe-chains'; import { useNetworkFormState } from './networks-form-state'; @@ -113,6 +115,8 @@ export const NetworksForm = ({ const [suggestedTicker, setSuggestedTicker] = useState(); const [fetchedChainId, setFetchedChainId] = useState(); + const tokenNetworkFilter = useSelector(getTokenNetworkFilter); + const templateInfuraRpc = (endpoint: string) => endpoint.endsWith('{infuraProjectId}') ? endpoint.replace('{infuraProjectId}', infuraProjectId ?? '') @@ -267,6 +271,13 @@ export const NetworksForm = ({ : undefined, }; await dispatch(updateNetwork(networkPayload, options)); + if (Object.keys(tokenNetworkFilter).length === 1) { + await dispatch( + setTokenNetworkFilter({ + [existingNetwork.chainId]: true, + }), + ); + } } else { await dispatch(addNetwork(networkPayload)); }