diff --git a/test/e2e/api-specs/ConfirmationRejectionRule.ts b/test/e2e/api-specs/ConfirmationRejectionRule.ts index 3e37dcd07fd7..43046d8b0943 100644 --- a/test/e2e/api-specs/ConfirmationRejectionRule.ts +++ b/test/e2e/api-specs/ConfirmationRejectionRule.ts @@ -73,20 +73,6 @@ export class ConfirmationsRejectRule implements Rule { tag: 'button', }); - const editButtons = await this.driver.findElements( - '[data-testid="edit"]', - ); - await editButtons[1].click(); - - await this.driver.clickElement({ - text: 'Localhost 8545', - tag: 'p', - }); - - await this.driver.clickElement( - '[data-testid="connect-more-chains-button"]', - ); - const screenshotTwo = await this.driver.driver.takeScreenshot(); call.attachments.push({ type: 'image', diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index c857838f0810..6d2ccebeb7c7 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -783,16 +783,6 @@ const connectToDapp = async (driver) => { await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - const editButtons = await driver.findElements('[data-testid="edit"]'); - await editButtons[1].click(); - - await driver.clickElement({ - text: 'Localhost 8545', - tag: 'p', - }); - - await driver.clickElement('[data-testid="connect-more-chains-button"]'); - await driver.clickElementAndWaitForWindowToClose({ text: 'Connect', tag: 'button', diff --git a/test/e2e/json-rpc/switchEthereumChain.spec.js b/test/e2e/json-rpc/switchEthereumChain.spec.js index fba06db48131..eb191e894317 100644 --- a/test/e2e/json-rpc/switchEthereumChain.spec.js +++ b/test/e2e/json-rpc/switchEthereumChain.spec.js @@ -158,7 +158,52 @@ describe('Switch Ethereum Chain for two dapps', function () { }); await driver.switchToWindowWithUrl(DAPP_ONE_URL); + // Switch to Dapp One and connect it + await driver.switchToWindowWithUrl(DAPP_URL); + await driver.clickElement({ text: 'Connect', tag: 'button' }); + + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + + await driver.clickElementAndWaitForWindowToClose({ + text: 'Connect', + tag: 'button', + }); + + // Switch to MM and disconnect localhost 8545 for Dapp One + await driver.switchToWindowWithTitle( + WINDOW_TITLES.ExtensionInFullScreenView, + ); + await driver.clickElement( + '[data-testid ="account-options-menu-button"]', + ); + await driver.clickElement({ + text: 'All Permissions', + tag: 'div', + }); + await driver.clickElementAndWaitToDisappear({ + text: 'Got it', + tag: 'button', + }); + await driver.clickElement({ + text: '127.0.0.1:8080', + tag: 'p', + }); + const editButtons = await driver.findElements('[data-testid="edit"]'); + + assert.ok(editButtons.length > 0, 'Edit buttons are available'); + + await editButtons[1].click(); + + // Disconnect Mainnet + await driver.clickElement({ + text: 'Localhost 8546', + tag: 'p', + }); + + await driver.clickElement('[data-testid="connect-more-chains-button"]'); + // Switch to Dapp Two + await driver.switchToWindowWithUrl(DAPP_ONE_URL); // Initiate send transaction on Dapp two await driver.clickElement('#sendButton'); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); @@ -174,15 +219,13 @@ describe('Switch Ethereum Chain for two dapps', function () { const switchEthereumChainRequest = JSON.stringify({ jsonrpc: '2.0', method: 'wallet_switchEthereumChain', - params: [{ chainId: '0x539' }], + params: [{ chainId: '0x53a' }], }); // Initiate switchEthereumChain on Dapp One await driver.executeScript( `window.ethereum.request(${switchEthereumChainRequest})`, ); - - // Switch to tx and confirm send tx. await switchToNotificationWindow(driver, 4); await driver.findClickableElements({ text: 'Confirm', @@ -192,7 +235,6 @@ describe('Switch Ethereum Chain for two dapps', function () { text: 'Confirm', tag: 'button', }); - // Delay here after notification for second notification popup for switchEthereumChain await driver.delay(1000); @@ -203,7 +245,13 @@ describe('Switch Ethereum Chain for two dapps', function () { text: 'Confirm', tag: 'button', }); - await driver.clickElement({ text: 'Confirm', tag: 'button' }); + await driver.clickElementAndWaitForWindowToClose({ + text: 'Confirm', + tag: 'button', + }); + await driver.delay(1000); + await driver.switchToWindowWithUrl(DAPP_URL); + await driver.findElement({ css: '#chainId', text: '0x53a' }); }, ); }); @@ -278,7 +326,36 @@ describe('Switch Ethereum Chain for two dapps', function () { text: 'Connect', tag: 'button', }); + await driver.switchToWindowWithTitle( + WINDOW_TITLES.ExtensionInFullScreenView, + ); + await driver.clickElement( + '[data-testid ="account-options-menu-button"]', + ); + await driver.clickElement({ text: 'All Permissions', tag: 'div' }); + await driver.clickElementAndWaitToDisappear({ + text: 'Got it', + tag: 'button', + }); + await driver.clickElement({ + text: '127.0.0.1:8081', + tag: 'p', + }); + const editButtons = await driver.findElements('[data-testid="edit"]'); + // Ensure there are edit buttons + assert.ok(editButtons.length > 0, 'Edit buttons are available'); + + // Click the first (0th) edit button + await editButtons[1].click(); + + // Disconnect Mainnet + await driver.clickElement({ + text: 'Localhost 8545', + tag: 'p', + }); + + await driver.clickElement('[data-testid="connect-more-chains-button"]'); await driver.switchToWindow(dappTwo); assert.equal(await driver.getCurrentUrl(), `${DAPP_ONE_URL}/`); @@ -293,14 +370,11 @@ describe('Switch Ethereum Chain for two dapps', function () { await driver.executeScript( `window.ethereum.request(${switchEthereumChainRequest})`, ); - - // Switch to notification of switchEthereumChain await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await driver.findClickableElements({ text: 'Confirm', tag: 'button', }); - // Switch back to dapp one await driver.switchToWindow(dappOne); assert.equal(await driver.getCurrentUrl(), `${DAPP_URL}/`); @@ -401,7 +475,36 @@ describe('Switch Ethereum Chain for two dapps', function () { text: 'Connect', tag: 'button', }); + await driver.switchToWindowWithTitle( + WINDOW_TITLES.ExtensionInFullScreenView, + ); + await driver.clickElement( + '[data-testid ="account-options-menu-button"]', + ); + await driver.clickElement({ text: 'All Permissions', tag: 'div' }); + await driver.clickElementAndWaitToDisappear({ + text: 'Got it', + tag: 'button', + }); + await driver.clickElement({ + text: '127.0.0.1:8081', + tag: 'p', + }); + const editButtons = await driver.findElements('[data-testid="edit"]'); + + // Ensure there are edit buttons + assert.ok(editButtons.length > 0, 'Edit buttons are available'); + + // Click the first (0th) edit button + await editButtons[1].click(); + + // Disconnect Mainnet + await driver.clickElement({ + text: 'Localhost 8545', + tag: 'p', + }); + await driver.clickElement('[data-testid="connect-more-chains-button"]'); await driver.switchToWindow(dappTwo); assert.equal(await driver.getCurrentUrl(), `${DAPP_ONE_URL}/`); diff --git a/test/e2e/page-objects/pages/test-dapp.ts b/test/e2e/page-objects/pages/test-dapp.ts index 4a02d80459e0..b9487ee599b9 100644 --- a/test/e2e/page-objects/pages/test-dapp.ts +++ b/test/e2e/page-objects/pages/test-dapp.ts @@ -209,15 +209,6 @@ class TestDapp { await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await this.driver.waitForSelector(this.connectMetaMaskMessage); - // TODO: Extra steps needed to preserve the current network. - // Following steps can be removed once the issue is fixed (#27891) - const editNetworkButton = await this.driver.findClickableElements( - this.editConnectButton, - ); - await editNetworkButton[1].click(); - await this.driver.clickElement(this.localhostCheckbox); - await this.driver.clickElement(this.updateNetworkButton); - await this.driver.clickElementAndWaitForWindowToClose( this.confirmDialogButton, ); diff --git a/test/e2e/snaps/test-snap-txinsights-v2.spec.js b/test/e2e/snaps/test-snap-txinsights-v2.spec.js index 5fb56687de96..830629d1c43e 100644 --- a/test/e2e/snaps/test-snap-txinsights-v2.spec.js +++ b/test/e2e/snaps/test-snap-txinsights-v2.spec.js @@ -127,6 +127,11 @@ describe('Test Snap TxInsights-v2', function () { tag: 'button', text: 'Activity', }); + // wait for transaction confirmation + await driver.waitForSelector({ + css: '.transaction-status-label', + text: 'Confirmed', + }); }, ); }); diff --git a/test/e2e/tests/connections/edit-networks-flow.spec.js b/test/e2e/tests/connections/edit-networks-flow.spec.js index e14e1ae325d5..1db224f0ac0a 100644 --- a/test/e2e/tests/connections/edit-networks-flow.spec.js +++ b/test/e2e/tests/connections/edit-networks-flow.spec.js @@ -9,11 +9,6 @@ const { } = require('../../helpers'); const FixtureBuilder = require('../../fixture-builder'); -async function switchToNetworkByName(driver, networkName) { - await driver.clickElement('.mm-picker-network'); - await driver.clickElement(`[data-testid="${networkName}"]`); -} - describe('Edit Networks Flow', function () { it('should be able to edit networks', async function () { await withFixtures( @@ -43,9 +38,6 @@ describe('Edit Networks Flow', function () { await driver.clickElement( '.mm-modal-content__dialog button[aria-label="Close"]', ); - - // Switch to first network, whose send transaction was just confirmed - await switchToNetworkByName(driver, 'Localhost 8545'); await locateAccountBalanceDOM(driver); await driver.clickElement( '[data-testid ="account-options-menu-button"]', diff --git a/test/e2e/tests/request-queuing/dapp1-switch-dapp2-send.spec.js b/test/e2e/tests/request-queuing/dapp1-switch-dapp2-send.spec.js index c330596c48f3..3fdfe73e1b7a 100644 --- a/test/e2e/tests/request-queuing/dapp1-switch-dapp2-send.spec.js +++ b/test/e2e/tests/request-queuing/dapp1-switch-dapp2-send.spec.js @@ -98,12 +98,6 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () { `window.ethereum.request(${switchEthereumChainRequest})`, ); - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.findElement({ - text: 'Use your enabled networks', - tag: 'p', - }); - await driver.switchToWindowWithUrl(DAPP_ONE_URL); await driver.clickElement('#sendButton'); @@ -119,19 +113,6 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () { // so we leave this delay until the issue is fixed (#27360) await driver.delay(5000); - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - - // Check correct network on the send confirmation. - await driver.findElement({ - css: '[data-testid="network-display"]', - text: 'Localhost 8546', - }); - - await driver.clickElementAndWaitForWindowToClose({ - text: 'Confirm', - tag: 'button', - }); - // Switch back to the extension await driver.switchToWindowWithTitle( WINDOW_TITLES.ExtensionInFullScreenView, @@ -240,37 +221,19 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () { `window.ethereum.request(${switchEthereumChainRequest})`, ); - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.findElement({ - text: 'Use your enabled networks', - tag: 'p', - }); - await driver.switchToWindowWithUrl(DAPP_ONE_URL); await driver.clickElement('#sendButton'); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.clickElement({ text: 'Cancel', tag: 'button' }); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.switchToWindowWithUrl(DAPP_ONE_URL); // Wait for switch confirmation to close then tx confirmation to show. // There is an extra window appearing and disappearing // so we leave this delay until the issue is fixed (#27360) await driver.delay(5000); - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - - // Check correct network on the send confirmation. - await driver.findElement({ - css: '[data-testid="network-display"]', - text: 'Localhost 8546', - }); - - await driver.clickElementAndWaitForWindowToClose({ - text: 'Confirm', - tag: 'button', - }); // Switch back to the extension await driver.switchToWindowWithTitle( diff --git a/test/e2e/tests/request-queuing/multi-dapp-sendTx-revokePermission.spec.js b/test/e2e/tests/request-queuing/multi-dapp-sendTx-revokePermission.spec.js index d32e96e29571..06d232635131 100644 --- a/test/e2e/tests/request-queuing/multi-dapp-sendTx-revokePermission.spec.js +++ b/test/e2e/tests/request-queuing/multi-dapp-sendTx-revokePermission.spec.js @@ -88,7 +88,7 @@ describe('Request Queuing for Multiple Dapps and Txs on different networks revok await driver.switchToWindowWithUrl(DAPP_URL); await driver.findElement({ css: '[id="chainId"]', - text: '0x1', + text: '0x539', }); await driver.clickElement('#sendButton'); @@ -108,7 +108,7 @@ describe('Request Queuing for Multiple Dapps and Txs on different networks revok await driver.switchToWindowWithUrl(DAPP_URL); await driver.findElement({ css: '[id="chainId"]', - text: '0x1', + text: '0x539', }); await driver.assertElementNotPresent({ css: '[id="chainId"]', diff --git a/test/e2e/tests/request-queuing/switchChain-watchAsset.spec.js b/test/e2e/tests/request-queuing/switchChain-watchAsset.spec.js index 308a9c36914b..5767bd26def5 100644 --- a/test/e2e/tests/request-queuing/switchChain-watchAsset.spec.js +++ b/test/e2e/tests/request-queuing/switchChain-watchAsset.spec.js @@ -3,9 +3,9 @@ const { defaultGanacheOptions, logInWithBalanceValidation, openDapp, - switchToNotificationWindow, WINDOW_TITLES, withFixtures, + switchToNotificationWindow, } = require('../../helpers'); const { SMART_CONTRACTS } = require('../../seeder/smart-contracts'); const { DAPP_URL } = require('../../constants'); @@ -48,7 +48,17 @@ describe('Request Queue SwitchChain -> WatchAsset', function () { await driver.clickElement('#connectButton'); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + const editButtons = await driver.findElements('[data-testid="edit"]'); + + await editButtons[1].click(); + // Disconnect Localhost 8545. By Default, this was the globally selected network + await driver.clickElement({ + text: 'Localhost 8545', + tag: 'p', + }); + + await driver.clickElement('[data-testid="connect-more-chains-button"]'); await driver.clickElementAndWaitForWindowToClose({ text: 'Connect', tag: 'button', @@ -72,7 +82,6 @@ describe('Request Queue SwitchChain -> WatchAsset', function () { text: 'Use your enabled networks', tag: 'p', }); - // Switch back to test dapp await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); @@ -81,7 +90,6 @@ describe('Request Queue SwitchChain -> WatchAsset', function () { text: 'Add Token(s) to Wallet', tag: 'button', }); - await switchToNotificationWindow(driver); // Confirm Switch Network diff --git a/ui/pages/permissions-connect/connect-page/connect-page.tsx b/ui/pages/permissions-connect/connect-page/connect-page.tsx index 0ae22b3d9e0f..d06af46e7dfb 100644 --- a/ui/pages/permissions-connect/connect-page/connect-page.tsx +++ b/ui/pages/permissions-connect/connect-page/connect-page.tsx @@ -39,6 +39,7 @@ import { EndowmentTypes, RestrictedMethods, } from '../../../../shared/constants/permissions'; +import { getMultichainNetwork } from '../../../selectors/multichain'; export type ConnectPageRequest = { id: string; @@ -92,10 +93,25 @@ export const ConnectPage: React.FC = ({ ), [networkConfigurations], ); + + // By default, if a non test network is the globally selected network. We will only show non test networks as default selected. + const currentlySelectedNetwork = useSelector(getMultichainNetwork); + const currentlySelectedNetworkChainId = + currentlySelectedNetwork.network.chainId; + // If globally selected network is a test network, include that in the default selcted networks for connection request + const selectedTestNetwork = testNetworks.filter( + (network: { chainId: string }) => + network.chainId === currentlySelectedNetworkChainId, + ); + + const selectedNetworksList = + selectedTestNetwork === undefined + ? nonTestNetworks + : [...nonTestNetworks, ...selectedTestNetwork]; const defaultSelectedChainIds = requestedChainIds.length > 0 ? requestedChainIds - : nonTestNetworks.map(({ chainId }) => chainId); + : selectedNetworksList.map(({ chainId }) => chainId); const [selectedChainIds, setSelectedChainIds] = useState( defaultSelectedChainIds, );