Skip to content

Conversation

@MananTank
Copy link
Member

@MananTank MananTank commented Nov 14, 2025


PR-Codex overview

This PR enhances the isMobile detection logic and refines the QR overlay creation process in the wallet functionality. It adds viewport checks for mobile devices and improves error handling when creating QR overlays.

Detailed summary

  • In isMobile.ts, added a check for mobile viewport size (less than 640px).
  • In create-wallet.ts, refined the QR overlay creation logic:
    • Added cleanup of existing overlays before creating a new one.
    • Improved error handling with console logging for overlay creation failures.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes

    • Improved mobile detection by also checking viewport width to more reliably identify mobile contexts.
  • New Features

    • Introduced a desktop-specific QR overlay workflow for WalletConnect with explicit cleanup and improved error handling for a more reliable connection experience.

@vercel
Copy link

vercel bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs-v2 Ready Ready Preview Comment Nov 14, 2025 4:18pm
nebula Ready Ready Preview Comment Nov 14, 2025 4:18pm
thirdweb_playground Ready Ready Preview Comment Nov 14, 2025 4:18pm
thirdweb-www Ready Ready Preview Comment Nov 14, 2025 4:18pm
wallet-ui Ready Ready Preview Comment Nov 14, 2025 4:18pm

@changeset-bot
Copy link

changeset-bot bot commented Nov 14, 2025

⚠️ No Changeset found

Latest commit: 304700f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

isMobile adds a viewport-width heuristic (window.innerWidth < 640). WalletConnect QR overlay gets a desktop-specific flow: dynamic import of overlay module, cleanup of any existing overlay, configurable overlay creation, and error handling.

Changes

Cohort / File(s) Summary
Mobile detection
packages/thirdweb/src/utils/web/isMobile.ts
Added a viewport-width check (window.innerWidth < 640) as an additional heuristic for classifying mobile contexts; existing OS and touch/API checks remain.
WalletConnect QR overlay (desktop flow)
packages/thirdweb/src/wallets/create-wallet.ts
Introduced a desktop-specific QR overlay workflow: dynamic import of the overlay module, explicit cleanup of any existing overlay before creation, configurable overlay options (theme/size/cancel), and try/catch error handling around import/creation.

Sequence Diagram(s)

sequenceDiagram
  participant App as App / WalletConnect flow
  participant Env as Runtime (browser)
  participant OverlayModule as QR Overlay Module (dynamic)
  rect rgba(0,128,0,0.06)
    Note right of App: Desktop QR overlay path (new)
  end
  App->>Env: detect isMobile()
  alt isMobile === false (desktop)
    App->>Env: dynamic import OverlayModule
    activate OverlayModule
    OverlayModule-->>App: overlay factory
    App->>OverlayModule: remove existing overlay (if any)
    App->>OverlayModule: create overlay with {theme,size,onCancel}
    OverlayModule-->>App: overlay instance / success
  else isMobile === true (mobile)
    Note right of App: use existing mobile flow (no desktop overlay)
  end
  par Error handling
    OverlayModule--xApp: import/creation error
    App->>App: handle error / fallback
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Files needing extra attention:
    • packages/thirdweb/src/wallets/create-wallet.ts: verify dynamic import error paths, ensure overlay cleanup is robust (no leaks, idempotent), and confirm cancel handling propagates correctly.
    • packages/thirdweb/src/utils/web/isMobile.ts: confirm viewport threshold and detection order to avoid misclassifying larger tablets or small-desktop windows.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes PR-Codex summary with detailed changes but lacks the required template format: missing title format '[SDK/Dashboard/Portal] Feature/Fix:', Linear issue tag (TEAM-0000), explicit 'Notes for the reviewer' section, and 'How to test' section. Reformat description to follow template: add '[SDK] Fix:' prefix to title, include Linear issue tag, add 'Notes for the reviewer' and 'How to test' sections with specific testing instructions.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main objective: improving mobile detection in WalletConnect connection flow by adding viewport-based detection checks.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 11-14-improve_mobile_detection_in_wc_connection

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 14, 2025

size-limit report 📦

