66 serializeTypedData ,
77 stringify ,
88 validateTypedData ,
9+ withTimeout ,
910} from "viem" ;
1011import { isInsufficientFundsError } from "../../analytics/track/helpers.js" ;
1112import {
@@ -110,7 +111,7 @@ export async function connectEip1193Wallet({
110111 }
111112 } catch {
112113 console . warn (
113- `Error switching to chain ${ chain ?. id } - defaulting to wallet chain (${ chainId } )` ,
114+ `Error switching to chain ${ chain ?. id } - defaulting to wallet chain (${ chainId } )`
114115 ) ;
115116 }
116117
@@ -309,15 +310,15 @@ function createAccount({
309310 method : "wallet_watchAsset" ,
310311 params : asset ,
311312 } ,
312- { retryCount : 0 } ,
313+ { retryCount : 0 }
313314 ) ;
314315 return result ;
315316 } ,
316317 async sendCalls ( options ) {
317318 try {
318319 const { callParams, chain } = await toProviderCallParams (
319320 options ,
320- account ,
321+ account
321322 ) ;
322323 const callId = await provider . request ( {
323324 method : "wallet_sendCalls" ,
@@ -330,7 +331,7 @@ function createAccount({
330331 } catch ( error ) {
331332 if ( / u n s u p p o r t | n o t s u p p o r t / i. test ( ( error as Error ) . message ) ) {
332333 throw new Error (
333- `${ id } errored calling wallet_sendCalls, with error: ${ error instanceof Error ? error . message : stringify ( error ) } ` ,
334+ `${ id } errored calling wallet_sendCalls, with error: ${ error instanceof Error ? error . message : stringify ( error ) } `
334335 ) ;
335336 }
336337 throw error ;
@@ -346,7 +347,7 @@ function createAccount({
346347 } catch ( error ) {
347348 if ( / u n s u p p o r t | n o t s u p p o r t / i. test ( ( error as Error ) . message ) ) {
348349 throw new Error (
349- `${ id } does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.` ,
350+ `${ id } does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`
350351 ) ;
351352 }
352353 throw error ;
@@ -400,6 +401,20 @@ async function onConnect({
400401 provider . removeListener ( "accountsChanged" , onAccountsChanged ) ;
401402 provider . removeListener ( "chainChanged" , onChainChanged ) ;
402403 provider . removeListener ( "disconnect" , onDisconnect ) ;
404+
405+ // Experimental support for MetaMask disconnect
406+ // https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-2.md
407+ try {
408+ // Adding timeout as not all wallets support this method and can hang
409+ await withTimeout (
410+ ( ) =>
411+ provider . request ( {
412+ method : "wallet_revokePermissions" ,
413+ params : [ { eth_accounts : { } } ] ,
414+ } ) ,
415+ { timeout : 100 }
416+ ) ;
417+ } catch { }
403418 }
404419
405420 async function onDisconnect ( ) {
0 commit comments