Skip to content

Commit 304700f

Browse files
committed
Improve Mobile detection in WC connection (#8415)
<!-- ## 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 enhances the `isMobile` function to include viewport detection for mobile devices and refines the QR overlay creation logic for desktop environments by ensuring existing overlays are cleaned up before creating new ones. ### Detailed summary - Added viewport detection in `isMobile` function to return `true` if `window.innerWidth` is less than 640. - Refactored QR overlay creation in `create-wallet.ts` to ensure existing overlays are destroyed before creating a new one. > ✨ 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** * Improved mobile device detection based on viewport size. * Enhanced QR code overlay display with better error handling and resource cleanup. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 6cd681c commit 304700f

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

packages/thirdweb/src/utils/web/isMobile.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function hasMobileAPIs(): boolean {
5757
*/
5858
export function isMobile(): boolean {
5959
// Primary signal: OS detection via user agent
60+
6061
const isMobileOS = isAndroid() || isIOS();
6162

6263
if (isMobileOS) {
@@ -70,5 +71,12 @@ export function isMobile(): boolean {
7071
return true;
7172
}
7273

74+
const isMobileViewport =
75+
typeof window !== "undefined" && window.innerWidth < 640;
76+
77+
if (isMobileViewport) {
78+
return true;
79+
}
80+
7381
return false;
7482
}

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -341,34 +341,35 @@ export function createWallet<const ID extends WalletId>(
341341
}
342342
return;
343343
}
344+
// on desktop, create a QR overlay
345+
else {
346+
try {
347+
const { createQROverlay } = await import(
348+
"./wallet-connect/qr-overlay.js"
349+
);
344350

345-
try {
346-
// on desktop, create a QR overlay
347-
const { createQROverlay } = await import(
348-
"./wallet-connect/qr-overlay.js"
349-
);
351+
// Clean up any existing overlay
352+
if (qrOverlay) {
353+
qrOverlay.destroy();
354+
}
350355

351-
// Clean up any existing overlay
352-
if (qrOverlay) {
353-
qrOverlay.destroy();
356+
// Create new QR overlay
357+
qrOverlay = createQROverlay(uri, {
358+
theme:
359+
wcOptions.walletConnect?.qrModalOptions
360+
?.themeMode ?? "dark",
361+
qrSize: 280,
362+
showCloseButton: true,
363+
onCancel: () => {
364+
wcOptions.walletConnect?.onCancel?.();
365+
},
366+
});
367+
} catch (error) {
368+
console.error(
369+
"Failed to create QR overlay:",
370+
error,
371+
);
354372
}
355-
356-
// Create new QR overlay
357-
qrOverlay = createQROverlay(uri, {
358-
theme:
359-
wcOptions.walletConnect?.qrModalOptions
360-
?.themeMode ?? "dark",
361-
qrSize: 280,
362-
showCloseButton: true,
363-
onCancel: () => {
364-
wcOptions.walletConnect?.onCancel?.();
365-
},
366-
});
367-
} catch (error) {
368-
console.error(
369-
"Failed to create QR overlay:",
370-
error,
371-
);
372373
}
373374
}
374375
}),

0 commit comments

Comments
 (0)