Skip to content

Commit

Permalink
fix (cherry-pick): UX: NetworkList: Ensure setNetworkClientIdForDomai…
Browse files Browse the repository at this point in the history
…n is called for test networks (#25184) (#25260)

## **Description**

Cuts down the duplication of the NetworkListItem and ensures that
`setNetworkClientIdForDomain` is called for test networks so that
manually choosing a test network sends a signal to the dapp to change
chain.

PR: #25195
Commit Hash:
[c67aa3f](c67aa3f)

There were no merge conflicts when picking these commits.

<!--
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/25070?quickstart=1)

## **Related issues**

Fixes: The current Profile Syncing Feature doesn't fully respect Basic
Functionality when turned off. This ensures that the notifications
feature and profile syncing are actually turned off when Basic
Functionality if off.

## **Manual testing steps**

1. Go to a given dapp, connect using Ethereum Mainnet
2. Manually open MetaMask, click the network picker, choose Sepolia
3. See dapp change to sepolia

## **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**

- [x] I’ve followed [MetaMask Coding

Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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-extension/blob/develop/.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.


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

<!--
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?
4. What is the improvement/solution?
-->

[![Open in GitHub

Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25184?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
5.

## **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**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding

Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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
- [ ] 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/develop/.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.<!--
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**

<!--
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/25260?quickstart=1)

## **Related issues**

Fixes:

## **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] -->

## **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/develop/.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/develop/.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.

Co-authored-by: Brian Bergeron <brian.e.bergeron@gmail.com>
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
  • Loading branch information
3 people authored Jun 14, 2024
1 parent c788598 commit aba68fd
Showing 1 changed file with 68 additions and 95 deletions.
163 changes: 68 additions & 95 deletions ui/components/multichain/network-list-menu/network-list-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,62 @@ export const NetworkListMenu = ({ onClose }) => {
);
}

const generateNetworkListItem = ({
network,
isCurrentNetwork,
canDeleteNetwork,
}) => {
return (
<NetworkListItem
name={network.nickname}
iconSrc={network?.rpcPrefs?.imageUrl}
key={network.id}
selected={isCurrentNetwork}
focus={isCurrentNetwork && !showSearch}
onClick={() => {
dispatch(toggleNetworkMenu());
if (network.providerType) {
dispatch(setProviderType(network.providerType));
} else {
dispatch(setActiveNetwork(network.id));
}

// If presently on a dapp, communicate a change to
// the dapp via silent switchEthereumChain that the
// network has changed due to user action
if (useRequestQueue && selectedTabOrigin) {
setNetworkClientIdForDomain(selectedTabOrigin, network.id);
}

trackEvent({
event: MetaMetricsEventName.NavNetworkSwitched,
category: MetaMetricsEventCategory.Network,
properties: {
location: 'Network Menu',
chain_id: currentChainId,
from_network: currentChainId,
to_network: network.chainId,
},
});
}}
onDeleteClick={
canDeleteNetwork
? () => {
dispatch(toggleNetworkMenu());
dispatch(
showModal({
name: 'CONFIRM_DELETE_NETWORK',
target: network.id,
onConfirm: () => undefined,
}),
);
}
: null
}
/>
);
};

const generateMenuItems = (desiredNetworks) => {
return desiredNetworks.map((network) => {
const isCurrentNetwork =
Expand All @@ -182,47 +238,11 @@ export const NetworkListMenu = ({ onClose }) => {
const canDeleteNetwork =
isUnlocked && !isCurrentNetwork && network.removable;

return (
<NetworkListItem
name={network.nickname}
iconSrc={network?.rpcPrefs?.imageUrl}
key={network.id}
selected={isCurrentNetwork}
focus={isCurrentNetwork && !showSearch}
onClick={() => {
dispatch(toggleNetworkMenu());
if (network.providerType) {
dispatch(setProviderType(network.providerType));
} else {
dispatch(setActiveNetwork(network.id));
}
trackEvent({
event: MetaMetricsEventName.NavNetworkSwitched,
category: MetaMetricsEventCategory.Network,
properties: {
location: 'Network Menu',
chain_id: currentChainId,
from_network: currentChainId,
to_network: network.chainId,
},
});
}}
onDeleteClick={
canDeleteNetwork
? () => {
dispatch(toggleNetworkMenu());
dispatch(
showModal({
name: 'CONFIRM_DELETE_NETWORK',
target: network.id,
onConfirm: () => undefined,
}),
);
}
: null
}
/>
);
return generateNetworkListItem({
network,
isCurrentNetwork,
canDeleteNetwork,
});
});
};

Expand Down Expand Up @@ -328,6 +348,12 @@ export const NetworkListMenu = ({ onClose }) => {
const canDeleteNetwork =
isUnlocked && !isCurrentNetwork && network.removable;

const networkListItem = generateNetworkListItem({
network,
isCurrentNetwork,
canDeleteNetwork,
});

return (
<Draggable
key={network.id}
Expand All @@ -340,60 +366,7 @@ export const NetworkListMenu = ({ onClose }) => {
{...providedDrag.draggableProps}
{...providedDrag.dragHandleProps}
>
<NetworkListItem
name={network.nickname}
iconSrc={network?.rpcPrefs?.imageUrl}
key={network.id}
selected={isCurrentNetwork}
focus={isCurrentNetwork && !showSearch}
onClick={() => {
dispatch(toggleNetworkMenu());
if (network.providerType) {
dispatch(
setProviderType(network.providerType),
);
} else {
dispatch(setActiveNetwork(network.id));
}

// If presently on a dapp, communicate a change to
// the dapp via silent switchEthereumChain that the
// network has changed due to user action
if (useRequestQueue && selectedTabOrigin) {
setNetworkClientIdForDomain(
selectedTabOrigin,
network.id,
);
}

trackEvent({
event:
MetaMetricsEventName.NavNetworkSwitched,
category:
MetaMetricsEventCategory.Network,
properties: {
location: 'Network Menu',
chain_id: currentChainId,
from_network: currentChainId,
to_network: network.chainId,
},
});
}}
onDeleteClick={
canDeleteNetwork
? () => {
dispatch(toggleNetworkMenu());
dispatch(
showModal({
name: 'CONFIRM_DELETE_NETWORK',
target: network.id,
onConfirm: () => undefined,
}),
);
}
: null
}
/>
{networkListItem}
</Box>
)}
</Draggable>
Expand Down

0 comments on commit aba68fd

Please sign in to comment.