w3wallets 1.0.0-beta.6 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -134,10 +134,6 @@ declare class Metamask extends Wallet {
134
134
  */
135
135
  lock(): Promise<void>;
136
136
  /**
137
- * Unlock MetaMask with password.
138
- * After unlocking, stabilizes the wallet UI by handling post-unlock
139
- * screens (metametrics, onboarding completion) and dismissing queued
140
- * notifications. Ends on home.html with the wallet UI ready.
141
137
  * Unlock MetaMask with password.
142
138
  * After unlocking, stabilizes the wallet UI by handling post-unlock
143
139
  * screens (metametrics, onboarding completion) and dismissing queued
package/dist/index.d.ts CHANGED
@@ -134,10 +134,6 @@ declare class Metamask extends Wallet {
134
134
  */
135
135
  lock(): Promise<void>;
136
136
  /**
137
- * Unlock MetaMask with password.
138
- * After unlocking, stabilizes the wallet UI by handling post-unlock
139
- * screens (metametrics, onboarding completion) and dismissing queued
140
- * notifications. Ends on home.html with the wallet UI ready.
141
137
  * Unlock MetaMask with password.
142
138
  * After unlocking, stabilizes the wallet UI by handling post-unlock
143
139
  * screens (metametrics, onboarding completion) and dismissing queued
package/dist/index.js CHANGED
@@ -98,12 +98,14 @@ var ARIA_CLOSE_TIMEOUT = 500;
98
98
  var POPUP_HIDDEN_TIMEOUT = 3e3;
99
99
  var POST_UNLOCK_TIMEOUT = 3e4;
100
100
  var NOTIFICATION_CHECK_TIMEOUT = 5e3;
101
- var CONFIRMATION_ROUTE_TIMEOUT = 15e3;
102
101
  var POST_CLICK_TIMEOUT = 1e4;
103
102
  var BUTTON_OR_POPUP_TIMEOUT = 3e4;
104
103
  var LAST_RESORT_CLICK_TIMEOUT = 1e4;
105
104
  var LOCK_SCREEN_TIMEOUT = 3e4;
106
105
  var MENU_BUTTON_TIMEOUT = 3e4;
106
+ var ONBOARD_VISIBLE_TIMEOUT = 3e4;
107
+ var ROUTE_RETRY_TIMEOUT = 5e3;
108
+ var MAX_ROUTE_ATTEMPTS = 5;
107
109
  var MNEMONIC_KEY_DELAY = 5;
108
110
  var MNEMONIC_WORD_DELAY = 100;
109
111
 
@@ -176,7 +178,7 @@ function withWallets(test, ...wallets) {
176
178
  });
177
179
  const extensionPaths = extensionInfo.map((e) => e.path);
178
180
  const fixtures = {
179
- context: async (_, use, testInfo) => {
181
+ context: async ({}, use, testInfo) => {
180
182
  const userDataDir = import_path3.default.join(
181
183
  process.cwd(),
182
184
  W3WALLETS_DIR,
@@ -293,7 +295,6 @@ async function findCachedExtension(context, ExtensionClass, expectedExtensionId,
293
295
  const page = await context.newPage();
294
296
  if (homeUrl) {
295
297
  await page.goto(`chrome-extension://${expectedExtensionId}/${homeUrl}`);
296
- await page.goto(`chrome-extension://${expectedExtensionId}/${homeUrl}`);
297
298
  }
298
299
  const extension = new ExtensionClass(page, expectedExtensionId);
299
300
  return extension;
@@ -360,7 +361,7 @@ var Metamask = class extends Wallet {
360
361
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
361
362
  await (0, import_test3.expect)(
362
363
  this.page.getByRole("button", { name: "I have an existing wallet" })
363
- ).toBeVisible({ timeout: config.expectTimeout });
364
+ ).toBeVisible({ timeout: ONBOARD_VISIBLE_TIMEOUT });
364
365
  }
365
366
  /**
366
367
  * Onboard MetaMask with a mnemonic phrase
@@ -385,7 +386,6 @@ var Metamask = class extends Wallet {
385
386
  }
386
387
  const continueBtn = this.page.getByTestId("import-srp-confirm");
387
388
  await (0, import_test3.expect)(continueBtn).toBeEnabled({ timeout: config.expectTimeout });
388
- await (0, import_test3.expect)(continueBtn).toBeEnabled({ timeout: config.expectTimeout });
389
389
  await continueBtn.click();
390
390
  const passwordInputs = this.page.locator('input[type="password"]');
391
391
  await passwordInputs.nth(0).fill(pwd);
@@ -399,7 +399,6 @@ var Metamask = class extends Wallet {
399
399
  });
400
400
  await openWalletBtn.click();
401
401
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
402
- await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
403
402
  await this.page.goto(
404
403
  `chrome-extension://${this.extensionId}/sidepanel.html`
405
404
  );
@@ -537,26 +536,26 @@ var Metamask = class extends Wallet {
537
536
  await btnLocator.first().waitFor({ state: "visible", timeout: BUTTON_OR_POPUP_TIMEOUT });
538
537
  await btnLocator.first().click();
539
538
  };
540
- await this.page.goto(sidepanelUrl);
541
- try {
542
- await this.page.waitForURL(confirmRoutePattern, {
543
- timeout: CONFIRMATION_ROUTE_TIMEOUT
544
- });
545
- } catch {
546
- console.warn(
547
- `[w3wallets] confirmation route not found, retrying. URL: ${this.page.url()}`
548
- );
539
+ let routeFound = false;
540
+ for (let attempt = 0; attempt < MAX_ROUTE_ATTEMPTS; attempt++) {
549
541
  await this.page.goto(sidepanelUrl);
550
542
  try {
551
543
  await this.page.waitForURL(confirmRoutePattern, {
552
- timeout: CONFIRMATION_ROUTE_TIMEOUT
544
+ timeout: ROUTE_RETRY_TIMEOUT
553
545
  });
546
+ routeFound = true;
547
+ break;
554
548
  } catch {
555
- console.warn(
556
- `[w3wallets] confirmation route not found after retry. URL: ${this.page.url()}`
549
+ debug(
550
+ `metamask.waitAndClickButton: route attempt ${attempt + 1}/${MAX_ROUTE_ATTEMPTS} failed. URL: ${this.page.url()}`
557
551
  );
558
552
  }
559
553
  }
554
+ if (!routeFound) {
555
+ console.warn(
556
+ `[w3wallets] confirmation route not found after ${MAX_ROUTE_ATTEMPTS} attempts. URL: ${this.page.url()}`
557
+ );
558
+ }
560
559
  const result = await waitForButtonOrPopup(BUTTON_OR_POPUP_TIMEOUT);
561
560
  debug(
562
561
  `metamask.waitAndClickButton: result=${result}, URL=${this.page.url()}`
@@ -610,14 +609,10 @@ var Metamask = class extends Wallet {
610
609
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
611
610
  const menuBtn = this.page.getByTestId("account-options-menu-button");
612
611
  await menuBtn.waitFor({ state: "visible", timeout: MENU_BUTTON_TIMEOUT });
613
- await menuBtn.click();
612
+ await menuBtn.click({ force: true });
614
613
  await this.page.locator("text=Log out").click();
615
614
  }
616
615
  /**
617
- * Unlock MetaMask with password.
618
- * After unlocking, stabilizes the wallet UI by handling post-unlock
619
- * screens (metametrics, onboarding completion) and dismissing queued
620
- * notifications. Ends on home.html with the wallet UI ready.
621
616
  * Unlock MetaMask with password.
622
617
  * After unlocking, stabilizes the wallet UI by handling post-unlock
623
618
  * screens (metametrics, onboarding completion) and dismissing queued
@@ -627,7 +622,6 @@ var Metamask = class extends Wallet {
627
622
  debug("metamask.unlock: starting");
628
623
  const pwd = password ?? this.defaultPassword;
629
624
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
630
- await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
631
625
  const passwordInput = this.page.getByTestId("unlock-password");
632
626
  await passwordInput.fill(pwd);
633
627
  await this.page.getByTestId("unlock-submit").click();
@@ -646,7 +640,7 @@ var Metamask = class extends Wallet {
646
640
  debug(`metamask.switchNetwork: ${networkName} (${networkType})`);
647
641
  await this.page.getByTestId("sort-by-networks").click();
648
642
  if (networkType === "Custom") {
649
- await this.page.getByRole("tab", { name: "Custom" }).click();
643
+ await this.page.getByRole("tab", { name: "Custom" }).click({ force: true });
650
644
  }
651
645
  await this.page.getByText(networkName).click();
652
646
  await (0, import_test3.expect)(this.page.getByTestId("sort-by-networks")).toHaveText(
@@ -672,7 +666,7 @@ var Metamask = class extends Wallet {
672
666
  await this.page.getByRole("button", { name: /save/i }).click();
673
667
  }
674
668
  async addCustomNetwork(settings) {
675
- await this.page.getByTestId("account-options-menu-button").click();
669
+ await this.page.getByTestId("account-options-menu-button").click({ force: true });
676
670
  await this.page.getByTestId("global-menu-networks").click();
677
671
  await this.page.getByRole("button", { name: "Add a custom network" }).click();
678
672
  await this.page.getByTestId("network-form-network-name").fill(settings.name);
@@ -683,11 +677,17 @@ var Metamask = class extends Wallet {
683
677
  await this.page.getByTestId("rpc-url-input-test").fill(settings.rpc);
684
678
  await this.page.getByRole("button", { name: "Add URL" }).click();
685
679
  await this.page.getByRole("button", { name: "Save" }).click();
680
+ await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
681
+ await this.page.waitForLoadState("domcontentloaded");
686
682
  }
687
683
  async enableTestNetworks() {
688
- await this.page.getByTestId("account-options-menu-button").click();
684
+ await this.page.getByTestId("account-options-menu-button").click({ force: true });
689
685
  await this.page.getByTestId("global-menu-networks").click();
690
- await this.page.locator("text=Show test networks >> xpath=following-sibling::label").click();
686
+ const toggle = this.page.locator(
687
+ "text=Show test networks >> xpath=following-sibling::label"
688
+ );
689
+ await (0, import_test3.expect)(toggle).toBeVisible({ timeout: config.expectTimeout });
690
+ await toggle.click();
691
691
  await this.page.keyboard.press("Escape");
692
692
  }
693
693
  async importAccount(privateKey) {
package/dist/index.mjs CHANGED
@@ -1,6 +1,9 @@
1
- import {
2
- __require
3
- } from "./chunk-HEBXNMVQ.mjs";
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
4
7
 
5
8
  // src/withWallets.ts
6
9
  import path3 from "path";
@@ -59,12 +62,14 @@ var ARIA_CLOSE_TIMEOUT = 500;
59
62
  var POPUP_HIDDEN_TIMEOUT = 3e3;
60
63
  var POST_UNLOCK_TIMEOUT = 3e4;
61
64
  var NOTIFICATION_CHECK_TIMEOUT = 5e3;
62
- var CONFIRMATION_ROUTE_TIMEOUT = 15e3;
63
65
  var POST_CLICK_TIMEOUT = 1e4;
64
66
  var BUTTON_OR_POPUP_TIMEOUT = 3e4;
65
67
  var LAST_RESORT_CLICK_TIMEOUT = 1e4;
66
68
  var LOCK_SCREEN_TIMEOUT = 3e4;
67
69
  var MENU_BUTTON_TIMEOUT = 3e4;
70
+ var ONBOARD_VISIBLE_TIMEOUT = 3e4;
71
+ var ROUTE_RETRY_TIMEOUT = 5e3;
72
+ var MAX_ROUTE_ATTEMPTS = 5;
68
73
  var MNEMONIC_KEY_DELAY = 5;
69
74
  var MNEMONIC_WORD_DELAY = 100;
70
75
 
@@ -137,7 +142,7 @@ function withWallets(test, ...wallets) {
137
142
  });
138
143
  const extensionPaths = extensionInfo.map((e) => e.path);
139
144
  const fixtures = {
140
- context: async (_, use, testInfo) => {
145
+ context: async ({}, use, testInfo) => {
141
146
  const userDataDir = path3.join(
142
147
  process.cwd(),
143
148
  W3WALLETS_DIR,
@@ -254,7 +259,6 @@ async function findCachedExtension(context, ExtensionClass, expectedExtensionId,
254
259
  const page = await context.newPage();
255
260
  if (homeUrl) {
256
261
  await page.goto(`chrome-extension://${expectedExtensionId}/${homeUrl}`);
257
- await page.goto(`chrome-extension://${expectedExtensionId}/${homeUrl}`);
258
262
  }
259
263
  const extension = new ExtensionClass(page, expectedExtensionId);
260
264
  return extension;
@@ -321,7 +325,7 @@ var Metamask = class extends Wallet {
321
325
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
322
326
  await expect(
323
327
  this.page.getByRole("button", { name: "I have an existing wallet" })
324
- ).toBeVisible({ timeout: config.expectTimeout });
328
+ ).toBeVisible({ timeout: ONBOARD_VISIBLE_TIMEOUT });
325
329
  }
326
330
  /**
327
331
  * Onboard MetaMask with a mnemonic phrase
@@ -346,7 +350,6 @@ var Metamask = class extends Wallet {
346
350
  }
347
351
  const continueBtn = this.page.getByTestId("import-srp-confirm");
348
352
  await expect(continueBtn).toBeEnabled({ timeout: config.expectTimeout });
349
- await expect(continueBtn).toBeEnabled({ timeout: config.expectTimeout });
350
353
  await continueBtn.click();
351
354
  const passwordInputs = this.page.locator('input[type="password"]');
352
355
  await passwordInputs.nth(0).fill(pwd);
@@ -360,7 +363,6 @@ var Metamask = class extends Wallet {
360
363
  });
361
364
  await openWalletBtn.click();
362
365
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
363
- await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
364
366
  await this.page.goto(
365
367
  `chrome-extension://${this.extensionId}/sidepanel.html`
366
368
  );
@@ -498,26 +500,26 @@ var Metamask = class extends Wallet {
498
500
  await btnLocator.first().waitFor({ state: "visible", timeout: BUTTON_OR_POPUP_TIMEOUT });
499
501
  await btnLocator.first().click();
500
502
  };
501
- await this.page.goto(sidepanelUrl);
502
- try {
503
- await this.page.waitForURL(confirmRoutePattern, {
504
- timeout: CONFIRMATION_ROUTE_TIMEOUT
505
- });
506
- } catch {
507
- console.warn(
508
- `[w3wallets] confirmation route not found, retrying. URL: ${this.page.url()}`
509
- );
503
+ let routeFound = false;
504
+ for (let attempt = 0; attempt < MAX_ROUTE_ATTEMPTS; attempt++) {
510
505
  await this.page.goto(sidepanelUrl);
511
506
  try {
512
507
  await this.page.waitForURL(confirmRoutePattern, {
513
- timeout: CONFIRMATION_ROUTE_TIMEOUT
508
+ timeout: ROUTE_RETRY_TIMEOUT
514
509
  });
510
+ routeFound = true;
511
+ break;
515
512
  } catch {
516
- console.warn(
517
- `[w3wallets] confirmation route not found after retry. URL: ${this.page.url()}`
513
+ debug(
514
+ `metamask.waitAndClickButton: route attempt ${attempt + 1}/${MAX_ROUTE_ATTEMPTS} failed. URL: ${this.page.url()}`
518
515
  );
519
516
  }
520
517
  }
518
+ if (!routeFound) {
519
+ console.warn(
520
+ `[w3wallets] confirmation route not found after ${MAX_ROUTE_ATTEMPTS} attempts. URL: ${this.page.url()}`
521
+ );
522
+ }
521
523
  const result = await waitForButtonOrPopup(BUTTON_OR_POPUP_TIMEOUT);
522
524
  debug(
523
525
  `metamask.waitAndClickButton: result=${result}, URL=${this.page.url()}`
@@ -571,14 +573,10 @@ var Metamask = class extends Wallet {
571
573
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
572
574
  const menuBtn = this.page.getByTestId("account-options-menu-button");
573
575
  await menuBtn.waitFor({ state: "visible", timeout: MENU_BUTTON_TIMEOUT });
574
- await menuBtn.click();
576
+ await menuBtn.click({ force: true });
575
577
  await this.page.locator("text=Log out").click();
576
578
  }
577
579
  /**
578
- * Unlock MetaMask with password.
579
- * After unlocking, stabilizes the wallet UI by handling post-unlock
580
- * screens (metametrics, onboarding completion) and dismissing queued
581
- * notifications. Ends on home.html with the wallet UI ready.
582
580
  * Unlock MetaMask with password.
583
581
  * After unlocking, stabilizes the wallet UI by handling post-unlock
584
582
  * screens (metametrics, onboarding completion) and dismissing queued
@@ -588,7 +586,6 @@ var Metamask = class extends Wallet {
588
586
  debug("metamask.unlock: starting");
589
587
  const pwd = password ?? this.defaultPassword;
590
588
  await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
591
- await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
592
589
  const passwordInput = this.page.getByTestId("unlock-password");
593
590
  await passwordInput.fill(pwd);
594
591
  await this.page.getByTestId("unlock-submit").click();
@@ -607,7 +604,7 @@ var Metamask = class extends Wallet {
607
604
  debug(`metamask.switchNetwork: ${networkName} (${networkType})`);
608
605
  await this.page.getByTestId("sort-by-networks").click();
609
606
  if (networkType === "Custom") {
610
- await this.page.getByRole("tab", { name: "Custom" }).click();
607
+ await this.page.getByRole("tab", { name: "Custom" }).click({ force: true });
611
608
  }
612
609
  await this.page.getByText(networkName).click();
613
610
  await expect(this.page.getByTestId("sort-by-networks")).toHaveText(
@@ -633,7 +630,7 @@ var Metamask = class extends Wallet {
633
630
  await this.page.getByRole("button", { name: /save/i }).click();
634
631
  }
635
632
  async addCustomNetwork(settings) {
636
- await this.page.getByTestId("account-options-menu-button").click();
633
+ await this.page.getByTestId("account-options-menu-button").click({ force: true });
637
634
  await this.page.getByTestId("global-menu-networks").click();
638
635
  await this.page.getByRole("button", { name: "Add a custom network" }).click();
639
636
  await this.page.getByTestId("network-form-network-name").fill(settings.name);
@@ -644,11 +641,17 @@ var Metamask = class extends Wallet {
644
641
  await this.page.getByTestId("rpc-url-input-test").fill(settings.rpc);
645
642
  await this.page.getByRole("button", { name: "Add URL" }).click();
646
643
  await this.page.getByRole("button", { name: "Save" }).click();
644
+ await this.page.goto(`chrome-extension://${this.extensionId}/home.html`);
645
+ await this.page.waitForLoadState("domcontentloaded");
647
646
  }
648
647
  async enableTestNetworks() {
649
- await this.page.getByTestId("account-options-menu-button").click();
648
+ await this.page.getByTestId("account-options-menu-button").click({ force: true });
650
649
  await this.page.getByTestId("global-menu-networks").click();
651
- await this.page.locator("text=Show test networks >> xpath=following-sibling::label").click();
650
+ const toggle = this.page.locator(
651
+ "text=Show test networks >> xpath=following-sibling::label"
652
+ );
653
+ await expect(toggle).toBeVisible({ timeout: config.expectTimeout });
654
+ await toggle.click();
652
655
  await this.page.keyboard.press("Escape");
653
656
  }
654
657
  async importAccount(privateKey) {
@@ -231,7 +231,8 @@ async function buildAllCaches(directory, options2 = {}) {
231
231
  outDir: distDir,
232
232
  format: ["cjs"],
233
233
  clean: true,
234
- silent: true
234
+ silent: true,
235
+ external: ["@playwright/test"]
235
236
  });
236
237
  let built = 0;
237
238
  let skipped = 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "w3wallets",
3
3
  "description": "browser wallets for playwright",
4
- "version": "1.0.0-beta.6",
4
+ "version": "1.0.0-beta.8",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "homepage": "https://github.com/Maksandre/w3wallets",
@@ -1,48 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
- var __esm = (fn, res) => function __init() {
14
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
- };
16
- var __commonJS = (cb, mod) => function __require2() {
17
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
- };
19
- var __export = (target, all) => {
20
- for (var name in all)
21
- __defProp(target, name, { get: all[name], enumerable: true });
22
- };
23
- var __copyProps = (to, from, except, desc) => {
24
- if (from && typeof from === "object" || typeof from === "function") {
25
- for (let key of __getOwnPropNames(from))
26
- if (!__hasOwnProp.call(to, key) && key !== except)
27
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
- }
29
- return to;
30
- };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
- // If the importer is in node compatibility mode or this is not an ESM
33
- // file that has been converted to a CommonJS file using a Babel-
34
- // compatible transform (i.e. "__esModule" has not been set), then set
35
- // "default" to the CommonJS "module.exports" for node compatibility.
36
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
- mod
38
- ));
39
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
-
41
- export {
42
- __require,
43
- __esm,
44
- __commonJS,
45
- __export,
46
- __toESM,
47
- __toCommonJS
48
- };