Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: account lookup error in wallet management functions #1688

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/app/playwright/crx/utils/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import type { MockData } from '../../mocks';

export async function getAccountByName(popupPage: Page, name: string) {
const accounts = await getWalletAccounts(popupPage);
return accounts.find((account) => account.name === name);

// Added check to throw an error if account is not found
const account = accounts.find((account) => account.name === name);
if (!account) {
throw new Error(`Account with name "${name}" not found`);
}

return account;
}

export async function getWalletAccounts(popupPage: Page) {
Expand All @@ -20,8 +27,6 @@ export async function getWalletAccounts(popupPage: Page) {
export async function switchAccount(popupPage: Page, name: string) {
let account = await getAccountByName(popupPage, name);

// If account is already selected return it
// to avoid unnecessary changes
if (account.isCurrent) {
return account;
}
Expand All @@ -30,7 +35,6 @@ export async function switchAccount(popupPage: Page, name: string) {
await getByAriaLabel(popupPage, 'Accounts').click();

await hasText(popupPage, name);
// Add position to click on the element and not on copy button
await popupPage.waitForTimeout(5000);
await getByAriaLabel(popupPage, name).click();

Expand All @@ -44,19 +48,17 @@ export async function switchAccount(popupPage: Page, name: string) {
)
.toBeTruthy();

// Return account to be used on tests
account = await getAccountByName(popupPage, name);

return account;
}

export async function hideAccount(popupPage: Page, name: string) {
await getByAriaLabel(popupPage, 'Accounts').click();
// Add position to click on the element and not on copy button
await getByAriaLabel(popupPage, `Account Actions ${name}`).click();
await getByAriaLabel(popupPage, `Hide ${name}`).click();
await hasText(popupPage, 'Show hidden accounts');
await popupPage.getByText(name).isHidden();
await popupPage.locator(`text=${name}`).isHidden();

await getByAriaLabel(popupPage, 'Close dialog').click();
}
Expand Down Expand Up @@ -97,11 +99,11 @@ export async function createAccountFromPrivateKey(
export async function getClipboardText(popupPage: Page): Promise<string> {
try {
const text = await popupPage.evaluate(() => navigator.clipboard.readText());
console.log('Clipboard text:', text); // log the text to the console
console.log('Clipboard text:', text);
return text;
} catch (error) {
console.error('Failed to read clipboard contents:', error);
return ''; // Return empty string or handle the error as needed
return '';
}
}

Expand All @@ -112,10 +114,7 @@ export async function getAddressForAccountNumber(
): Promise<string> {
await getByAriaLabel(popupPage, 'Accounts').click();

// Construct the XPath selector dynamically based on the order of the account in the list
const xpathSelector = `/html/body/div[2]/div/div/div/div/article[${accountNumber}]/div[1]/div[2]/div/div/button`;

// Click on the element
await popupPage.click(`xpath=${xpathSelector}`);

await getByAriaLabel(popupPage, accountName).click({
Expand Down
Loading