w3wallets 0.10.2 → 1.0.0-beta.10

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.ts CHANGED
@@ -1,43 +1,159 @@
1
1
  import * as playwright_test from 'playwright/test';
2
2
  import { Page, test, BrowserContext } from '@playwright/test';
3
3
 
4
- /**
5
- * Represents the supported network types for the BackPack application.
6
- */
7
- type BackPackNetwork = "Solana" | "Eclipse" | "Ethereum" | "Polygon" | "Base" | "Arbitrum" | "Optimism";
8
-
9
- type WalletName = "backpack" | "polkadotJS" | "metamask";
10
- type NoDuplicates<T extends readonly unknown[], Acc extends readonly unknown[] = []> = T extends [infer Head, ...infer Tail] ? Head extends Acc[number] ? never : [Head, ...NoDuplicates<Tail, [...Acc, Head]>] : T;
11
4
  interface IWallet {
5
+ readonly page: Page;
12
6
  gotoOnboardPage(): Promise<void>;
7
+ approve(): Promise<void>;
8
+ deny(): Promise<void>;
9
+ }
10
+ /**
11
+ * Configuration object for a wallet.
12
+ */
13
+ interface WalletConfig<TName extends string = string, TWallet extends IWallet = IWallet> {
14
+ /** Unique wallet identifier, used as fixture name */
15
+ name: TName;
16
+ /** Directory name under .w3wallets/ where extension is stored */
17
+ extensionDir: string;
18
+ /** Wallet class constructor */
19
+ WalletClass: new (page: Page, extensionId: string) => TWallet;
20
+ /**
21
+ * Chrome extension ID. If not provided, it will be derived from
22
+ * the manifest.json `key` field. Required for custom extensions
23
+ * that don't have a `key` field in their manifest.
24
+ */
25
+ extensionId?: string;
26
+ /** Path to the extension's home page (e.g. "home.html"), used for cached wallets */
27
+ homeUrl?: string;
13
28
  }
29
+ /**
30
+ * Creates a wallet configuration object.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const myWallet = createWallet({
35
+ * name: "myWallet",
36
+ * extensionDir: "my-wallet",
37
+ * WalletClass: MyWalletClass,
38
+ * });
39
+ * ```
40
+ */
41
+ declare function createWallet<TName extends string, TWallet extends IWallet>(config: WalletConfig<TName, TWallet>): WalletConfig<TName, TWallet>;
42
+ /**
43
+ * Extracts fixture name from a wallet config.
44
+ */
45
+ type WalletConfigName<T> = T extends WalletConfig<infer N, IWallet> ? N : never;
46
+ /**
47
+ * Extracts wallet class instance type from a wallet config.
48
+ */
49
+ type WalletConfigInstance<T> = T extends WalletConfig<string, infer W> ? W : never;
50
+ /**
51
+ * Builds fixture types from an array of wallet configs.
52
+ */
53
+ type WalletFixturesFromConfigs<T extends readonly WalletConfig[]> = {
54
+ [K in T[number] as WalletConfigName<K>]: WalletConfigInstance<K>;
55
+ };
56
+ /**
57
+ * Supported blockchain networks.
58
+ * Common networks are listed for autocomplete, but any string is accepted.
59
+ */
60
+ type Network = "Solana" | "Eclipse" | "Ethereum" | "Polygon" | "Base" | "Arbitrum" | "Optimism" | (string & {});
61
+
62
+ /**
63
+ * Extends Playwright test with wallet fixtures.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { withWallets, metamask, polkadotJS } from "w3wallets";
68
+ *
69
+ * const test = withWallets(base, metamask, polkadotJS);
70
+ *
71
+ * test("can connect", async ({ metamask, polkadotJS }) => {
72
+ * await metamask.onboard(mnemonic);
73
+ * });
74
+ * ```
75
+ */
76
+ declare function withWallets<const T extends readonly WalletConfig[]>(test: typeof test, ...wallets: T): playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & WalletFixturesFromConfigs<T> & {
77
+ context: BrowserContext;
78
+ }, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
14
79
 
