@@ -137,10 +137,6 @@ function main() {
137137
138138 const transport = viem . custom ( provider ) ;
139139
140- if ( baseProvider instanceof EthereumProvider ) {
141- await baseProvider . connect ( ) ;
142- }
143-
144140 const blockchain : TestChain = {
145141 provider,
146142 wallet : viem . createWalletClient ( {
@@ -196,6 +192,20 @@ function main() {
196192 glue = new ManualGlue ( glueElem , unboundWallet ) ;
197193 }
198194
195+ let requestAccountsPromise : unknown = null ;
196+ const unsubscribe = glue . on ( "requestaccounts" , ( event ) => {
197+ unsubscribe ( ) ;
198+ requestAccountsPromise = glue . requestAccounts ( {
199+ action : "approve" ,
200+ id : event . id ,
201+ accounts : [ event . accounts [ 0 ] ] ,
202+ } ) ;
203+ } ) ;
204+
205+ if ( baseProvider instanceof EthereumProvider ) {
206+ await baseProvider . connect ( ) ;
207+ }
208+
199209 const wsUrl = new URL ( `./${ uuid } ` , window . location . href ) ;
200210 wsUrl . protocol = wsUrl . protocol == "http:" ? "ws:" : "wss:" ;
201211 wsUrl . hash = "" ;
@@ -299,16 +309,6 @@ function main() {
299309 const open = spawn ( async ( ) => {
300310 webSocket ?. removeEventListener ( "open" , open ) ;
301311
302- let requestAccountsPromise : unknown = null ;
303- const unsubscribe = glue . on ( "requestaccounts" , ( event ) => {
304- unsubscribe ( ) ;
305- requestAccountsPromise = glue . requestAccounts ( {
306- action : "approve" ,
307- id : event . id ,
308- accounts : [ event . accounts [ 0 ] ] ,
309- } ) ;
310- } ) ;
311-
312312 await glue . activateChain ( {
313313 chainId : "0x" + chainId . toString ( 16 ) ,
314314 rpcUrl : rpcUrl . href ,
0 commit comments