Skip to content

Commit

Permalink
fix: fix network filter on edit network (#29898)
Browse files Browse the repository at this point in the history
<!--
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**
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")

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![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**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->



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.
  • Loading branch information
salimtb authored Jan 24, 2025
1 parent bdcd207 commit 00e2bae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -442,6 +449,7 @@ describe('NetworkForm Component', () => {
replacementSelectedRpcEndpointIndex: undefined,
},
);
expect(setTokenNetworkFilter).toHaveBeenCalledTimes(1);
});
});
});
11 changes: 11 additions & 0 deletions ui/pages/settings/networks-tab/networks-form/networks-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { getNetworkConfigurationsByChainId } from '../../../../../shared/modules
import {
addNetwork,
setEditedNetwork,
setTokenNetworkFilter,
showDeprecatedNetworkModal,
toggleNetworkMenu,
updateNetwork,
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -113,6 +115,8 @@ export const NetworksForm = ({
const [suggestedTicker, setSuggestedTicker] = useState<string>();
const [fetchedChainId, setFetchedChainId] = useState<string>();

const tokenNetworkFilter = useSelector(getTokenNetworkFilter);

const templateInfuraRpc = (endpoint: string) =>
endpoint.endsWith('{infuraProjectId}')
? endpoint.replace('{infuraProjectId}', infuraProjectId ?? '')
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 00e2bae

Please sign in to comment.