Skip to content

Commit c08fb13

Browse files
committed
SDK: Fix Safe wallet connection issues with WalletConnect (#8327)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed Safe wallet connection issues with WalletConnect <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 68cca6f commit c08fb13

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/early-spoons-say.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+
Fix Safe wallet connection issues with WalletConnect

packages/thirdweb/src/wallets/wallet-connect/controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export async function connectWC(
157157
);
158158
const currentChainId = chainsToRequest[0]?.split(":")[1] || 1;
159159
const providerChainId = normalizeChainId(currentChainId);
160-
const account = firstAccountOn(provider.session, `eip155:1`); // grab the address from mainnet
160+
const account = firstAccountOn(provider.session, `eip155:1`); // grab the address from mainnet if available
161161
const address = account;
162162
if (!address) {
163163
throw new Error("No accounts found on provider.");
@@ -291,7 +291,8 @@ function hasChainEnabled(session: WCSession, caip: string) {
291291
}
292292
function firstAccountOn(session: WCSession, caip: string): string | null {
293293
const ns = getNS(session);
294-
const hit = ns?.accounts?.find((a) => a.startsWith(`${caip}:`));
294+
const hit =
295+
ns?.accounts?.find((a) => a.startsWith(`${caip}:`)) || ns?.accounts[0];
295296
return hit ? (hit.split(":")[2] ?? null) : null;
296297
}
297298
function anyRoutableChain(session: WCSession): string | null {

0 commit comments

Comments
 (0)