Skip to content

Commit

Permalink
feat: Add Wallet to installMockWallet
Browse files Browse the repository at this point in the history
Allow for a custom implementation of `Wallet` if default implementation is not sufficient
  • Loading branch information
johanneskares committed Aug 6, 2024
1 parent acd5ca7 commit efac34b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/installMockWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,35 @@ import { randomUUID } from "crypto";
let wallets: Map<string, Wallet> = new Map();

export async function installMockWallet({
account,
transports,
defaultChain,
debug,
...params
}: {
account: LocalAccount;
transports?: Record<number, Transport>;
defaultChain?: Chain;
debug?: boolean;
} & ({ page: Page } | { browserContext: BrowserContext })) {
} & ({ page: Page } | { browserContext: BrowserContext }) &
(
| {
account: LocalAccount;
transports?: Record<number, Transport>;
defaultChain?: Chain;
}
| {
wallet: Wallet;
}
)) {
const browserOrPage =
"browserContext" in params ? params.browserContext : params.page;

const wallet: Wallet =
"wallet" in params
? params.wallet
: createWallet(params.account, params.transports, params.defaultChain);

// Connecting the browser context to the Node.js playwright context
await browserOrPage.exposeFunction("eip1193Request", eip1193Request);

// Everytime we call installMockWallet, we create a new uuid to identify the wallet.
const uuid = randomUUID();
wallets.set(uuid, createWallet(account, transports, defaultChain));
wallets.set(uuid, wallet);

await browserOrPage.addInitScript(
({ uuid, debug }) => {
Expand Down

0 comments on commit efac34b

Please sign in to comment.