diff --git a/client/src/index.ts b/client/src/index.ts index 37bb951..51e9d20 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -137,10 +137,6 @@ function main() { const transport = viem.custom(provider); - if (baseProvider instanceof EthereumProvider) { - await baseProvider.connect(); - } - const blockchain: TestChain = { provider, wallet: viem.createWalletClient({ @@ -196,6 +192,20 @@ function main() { glue = new ManualGlue(glueElem, unboundWallet); } + let requestAccountsPromise: unknown = null; + const unsubscribe = glue.on("requestaccounts", (event) => { + unsubscribe(); + requestAccountsPromise = glue.requestAccounts({ + action: "approve", + id: event.id, + accounts: [event.accounts[0]], + }); + }); + + if (baseProvider instanceof EthereumProvider) { + await baseProvider.connect(); + } + const wsUrl = new URL(`./${uuid}`, window.location.href); wsUrl.protocol = wsUrl.protocol == "http:" ? "ws:" : "wss:"; wsUrl.hash = ""; @@ -299,16 +309,6 @@ function main() { const open = spawn(async () => { webSocket?.removeEventListener("open", open); - let requestAccountsPromise: unknown = null; - const unsubscribe = glue.on("requestaccounts", (event) => { - unsubscribe(); - requestAccountsPromise = glue.requestAccounts({ - action: "approve", - id: event.id, - accounts: [event.accounts[0]], - }); - }); - await glue.activateChain({ chainId: "0x" + chainId.toString(16), rpcUrl: rpcUrl.href,