mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +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:
parent
bdbaa03aca
commit
ce771bee66
@ -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 ? (
|
||||
|
Loading…
Reference in New Issue
Block a user