1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Direct users to testnet toggle on dapp requests (#20048)

* auto switch test network when dapp requests

* fixed memory leakage issue
This commit is contained in:
Nidhi Kumari 2023-07-17 22:12:58 +05:30 committed by GitHub
parent bdbaa03aca
commit ce771bee66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import React, { useContext, useEffect } from 'react';
import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
@ -73,6 +73,12 @@ export const NetworkListMenu = ({ onClose }) => {
const lineaMainnetReleased = useSelector(isLineaMainnetNetworkReleased);
useEffect(() => {
if (currentlyOnTestNetwork) {
dispatch(setShowTestNetworks(currentlyOnTestNetwork));
}
}, [dispatch, currentlyOnTestNetwork]);
const generateMenuItems = (desiredNetworks) => {
return desiredNetworks.map((network, index) => {
if (!lineaMainnetReleased && network.providerType === 'linea-mainnet') {
@ -126,6 +132,17 @@ export const NetworkListMenu = ({ onClose }) => {
});
};
const handleToggle = (value) => {
const shouldShowTestNetworks = !value;
dispatch(setShowTestNetworks(shouldShowTestNetworks));
if (shouldShowTestNetworks) {
trackEvent({
event: MetaMetricsEventName.TestNetworksDisplayed,
category: MetaMetricsEventCategory.Network,
});
}
};
return (
<Modal isOpen onClose={onClose}>
<ModalOverlay />
@ -154,16 +171,7 @@ export const NetworkListMenu = ({ onClose }) => {
<ToggleButton
value={showTestNetworks}
disabled={currentlyOnTestNetwork}
onToggle={(value) => {
const shouldShowTestNetworks = !value;
dispatch(setShowTestNetworks(shouldShowTestNetworks));
if (shouldShowTestNetworks) {
trackEvent({
event: MetaMetricsEventName.TestNetworksDisplayed,
category: MetaMetricsEventCategory.Network,
});
}
}}
onToggle={handleToggle}
/>
</Box>
{showTestNetworks || currentlyOnTestNetwork ? (