From 0ff350aeb92ec3abdb47c6e3fd22168c541ada59 Mon Sep 17 00:00:00 2001 From: matstyler Date: Fri, 9 Feb 2024 22:53:36 +0100 Subject: [PATCH] chore: separated 'connectMultipleAccounts' function --- .../NotificationPage/actions/connectToDapp.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts b/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts index b5e4594d9..f2177fed6 100644 --- a/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts +++ b/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts @@ -10,26 +10,32 @@ async function selectAccounts(accountsToSelect: string[], accountLocators: Locat } } +async function connectMultipleAccounts(notificationPage: Page, accounts: string[]) { + // Wait for the accounts to be loaded as 'all()' doesnt not wait for the results - https://playwright.dev/docs/api/class-locator#locator-all + // Additionally disable default account to reuse necessary delay + await notificationPage + .locator(Selectors.ConnectPage.accountOption) + .locator(Selectors.ConnectPage.accountCheckbox) + .last() + .setChecked(false) + + const accountLocators = await notificationPage.locator(Selectors.ConnectPage.accountOption).all() + const accountNames = await allTextContents(accountLocators) + + await selectAccounts(accounts, accountLocators, accountNames) +} + async function confirmConnection(notificationPage: Page) { + // Click `Next` await notificationPage.locator(Selectors.ActionFooter.confirmActionButton).click() + // Click `Connect` await notificationPage.locator(Selectors.ActionFooter.confirmActionButton).click() } // By default, only the last account will be selected. If you want to select a specific account, pass `accounts` parameter. export async function connectToDapp(notificationPage: Page, accounts?: string[]) { if (accounts && accounts.length > 0) { - // Wait for the accounts to be loaded as 'all()' doesnt not wait for the results - https://playwright.dev/docs/api/class-locator#locator-all - // Additionally disable default account to reuse necessary delay - await notificationPage - .locator(Selectors.ConnectPage.accountOption) - .locator(Selectors.ConnectPage.accountCheckbox) - .last() - .setChecked(false) - - const accountLocators = await notificationPage.locator(Selectors.ConnectPage.accountOption).all() - const accountNames = await allTextContents(accountLocators) - - await selectAccounts(accounts, accountLocators, accountNames) + await connectMultipleAccounts(notificationPage, accounts) } await confirmConnection(notificationPage)