Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] useAutoConnect to throw error #5742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kien-ngo
Copy link
Contributor

@kien-ngo kien-ngo commented Dec 14, 2024

Problem solved

Short description of the bug fixed or feature added


PR-Codex overview

This PR focuses on improving error handling in the useAutoConnect hook by ensuring the connection status is set to "disconnected" when an error occurs during the wallet auto-connection process.

Detailed summary

  • Added setConnectionStatus("disconnected"); inside the catch block to handle errors.
  • Removed redundant setConnectionStatus("disconnected"); from the else block.

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

Copy link

vercel bot commented Dec 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2024 10:54am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2024 10:54am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2024 10:54am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2024 10:54am

Copy link

linear bot commented Dec 14, 2024

Copy link

changeset-bot bot commented Dec 14, 2024

⚠️ No Changeset found

Latest commit: 0b6f8de

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

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Dec 14, 2024
Copy link
Contributor Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kien-ngo kien-ngo changed the title update [SDK] useAutoConnect to throw error Dec 14, 2024
@kien-ngo kien-ngo marked this pull request as ready for review December 14, 2024 10:41
Comment on lines +124 to +127
setConnectionStatus("disconnected");
if (e instanceof Error) {
console.warn("Error auto connecting wallet:", e.message);
throw e;
Copy link

Choose a reason for hiding this comment

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

The state update to setConnectionStatus may be interrupted by the subsequent throw. Consider either:

  1. Removing throw e to allow the state to update properly, or
  2. Wrapping the state update in a setTimeout to ensure it completes before the error propagates

The choice depends on whether error propagation or state consistency is more important for this use case.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Member

Choose a reason for hiding this comment

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

def don't want to throw here. autoconnecting can fail for legit reasons (auth token expired, extension locked, etc)

what would be acceptable is to let the user pass an onError callback or return the error like any other mutation/query hook

Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 44.94 KB (0%) 899 ms (0%) 240 ms (+21.65% 🔺) 1.2 s
thirdweb (cjs) 110.78 KB (0%) 2.3 s (0%) 425 ms (+14.37% 🔺) 2.7 s
thirdweb (minimal + tree-shaking) 5.58 KB (0%) 112 ms (0%) 54 ms (+141.47% 🔺) 166 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 9 ms (-25.59% 🔽) 19 ms
thirdweb/react (minimal + tree-shaking) 19.03 KB (0%) 381 ms (0%) 76 ms (+61.06% 🔺) 456 ms

Comment on lines +124 to +127
setConnectionStatus("disconnected");
if (e instanceof Error) {
console.warn("Error auto connecting wallet:", e.message);
throw e;
Copy link
Member

Choose a reason for hiding this comment

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

def don't want to throw here. autoconnecting can fail for legit reasons (auth token expired, extension locked, etc)

what would be acceptable is to let the user pass an onError callback or return the error like any other mutation/query hook

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