Skip to content

Commit efac34b

Browse files
committed
feat: Add Wallet to installMockWallet
Allow for a custom implementation of `Wallet` if default implementation is not sufficient
1 parent acd5ca7 commit efac34b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/installMockWallet.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,35 @@ import { randomUUID } from "crypto";
66
let wallets: Map<string, Wallet> = new Map();
77

88
export async function installMockWallet({
9-
account,
10-
transports,
11-
defaultChain,
129
debug,
1310
...params
1411
}: {
15-
account: LocalAccount;
16-
transports?: Record<number, Transport>;
17-
defaultChain?: Chain;
1812
debug?: boolean;
19-
} & ({ page: Page } | { browserContext: BrowserContext })) {
13+
} & ({ page: Page } | { browserContext: BrowserContext }) &
14+
(
15+
| {
16+
account: LocalAccount;
17+
transports?: Record<number, Transport>;
18+
defaultChain?: Chain;
19+
}
20+
| {
21+
wallet: Wallet;
22+
}
23+
)) {
2024
const browserOrPage =
2125
"browserContext" in params ? params.browserContext : params.page;
2226

27+
const wallet: Wallet =
28+
"wallet" in params
29+
? params.wallet
30+
: createWallet(params.account, params.transports, params.defaultChain);
31+
2332
// Connecting the browser context to the Node.js playwright context
2433
await browserOrPage.exposeFunction("eip1193Request", eip1193Request);
2534

2635
// Everytime we call installMockWallet, we create a new uuid to identify the wallet.
2736
const uuid = randomUUID();
28-
wallets.set(uuid, createWallet(account, transports, defaultChain));
37+
wallets.set(uuid, wallet);
2938

3039
await browserOrPage.addInitScript(
3140
({ uuid, debug }) => {

0 commit comments

Comments
 (0)