Skip to content

Commit dd1141f

Browse files
authored
fix: Do not open wallet uri when connected using official WC modal (#2595)
1 parent 968fdc3 commit dd1141f

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

.changeset/dirty-bears-sort.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+
Do not subscribe to `session_request_sent` event when using `walletConnect` because that is already handled when connecting with official Modal

packages/thirdweb/src/wallets/create-wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export function createWallet<const ID extends WalletId>(
168168
] = await connectWC(
169169
wcOptions,
170170
emitter,
171-
wallet.id as WCSupportedWalletIds,
171+
wallet.id as WCSupportedWalletIds | "walletConnect",
172172
);
173173
// set the states
174174
account = connectedAccount;

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

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const storageKeys = {
6565
export async function connectWC(
6666
options: WCConnectOptions,
6767
emitter: WalletEmitter<WCSupportedWalletIds>,
68-
walletId: WCSupportedWalletIds,
68+
walletId: WCSupportedWalletIds | "walletConnect",
6969
): Promise<ReturnType<typeof onConnect>> {
7070
const provider = await initProvider(options, walletId);
7171

@@ -140,7 +140,7 @@ export async function connectWC(
140140
export async function autoConnectWC(
141141
options: WCAutoConnectOptions,
142142
emitter: WalletEmitter<WCSupportedWalletIds>,
143-
walletId: WCSupportedWalletIds,
143+
walletId: WCSupportedWalletIds | "walletConnect",
144144
): Promise<ReturnType<typeof onConnect>> {
145145
const savedConnectParams: SavedConnectParams | null = asyncLocalStorage
146146
? await getSavedConnectParamsFromStorage(asyncLocalStorage, walletId)
@@ -196,7 +196,7 @@ export async function autoConnectWC(
196196

197197
async function initProvider(
198198
options: WCConnectOptions,
199-
walletId: WCSupportedWalletIds,
199+
walletId: WCSupportedWalletIds | "walletConnect",
200200
isAutoConnect = false,
201201
) {
202202
const walletInfo = await getWalletInfo(walletId);
@@ -257,33 +257,41 @@ async function initProvider(
257257
}
258258
}
259259

260-
function handleSessionRequest() {
261-
if (typeof window === "undefined") {
262-
return;
263-
}
260+
if (walletId !== "walletConnect") {
261+
function handleSessionRequest() {
262+
if (typeof window === "undefined") {
263+
return;
264+
}
264265

265-
if (!isMobile()) {
266-
return;
267-
}
266+
if (!isMobile()) {
267+
return;
268+
}
268269

269-
const preferUniversal =
270-
walletInfo.mobile.universal || walletInfo.mobile.native || "";
271-
const preferNative =
272-
walletInfo.mobile.native || walletInfo.mobile.universal || "";
270+
const preferUniversal =
271+
walletInfo.mobile.universal || walletInfo.mobile.native;
272+
const preferNative =
273+
walletInfo.mobile.native || walletInfo.mobile.universal;
273274

274-
if (isAndroid()) {
275-
openWindow(preferUniversal);
276-
} else if (isIOS()) {
277-
openWindow(preferNative);
278-
} else {
279-
openWindow(preferUniversal);
275+
if (isAndroid()) {
276+
if (preferUniversal) {
277+
openWindow(preferUniversal);
278+
}
279+
} else if (isIOS()) {
280+
if (preferNative) {
281+
openWindow(preferNative);
282+
}
283+
} else {
284+
if (preferUniversal) {
285+
openWindow(preferUniversal);
286+
}
287+
}
280288
}
281-
}
282289

283-
provider.signer.client.on("session_request_sent", handleSessionRequest);
284-
provider.events.addListener("disconnect", () => {
285-
provider.signer.client.off("session_request_sent", handleSessionRequest);
286-
});
290+
provider.signer.client.on("session_request_sent", handleSessionRequest);
291+
provider.events.addListener("disconnect", () => {
292+
provider.signer.client.off("session_request_sent", handleSessionRequest);
293+
});
294+
}
287295

288296
// try switching to correct chain
289297
if (options?.chain && provider.chainId !== options?.chain.id) {

0 commit comments

Comments
 (0)