-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Support multiple accounts connection (#1101)
* ✨ feat: Support multiple account connection Signed-off-by: Mateusz Franczuk <[email protected]> * chore: separated 'connectMultipleAccounts' function --------- Signed-off-by: Mateusz Franczuk <[email protected]>
- Loading branch information
Showing
8 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 37 additions & 5 deletions
42
wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
import type { Page } from '@playwright/test' | ||
import type { Locator, Page } from '@playwright/test' | ||
import { allTextContents } from '../../../utils/allTextContents' | ||
import Selectors from '../selectors' | ||
|
||
export async function connectToDapp(notificationPage: Page) { | ||
// Click `Next`. | ||
await notificationPage.locator(Selectors.ActionFooter.confirmActionButton).click() | ||
async function selectAccounts(accountsToSelect: string[], accountLocators: Locator[], availableAccountNames: string[]) { | ||
for (const account of accountsToSelect) { | ||
const accountNameIndex = availableAccountNames.findIndex((name) => name.startsWith(account)) | ||
if (accountNameIndex < 0) throw new Error(`[ConnectToDapp] Account with name ${account} not found`) | ||
await accountLocators[accountNameIndex]?.locator(Selectors.ConnectPage.accountCheckbox).check() | ||
} | ||
} | ||
|
||
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) | ||
} | ||
|
||
// Click `Connect`. | ||
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) { | ||
await connectMultipleAccounts(notificationPage, accounts) | ||
} | ||
|
||
await confirmConnection(notificationPage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
wallets/metamask/src/pages/NotificationPage/selectors/connectPage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default { | ||
accountOption: '.choose-account-list .choose-account-list__list .choose-account-list__account', | ||
accountCheckbox: 'input.choose-account-list__list-check-box' | ||
} |
2 changes: 2 additions & 0 deletions
2
wallets/metamask/src/pages/NotificationPage/selectors/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters