1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Fix #20274 - Update locked network menu controls (#20277)

This commit is contained in:
David Walsh 2023-08-03 09:20:03 -05:00 committed by GitHub
parent 5a9addc532
commit 72cc669ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -74,6 +74,8 @@ export const NetworkListMenu = ({ onClose }) => {
const lineaMainnetReleased = useSelector(isLineaMainnetNetworkReleased);
const isUnlocked = useSelector((state) => state.metamask.isUnlocked);
const showSearch = nonTestNetworks.length > 3;
useEffect(() => {
@ -111,7 +113,9 @@ export const NetworkListMenu = ({ onClose }) => {
}
const isCurrentNetwork = currentNetwork.id === network.id;
const canDeleteNetwork = !isCurrentNetwork && network.removable;
const canDeleteNetwork =
isUnlocked && !isCurrentNetwork && network.removable;
return (
<NetworkListItem
@ -227,7 +231,7 @@ export const NetworkListMenu = ({ onClose }) => {
<Text>{t('showTestnetNetworks')}</Text>
<ToggleButton
value={showTestNetworks}
disabled={currentlyOnTestNetwork}
disabled={currentlyOnTestNetwork || !isUnlocked}
onToggle={handleToggle}
/>
</Box>
@ -239,6 +243,7 @@ export const NetworkListMenu = ({ onClose }) => {
<Box padding={4}>
<ButtonSecondary
size={BUTTON_SECONDARY_SIZES.LG}
disabled={!isUnlocked}
block
onClick={() => {
if (isFullScreen) {

View File

@ -23,10 +23,12 @@ const render = (
showTestNetworks = false,
currentChainId = '0x5',
providerConfigId = 'chain5',
isUnlocked = true,
) => {
const state = {
metamask: {
...mockState.metamask,
isUnlocked,
providerConfig: {
...mockState.metamask.providerConfig,
chainId: currentChainId,
@ -111,4 +113,21 @@ describe('NetworkListMenu', () => {
expect(queryByText('Chain 5')).not.toBeInTheDocument();
});
it('disables the "Add Network" button when MetaMask is locked', () => {
const { queryByText } = render(false, '0x5', 'chain5', false);
expect(queryByText('Add network')).toBeDisabled();
});
it('enables the "Add Network" button when MetaMask is true', () => {
const { queryByText } = render(false, '0x5', 'chain5', true);
expect(queryByText('Add network')).toBeEnabled();
});
it('does not allow deleting networks when locked', () => {
render(false, '0x5', 'chain5', false);
expect(
document.querySelectorAll('multichain-network-list-item__delete'),
).toHaveLength(0);
});
});