Skip to content

Commit

Permalink
feat: update setnetwork
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Mucha <[email protected]>
  • Loading branch information
drptbl committed Oct 29, 2022
1 parent 7f34515 commit 7050dbf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
30 changes: 24 additions & 6 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,28 @@ module.exports = {
await playwright.waitAndClick(mainPageElements.networkSwitcher.button);
if (typeof network === 'string') {
network = network.toLowerCase();
await playwright.waitAndClickByText(
mainPageElements.networkSwitcher.dropdownMenuItem,
network,
);
if (network === 'mainnet') {
await playwright.waitAndClick(
mainPageElements.networkSwitcher.mainnetNetworkItem,
);
} else if (network === 'goerli') {
await playwright.waitAndClick(
mainPageElements.networkSwitcher.goerliNetworkItem,
);
} else if (network === 'sepolia') {
await playwright.waitAndClick(
mainPageElements.networkSwitcher.sepoliaNetworkItem,
);
} else if (network === 'localhost') {
await playwright.waitAndClick(
mainPageElements.networkSwitcher.localhostNetworkItem,
);
} else {
await playwright.waitAndClickByText(
mainPageElements.networkSwitcher.dropdownMenuItem,
network,
);
}
await playwright.waitForText(
mainPageElements.networkSwitcher.networkName,
network,
Expand All @@ -387,7 +405,7 @@ module.exports = {
network.networkName,
);
}
setNetwork(network);
await setNetwork(network);
await switchToCypressIfNotActive();
return true;
},
Expand Down Expand Up @@ -445,7 +463,7 @@ module.exports = {
},
);
await module.exports.closePopupAndTooltips();
setNetwork(network);
await setNetwork(network);
await playwright.waitForText(
mainPageElements.networkSwitcher.networkName,
network.networkName,
Expand Down
27 changes: 14 additions & 13 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const log = require('debug')('synpress:helpers');
const axios = require('axios');
const fs = require('fs').promises;
const path = require('path');
const { ethers } = require('ethers');
const download = require('download');
const packageJson = require('./package.json');

Expand All @@ -10,7 +11,7 @@ let networkId = 1;
let isTestnet = false;

module.exports = {
setNetwork: network => {
setNetwork: async network => {
typeof network === 'object'
? log(`Setting network to ${JSON.stringify(network)}`)
: log(`Setting network to ${network}`);
Expand All @@ -19,22 +20,22 @@ module.exports = {
networkName = 'mainnet';
networkId = 1;
isTestnet = false;
} else if (network === 'ropsten') {
networkName = 'ropsten';
networkId = 3;
isTestnet = true;
} else if (network === 'kovan') {
networkName = 'kovan';
networkId = 42;
isTestnet = true;
} else if (network === 'rinkeby') {
networkName = 'rinkeby';
networkId = 4;
isTestnet = true;
} else if (network === 'goerli') {
networkName = 'goerli';
networkId = 5;
isTestnet = true;
} else if (network === 'sepolia') {
networkName = 'sepolia';
networkId = 11155111;
isTestnet = true;
} else if (network === 'localhost') {
const provider = new ethers.providers.JsonRpcProvider(
'http://127.0.0.1:8545',
);
const { chainId, name } = await provider.getNetwork();
networkName = name;
networkId = chainId;
isTestnet = true;
} else if (typeof network === 'object') {
networkName = network.networkName;
networkId = Number(network.chainId);
Expand Down

0 comments on commit 7050dbf

Please sign in to comment.