From c08fb1356e77be9eeb0569905fcb2ab76a516dc3 Mon Sep 17 00:00:00 2001 From: MananTank Date: Tue, 28 Oct 2025 17:19:37 +0000 Subject: [PATCH] SDK: Fix Safe wallet connection issues with WalletConnect (#8327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR addresses issues with the Safe wallet connection when using `WalletConnect`, ensuring better handling of account retrieval. ### Detailed summary - Updated the comment for `account` retrieval to clarify that it grabs the address from mainnet if available. - Modified the `firstAccountOn` function to return the first account from the session if no matching account is found. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit * **Bug Fixes** * Fixed Safe wallet connection issues with WalletConnect --- .changeset/early-spoons-say.md | 5 +++++ packages/thirdweb/src/wallets/wallet-connect/controller.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/early-spoons-say.md diff --git a/.changeset/early-spoons-say.md b/.changeset/early-spoons-say.md new file mode 100644 index 00000000000..6a973edbe24 --- /dev/null +++ b/.changeset/early-spoons-say.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Fix Safe wallet connection issues with WalletConnect diff --git a/packages/thirdweb/src/wallets/wallet-connect/controller.ts b/packages/thirdweb/src/wallets/wallet-connect/controller.ts index c685e091ba2..6ae873d692f 100644 --- a/packages/thirdweb/src/wallets/wallet-connect/controller.ts +++ b/packages/thirdweb/src/wallets/wallet-connect/controller.ts @@ -157,7 +157,7 @@ export async function connectWC( ); const currentChainId = chainsToRequest[0]?.split(":")[1] || 1; const providerChainId = normalizeChainId(currentChainId); - const account = firstAccountOn(provider.session, `eip155:1`); // grab the address from mainnet + const account = firstAccountOn(provider.session, `eip155:1`); // grab the address from mainnet if available const address = account; if (!address) { throw new Error("No accounts found on provider."); @@ -291,7 +291,8 @@ function hasChainEnabled(session: WCSession, caip: string) { } function firstAccountOn(session: WCSession, caip: string): string | null { const ns = getNS(session); - const hit = ns?.accounts?.find((a) => a.startsWith(`${caip}:`)); + const hit = + ns?.accounts?.find((a) => a.startsWith(`${caip}:`)) || ns?.accounts[0]; return hit ? (hit.split(":")[2] ?? null) : null; } function anyRoutableChain(session: WCSession): string | null {