Path Size
@thirdweb-dev/nexus (esm) 104.88 KB (0%)
@thirdweb-dev/nexus (cjs) 316.6 KB (0%)

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 7.14286% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.85%. Comparing base (6cd681c) to head (304700f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/thirdweb/src/wallets/create-wallet.ts 0.00% 23 Missing ⚠️
packages/thirdweb/src/utils/web/isMobile.ts 40.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8415   +/-   ##
=======================================
  Coverage   54.84%   54.85%           
=======================================
  Files         919      919           
  Lines       60846    60853    +7     
  Branches     4141     4142    +1     
=======================================
+ Hits        33372    33378    +6     
- Misses      27372    27373    +1     
  Partials      102      102           
Flag Coverage Δ
packages 54.85% <7.14%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
packages/thirdweb/src/utils/web/isMobile.ts 62.50% <40.00%> (-2.62%) ⬇️
packages/thirdweb/src/wallets/create-wallet.ts 23.07% <0.00%> (-0.15%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 14, 2025

Merge activity

<!--

## 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 -->
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/thirdweb/src/utils/web/isMobile.ts (1)

58-81: Viewport-based fallback broadens “mobile” to narrow desktop windows; consider scope and add tests

The new isMobileViewport fallback runs only after OS and touch/mobile-API checks, so the primary new cases that become “mobile” are environments where:

  • OS is not Android/iOS,
  • no touch/mobile APIs are detected, but
  • window.innerWidth < 640.

That effectively treats narrow desktop browser windows as mobile. If that’s intentional (for WalletConnect UX, responsive layouts, etc.), it’s fine, but it does change semantics for every existing isMobile() caller (including the session handler and WC flows in create-wallet.ts). Please double-check that all current usages are okay with “narrow viewport” being equivalent to mobile, or consider constraining this heuristic to the specific call sites that need it (or gating it behind an option).

Also, the new viewport branch isn’t covered by tests (per codecov). It would be good to add unit tests that stub window.innerWidth around edge values (e.g. 639/640) to lock in the intended behavior.

packages/thirdweb/src/wallets/create-wallet.ts (1)

352-371: QR overlay lifecycle is well-handled; consider adding tests for overlay creation/cleanup

The QR overlay management is carefully done:

  • Destroys any existing qrOverlay before creating a new one to avoid stacking overlays.
  • Cleans up the overlay in both the success path (lines 384–388) and error path (lines 403–407).
  • onCancel delegates to any user-provided walletConnect.onCancel, preserving existing hooks.
  • Dynamic import of createQROverlay is scoped to the desktop branch and wrapped in a try/catch, so failures degrade gracefully.

Given the new logic is not covered by tests (per codecov), it would be ideal to add tests that simulate onDisplayUri being called on desktop and verify that:

  • createQROverlay is invoked with the expected options (theme, size, onCancel).
  • destroy() is called on successful connect and on error.

You can mock ./wallet-connect/qr-overlay.js and connectWC to exercise these branches without relying on real DOM or WalletConnect behavior.

Also applies to: 384-407

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8a83711 and 304700f.

📒 Files selected for processing (2)
  • packages/thirdweb/src/utils/web/isMobile.ts (2 hunks)
  • packages/thirdweb/src/wallets/create-wallet.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: MananTank
Repo: thirdweb-dev/js PR: 8106
File: packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx:482-485
Timestamp: 2025-09-23T19:56:43.668Z
Learning: In packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx, the EmbedContainer uses width: "100vw" intentionally rather than "100%" - this is by design for the bridge widget embedding use case.
🧬 Code graph analysis (1)
packages/thirdweb/src/wallets/create-wallet.ts (1)
packages/thirdweb/src/wallets/wallet-connect/qr-overlay.ts (1)
  • createQROverlay (59-296)
🪛 GitHub Check: codecov/patch
packages/thirdweb/src/wallets/create-wallet.ts

[warning] 345-349: packages/thirdweb/src/wallets/create-wallet.ts#L345-L349
Added lines #L345 - L349 were not covered by tests


[warning] 352-354: packages/thirdweb/src/wallets/create-wallet.ts#L352-L354
Added lines #L352 - L354 were not covered by tests


[warning] 357-371: packages/thirdweb/src/wallets/create-wallet.ts#L357-L371
Added lines #L357 - L371 were not covered by tests

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

[warning] 78-79: packages/thirdweb/src/utils/web/isMobile.ts#L78-L79
Added lines #L78 - L79 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/thirdweb/src/wallets/create-wallet.ts (1)

321-373: Remove concern about sessionHandler vs onDisplayUri conflict; only viewport-based UX change warrants attention

The core concern in the original review is incorrect. When create-wallet.ts provides a custom onDisplayUri callback (which it does), connectWC completely bypasses the fallback sessionHandler for URI display. The logic is:

At connectWC line 94: if (!onDisplayUri && sessionHandler) — since onDisplayUri is provided by create-wallet.ts, this condition is false and the deeplinkHandler wrapper is never used. The custom callback has full control; sessionHandler is only used for session initialization/recovery, not for URI handling. No conflict or duplicate handling occurs.

The only valid observation from the original review is that isMobile() now includes a viewport-width heuristic, so narrow desktop windows will show the mobile deeplink UI instead of QR. That's an intentional UX shift worth confirming, but not a correctness issue.

Likely an incorrect or invalid review comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants