Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withTimeout for wallet_revokePermissions request during disconnect #4065

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-cups-rhyme.md
Original file line number Diff line number Diff line change
@@ -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.
27 changes: 17 additions & 10 deletions packages/core/src/connectors/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getAddress,
numberToHex,
withRetry,
withTimeout,
} from 'viem'

import type { Connector } from '../createConfig.js'
Expand Down Expand Up @@ -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<string, any> }]
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<string, any> }]
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
Expand Down
Loading