diff --git a/.changeset/neat-cups-rhyme.md b/.changeset/neat-cups-rhyme.md new file mode 100644 index 0000000000..dc845ab979 --- /dev/null +++ b/.changeset/neat-cups-rhyme.md @@ -0,0 +1,5 @@ +--- +"@wagmi/core": patch +--- + +Added timeout to internal call of `'wallet_revokePermissions'` request during `injected#disconnect` as some wallets that do not support this method hang. diff --git a/packages/core/src/connectors/injected.ts b/packages/core/src/connectors/injected.ts index 897bda6cd9..ab08033a22 100644 --- a/packages/core/src/connectors/injected.ts +++ b/packages/core/src/connectors/injected.ts @@ -11,6 +11,7 @@ import { getAddress, numberToHex, withRetry, + withTimeout, } from 'viem' import type { Connector } from '../createConfig.js' @@ -267,16 +268,22 @@ export function injected(parameters: InjectedParameters = {}) { // Experimental support for MetaMask disconnect // https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-2.md try { - // TODO: Remove explicit type for viem@3 - await provider.request<{ - Method: 'wallet_revokePermissions' - Parameters: [permissions: { eth_accounts: Record }] - ReturnType: null - }>({ - // `'wallet_revokePermissions'` added in `viem@2.10.3` - method: 'wallet_revokePermissions', - params: [{ eth_accounts: {} }], - }) + // Adding timeout as not all wallets support this method and can hang + // https://github.com/wevm/wagmi/issues/4064 + await withTimeout( + () => + // TODO: Remove explicit type for viem@3 + provider.request<{ + Method: 'wallet_revokePermissions' + Parameters: [permissions: { eth_accounts: Record }] + ReturnType: null + }>({ + // `'wallet_revokePermissions'` added in `viem@2.10.3` + method: 'wallet_revokePermissions', + params: [{ eth_accounts: {} }], + }), + { timeout: 100 }, + ) } catch {} // Add shim signalling connector is disconnected