diff --git a/commands/phantom.js b/commands/phantom.js index 950ce8241..f710f5b28 100644 --- a/commands/phantom.js +++ b/commands/phantom.js @@ -225,11 +225,23 @@ module.exports = { } return true; }, - getWalletAddress: async () => { + getWalletAddress: async (chain = 'eth') => { await switchToPhantomIfNotActive(); await playwright.windows(PROVIDER).hover(mainPageElements.accountBar.title); await new Promise(resolve => setTimeout(resolve, 100)); - await playwright.waitAndClick(PROVIDER, mainPageElements.accountBar.ethRow); + + if (chain === 'eth') { + await playwright.waitAndClick( + PROVIDER, + mainPageElements.accountBar.ethRow, + ); + } else if (chain === 'solana') { + await playwright.waitAndClick( + PROVIDER, + mainPageElements.accountBar.solanaRow, + ); + } + walletAddress = await playwright .windows(PROVIDER) .evaluate('navigator.clipboard.readText()'); @@ -418,6 +430,43 @@ module.exports = { return true; } }, + selectDefaultWallet: async wallet => { + if (!Object.keys(mainPageElements.defaultWallet).includes(wallet)) { + throw new Error( + 'Wallet not supported, support ' + + Object.keys(mainPageElements.defaultWallet).join(', '), + ); + } + + await switchToPhantomIfNotActive(); + + // click settings + await playwright.waitAndClick( + PROVIDER, + mainPageElements.settingsMenu.settingsMenuButton, + ); + + // click gear in sidebar settings + await playwright.waitAndClick( + PROVIDER, + mainPageElements.settingsMenu.settingsSidebarButton, + ); + + // click default app wallet row + await playwright.waitAndClick( + PROVIDER, + mainPageElements.settingsMenu.defaultAppWalletRow, + ); + + // click option + await playwright.waitAndClick( + PROVIDER, + mainPageElements.defaultWallet[wallet], + ); + + // go back to main menu + await backToMainFromSettings(); + }, disconnectWalletFromDapp: async () => { await switchToPhantomIfNotActive(); await playwright.waitAndClick( @@ -441,6 +490,7 @@ module.exports = { .waitForSelector(mainPageElements.connectedSites.trustedAppsRevokeButton); const hasRevokeButton = await revokeButtonLocator.isVisible(); + let isDisconnected = false; if (hasRevokeButton) { console.log( '[disconnectWalletFromDapp] Wallet is connected to a dapp, disconnecting...', @@ -450,13 +500,17 @@ module.exports = { mainPageElements.connectedSites.trustedAppsRevokeButton, ); await switchToCypressIfNotActive(); - return true; + isDisconnected = true; } else { console.log( '[disconnectWalletFromDapp] Wallet is not connected to a dapp, skipping...', ); } - return false; + + // back to main + await backToMainFromSettings(); + + return isDisconnected; }, }; @@ -476,3 +530,17 @@ async function switchToCypressIfNotActive() { } return switchBackToCypressWindow; } + +async function backToMainFromSettings() { + // click back + await playwright.waitAndClick( + PROVIDER, + mainPageElements.connectedSites.trustedAppsBackButton, + ); + + // click close menu + await playwright.waitAndClick( + PROVIDER, + mainPageElements.settingsMenu.settingsSidebarCloseButton, + ); +} diff --git a/helpers.js b/helpers.js index d659da7d4..a926a80a0 100644 --- a/helpers.js +++ b/helpers.js @@ -207,53 +207,62 @@ module.exports = { let tagName; let response; - try { - if (version === 'latest' || !version) { - if (process.env.GH_USERNAME && process.env.GH_PAT) { - response = await axios.get( - 'https://api.github.com/repos/phantom-labs/phantom-wallet/releases', - { - auth: { - username: process.env.GH_USERNAME, - password: process.env.GH_PAT, - }, - }, - ); - } else { - response = await axios.get( - 'https://api.github.com/repos/phantom-labs/phantom-wallet/releases', - ); - } - filename = response.data[0].assets[0].name; - downloadUrl = response.data[0].assets[0].url; - tagName = 'phantom-chrome-latest'; - log( - `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`, - ); - } else if (version) { - filename = `chrome-dist.zip`; - downloadUrl = `https://github.com/phantom-labs/phantom-wallet/releases/download/v${version}/chrome-dist.zip`; - tagName = `phantom-chrome-${version}`; - log( - `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`, - ); - } - return { - filename, - downloadUrl, - tagName, - }; - } catch (e) { - if (e.response && e.response.status === 403) { - throw new Error( - `[getPhantomReleases] Unable to fetch phantom releases from GitHub because you've been rate limited! Please set GH_USERNAME and GH_PAT environment variables to avoid this issue or retry again.`, - ); - } else { - throw new Error( - `[getPhantomReleases] Unable to fetch phantom releases from GitHub with following error:\n${e}`, - ); - } - } + /** + * We don't have github releases public for now. Hardcode values until we have + */ + return { + filename: 'phantom-chrome-latest', + downloadUrl: 'chrome-dist.zip', + tagName: 'phantom-chrome-latest', + }; + // try { + // if (version === 'latest' || !version) { + // if (process.env.GH_USERNAME && process.env.GH_PAT) { + // response = await axios.get( + // 'https://api.github.com/repos/phantom/wallet/releases', + // { + // auth: { + // username: process.env.GH_USERNAME, + // password: process.env.GH_PAT, + // }, + // }, + // ); + // } else { + // response = await axios.get( + // 'https://api.github.com/repos/phantom/wallet/releases', + // ); + // } + // console.log(response.data[0]) + // filename = response.data[0].assets[0].name; + // downloadUrl = response.data[0].assets[0].url; + // tagName = 'phantom-chrome-latest'; + // log( + // `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`, + // ); + // } else if (version) { + // filename = `chrome-dist.zip`; + // downloadUrl = `https://github.com/phantom-labs/wallet/releases/download/v${version}/chrome-dist.zip`; + // tagName = `phantom-chrome-${version}`; + // log( + // `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`, + // ); + // } + // return { + // filename, + // downloadUrl, + // tagName, + // }; + // } catch (e) { + // if (e.response && e.response.status === 403) { + // throw new Error( + // `[getPhantomReleases] Unable to fetch phantom releases from GitHub because you've been rate limited! Please set GH_USERNAME and GH_PAT environment variables to avoid this issue or retry again.`, + // ); + // } else { + // throw new Error( + // `[getPhantomReleases] Unable to fetch phantom releases from GitHub with following error:\n${e}`, + // ); + // } + // } }, download: async (provider, url, destination) => { try { diff --git a/pages/phantom/main-page.js b/pages/phantom/main-page.js index 62e0197b7..ba674e06d 100644 --- a/pages/phantom/main-page.js +++ b/pages/phantom/main-page.js @@ -72,7 +72,9 @@ const accountMenu = { const settingsMenu = { settingsMenuButton: '[data-testid="settings-menu-open-button"]', settingsSidebarButton: '[data-testid="sidebar_menu-button-settings"]', + settingsSidebarCloseButton: '[data-testid="settings-menu-close-button"]', trustedAppsRow: '[data-testid="settings-item-trusted-apps"]', + defaultAppWalletRow: '[data-testid="settings-item-metamask-override"]', }; const whatsNew = { @@ -88,10 +90,18 @@ const welcome = { const accountBar = { title: '[data-testid="tooltip_interactive-wrapper"]', ethRow: '[data-testid="account-header-chain-eip155:1"]', + solanaRow: '[data-testid="account-header-chain-solana:101"]', +}; + +const defaultWallet = { + metamask: '[data-testid="metamask-override--USE_METAMASK"]', + phantom: '[data-testid="metamask-override--USE_PHANTOM"]', + always_ask: '[data-testid="metamask-override--ALWAYS_ASK"]', }; const connectedSites = { trustedAppsRevokeButton: '[data-testid="trusted-apps-revoke-button"]', + trustedAppsBackButton: '[data-testid="header--back"]', }; const accountModal = { @@ -151,4 +161,5 @@ module.exports.mainPageElements = { asset, whatsNew, welcome, + defaultWallet, };