Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @tobelabs/chainwright

## 0.10.10

### Patch Changes

- [Solflare] - Close the "What's new" modal popup during onboarding

## 0.10.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chainwright",
"version": "0.10.9",
"version": "0.10.10",
"description": "Playwright Web3 wallet testing framework for end-to-end dApp automation with MetaMask, Phantom, Solflare, Petra, Meteor, and Keplr",
"type": "module",
"license": "MIT",
Expand Down
7 changes: 3 additions & 4 deletions src/wallets/phantom/actions/onboard.phantom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,13 @@ export default async function onboard({ page, additionalAccounts, ...args }: Onb
}

if (additionalAccounts && additionalAccounts.length > 0) {
let cancelled = false;
const isCancelled = () => cancelled;
const autoCloseController = new AbortController();

autoClosePhantomNotification(newPage, isCancelled).catch((error) => console.error({ error }));
autoClosePhantomNotification(newPage, autoCloseController.signal).catch((error) => console.error({ error }));

for (const { accountName, chain, privateKey } of additionalAccounts) {
await addAccount({ page: newPage, privateKey, accountName, chain });
cancelled = true;
autoCloseController.abort();
}

await switchAccount(newPage, args.accountName);
Expand Down
7 changes: 3 additions & 4 deletions src/wallets/phantom/phantom-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ export const phantomFixture = ({ slowMo = 0, profileName }: WalletProfileFixture
},
autoCloseNotification: [
async ({ context: _ }, use) => {
let cancelled = false;
const isCancelled = () => cancelled;
const runner = autoClosePhantomNotification(_phantomPage, isCancelled);
const autoCloseController = new AbortController();
const runner = autoClosePhantomNotification(_phantomPage, autoCloseController.signal);

await use(undefined);

cancelled = true;
autoCloseController.abort();
await runner.catch((error) => {
console.error(`Auto close notification error: ${(error as Error).message}`);
});
Expand Down
18 changes: 4 additions & 14 deletions src/wallets/phantom/utils.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import type { Page } from "@playwright/test";
import { sleep } from "@/utils/sleep";

export async function autoClosePhantomNotification(page: Page, isCancelled: () => boolean) {
export async function autoClosePhantomNotification(page: Page, signal: AbortSignal) {
const INTERVAL = 300;
let IS_POLLING_COMPLETE = false;

while (!isCancelled()) {
const _isCancelled = isCancelled();

// Check if notification is closed
// If it's closed or cancelled, there's no need to check again
if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

while (!signal.aborted && !page.isClosed()) {
try {
const notificationPopupBackButton = page.locator("div[id='modal']").locator("div > svg").first();
const isNotificationButtonVisible = await notificationPopupBackButton.isVisible().catch(() => false);

if (isNotificationButtonVisible) {
await notificationPopupBackButton.click();
IS_POLLING_COMPLETE = true;
return;
}
} catch (error) {
if (page.isClosed()) break;
console.error("[autoClosePhantomNotification]: ", error);
if (page.isClosed()) return;
}

// Check if polling is complete
if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

await sleep(INTERVAL);
}
}
7 changes: 7 additions & 0 deletions src/wallets/solflare/actions/onboard.solflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Page } from "@playwright/test";
import { getWalletPasswordFromCache } from "@/utils/wallets/get-wallet-password-from-cache";
import { onboardingSelectors } from "../selectors/onboard-selectors.solflare";
import type { OnboardingArgs } from "../types";
import { autoCloseSolflareNotification } from "../utils";
import { addAccount } from "./add-account.solflare";
import { renameAccount } from "./rename-account.solflare";
import { switchNetwork } from "./switch-network.solflare";
Expand Down Expand Up @@ -42,6 +43,10 @@ export async function onboard({ page, recoveryPhrase, network, walletName, addit
const IAgreeButton = page.getByTestId(onboardingSelectors.IAgreeButton);
await IAgreeButton.click();

const autoCloseController = new AbortController();

autoCloseSolflareNotification(page, autoCloseController.signal).catch((error) => console.error({ error }));

if (walletName) {
// "Main Wallet" is the default wallet name for the fist wallet in Solflare.
await renameAccount({ page, currentAccountName: "Main Wallet", newAccountName: walletName });
Expand All @@ -56,5 +61,7 @@ export async function onboard({ page, recoveryPhrase, network, walletName, addit
}
}

autoCloseController.abort();

console.info(styleText("greenBright", "✨ Solflare onboarding completed successfully", { validateStream: false }));
}
7 changes: 3 additions & 4 deletions src/wallets/solflare/solflare-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ export const solflareFixture = ({ slowMo = 0, profileName }: WalletProfileFixtur
},
autoCloseNotification: [
async ({ context: _ }, use) => {
let cancelled = false;
const isCancelled = () => cancelled;
const runner = autoCloseSolflareNotification(_solflarePage, isCancelled);
const autoCloseController = new AbortController();
const runner = autoCloseSolflareNotification(_solflarePage, autoCloseController.signal);

await use(undefined);

cancelled = true;
autoCloseController.abort();
await runner.catch((error) => {
console.error(`Auto close notification error: ${(error as Error).message}`);
});
Expand Down
15 changes: 3 additions & 12 deletions src/wallets/solflare/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import type { Page } from "@playwright/test";
import { sleep } from "@/utils/sleep";

export async function autoCloseSolflareNotification(page: Page, isCancelled: () => boolean) {
export async function autoCloseSolflareNotification(page: Page, signal: AbortSignal) {
const INTERVAL = 150;
let IS_POLLING_COMPLETE = false;

while (!isCancelled()) {
const _isCancelled = isCancelled();

// Check if notification is closed
// If it's closed or cancelled, there's no need to check again
if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

while (!signal.aborted && !page.isClosed()) {
try {
const notificationPopupCloseButton = page
.locator("div[role='dialog']")
Expand All @@ -23,14 +16,12 @@ export async function autoCloseSolflareNotification(page: Page, isCancelled: ()

if (isNotificationPopupCloseButtonVisisble) {
await notificationPopupCloseButton.click();
IS_POLLING_COMPLETE = true;
return;
}
} catch (error) {
console.error("[autoCloseSolflareNotification]: ", error);
}

if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

await sleep(INTERVAL);
}
}