15
80
  declare abstract class Wallet implements IWallet {
16
- page: Page;
17
- protected extensionId: string;
81
+ readonly page: Page;
82
+ readonly extensionId: string;
18
83
  constructor(page: Page, extensionId: string);
19
84
  abstract gotoOnboardPage(): Promise<void>;
85
+ abstract approve(): Promise<void>;
86
+ abstract deny(): Promise<void>;
87
+ }
88
+
89
+ interface NetworkSettings {
90
+ name: string;
91
+ rpc: string;
92
+ chainId: number;
93
+ currencySymbol: string;
20
94
  }
21
95
 
22
- declare class Backpack extends Wallet {
96
+ declare class Metamask extends Wallet {
23
97
  private defaultPassword;
24
- private currentAccountId;
25
- private maxAccountId;
26
98
  gotoOnboardPage(): Promise<void>;
27
- onboard(network: BackPackNetwork, privateKey: string): Promise<void>;
28
- addAccount(network: BackPackNetwork, privateKey: string): Promise<void>;
29
99
  /**
30
- * Switch account
31
- * @param id The first added account has id 1, the second – 2, and so on
100
+ * Onboard MetaMask with a mnemonic phrase
101
+ * @param mnemonic - 12 or 24 word recovery phrase
102
+ * @param password - Optional password (defaults to TestPassword123!)
103
+ */
104
+ onboard(mnemonic: string, password?: string): Promise<void>;
105
+ /**
106
+ * Dismiss MetaMask promotional popups (e.g., "Transaction Shield")
107
+ * that may overlay the confirmation UI.
108
+ */
109
+ dismissPopups(): Promise<void>;
110
+ private waitForPopupHidden;
111
+ /**
112
+ * After unlock, MetaMask may show onboarding screens, queued
113
+ * notifications, or go straight to the wallet UI. Race all possible
114
+ * states in a single wait to avoid sequential timeout penalties.
115
+ */
116
+ private stabilizePostUnlock;
117
+ /**
118
+ * Dismiss all queued MetaMask notifications (e.g., Solana/Tron account
119
+ * removal). These use the templated confirmation flow at #/confirmation/...
120
+ * If multiple are queued, "Reject all" appears; if only one, just
121
+ * confirmation-cancel-button is available.
32
122
  */
33
- switchAccount(id: number): Promise<void>;
34
- unlock(): Promise<void>;
35
- setRPC(network: BackPackNetwork, rpc: string): Promise<void>;
36
- ignoreAndProceed(): Promise<void>;
123
+ private dismissQueuedNotifications;
124
+ /**
125
+ * Wait for a target button while handling the Transaction Shield popup.
126
+ * Always navigates to sidepanel.html fresh so MetaMask's
127
+ * ConfirmationHandler can route to the pending approval.
128
+ */
129
+ private waitAndClickButton;
37
130
  approve(): Promise<void>;
38
131
  deny(): Promise<void>;
39
- private _clickOnAccount;
40
- private _importAccount;
132
+ /**
133
+ * Lock the MetaMask wallet
134
+ */
135
+ lock(): Promise<void>;
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
+ */
142
+ unlock(password?: string): Promise<void>;
143
+ /**
144
+ * Switch to an existing network in MetaMask
145
+ * @param networkName - Name of the network to switch to (e.g., "Ethereum Mainnet", "Sepolia")
146
+ */
147
+ switchNetwork(networkName: string, networkType?: "Popular" | "Custom"): Promise<void>;
148
+ switchAccount(accountName: string): Promise<void>;
149
+ /**
150
+ * Add a custom network to MetaMask
151
+ */
152
+ addNetwork(network: NetworkSettings): Promise<void>;
153
+ addCustomNetwork(settings: NetworkSettings): Promise<void>;
154
+ enableTestNetworks(): Promise<void>;
155
+ importAccount(privateKey: string): Promise<void>;
156
+ accountNameIs(accountName: string): Promise<void>;
41
157
  }
42
158
 
43
159
  declare class PolkadotJS extends Wallet {
@@ -52,41 +168,43 @@ declare class PolkadotJS extends Wallet {
52
168
  private _getLabeledInput;
53
169
  }
54
170
 
55
- type NetworkSettings = {
56
- name: string;
57
- rpc: string;
58
- chainId: number;
59
- currencySymbol: string;
60
- };
171
+ /**
172
+ * Pre-built MetaMask wallet configuration.
173
+ */
174
+ declare const metamask: WalletConfig<"metamask", Metamask>;
175
+ /**
176
+ * Pre-built Polkadot.js wallet configuration.
177
+ */
178
+ declare const polkadotJS: WalletConfig<"polkadotJS", PolkadotJS>;
61
179
 
62
- declare class Metamask extends Wallet {
63
- private defaultPassword;
64
- gotoOnboardPage(): Promise<void>;
180
+ /**
181
+ * Configuration for w3wallets library.
182
+ * Values can be overridden via environment variables.
183
+ */
184
+ declare const config: {
65
185
  /**
66
- *
67
- * @param mnemonic 12-word mnemonic seed phrase
186
+ * Timeout for actions like click, fill, waitFor, goto.
187
+ * Set via W3WALLETS_ACTION_TIMEOUT env variable.
188
+ * @default 30000 (30 seconds)
68
189
  */
69
- onboard(mnemonic: string, password?: string): Promise<void>;
70
- switchAccount(accountName: {
71
- name: string;
72
- }): Promise<void>;
73
- importAccount(privateKey: string): Promise<void>;
74
- addAccount(accountName?: string): Promise<void>;
75
- getAccountName(): Promise<string>;
76
- connectToNetwork(networkName: string, networkType?: "Popular" | "Custom"): Promise<void>;
77
- addCustomNetwork(settings: NetworkSettings): Promise<void>;
78
- enableTestNetworks(): Promise<void>;
79
- approve(): Promise<void>;
80
- deny(): Promise<void>;
81
- private usingNotificationPage;
82
- private clickTopRightCornerToCloseAllTheMarketingBullshit;
190
+ readonly actionTimeout: number | undefined;
191
+ /**
192
+ * Timeout for expect assertions like toBeVisible, toContainText.
193
+ * Set via W3WALLETS_EXPECT_TIMEOUT env variable.
194
+ * @default undefined (uses Playwright's default of 5000ms)
195
+ */
196
+ readonly expectTimeout: number | undefined;
197
+ };
198
+
199
+ declare function debug(message: string): void;
200
+
201
+ type SetupFn<TWallet extends IWallet> = (wallet: TWallet, page: Page) => Promise<void>;
202
+ interface CachedWalletConfig<TName extends string = string, TWallet extends IWallet = IWallet> extends WalletConfig<TName, TWallet> {
203
+ setupFn: SetupFn<TWallet>;
204
+ __cached: true;
83
205
  }
206
+ declare function isCachedConfig(config: WalletConfig): config is CachedWalletConfig;
84
207
 
85
- declare function withWallets<T extends readonly WalletName[]>(test: typeof test, ...config: NoDuplicates<T>): playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
86
- context: BrowserContext;
87
- backpack: Backpack;
88
- polkadotJS: PolkadotJS;
89
- metamask: Metamask;
90
- }, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
208
+ declare function prepareWallet<TName extends string, TWallet extends IWallet>(walletConfig: WalletConfig<TName, TWallet>, setupFn: SetupFn<TWallet>): CachedWalletConfig<TName, TWallet>;
91
209
 
92
- export { withWallets };
210
+ export { type CachedWalletConfig, type IWallet, Metamask, type Network, type NetworkSettings, PolkadotJS, type SetupFn, type WalletConfig, config, createWallet, debug, isCachedConfig, metamask, polkadotJS, prepareWallet, withWallets };