Skip to content
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/petite-lizards-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Support fully disconnecting from metamask on disconnect
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
`);
});

it("with owner using indexer", async () => {
// skip until indexer restores owner functionality
it.skip("with owner using indexer", async () => {
const nft = await getNFT({
contract: { ...DOODLES_CONTRACT },
includeOwner: true,
Expand Down
15 changes: 15 additions & 0 deletions packages/thirdweb/src/wallets/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
serializeTypedData,
stringify,
validateTypedData,
withTimeout,
} from "viem";
import { isInsufficientFundsError } from "../../analytics/track/helpers.js";
import {
Expand Down Expand Up @@ -400,6 +401,20 @@ async function onConnect({
provider.removeListener("accountsChanged", onAccountsChanged);
provider.removeListener("chainChanged", onChainChanged);
provider.removeListener("disconnect", onDisconnect);

// Experimental support for MetaMask disconnect
// https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-2.md
try {
// Adding timeout as not all wallets support this method and can hang
await withTimeout(
() =>
provider.request({
method: "wallet_revokePermissions",
params: [{ eth_accounts: {} }],
}),
{ timeout: 100 },
);
} catch {}
}

async function onDisconnect() {
Expand Down
Loading