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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
update
  • Loading branch information
kien-ngo committed Dec 14, 2024
commit 0b6f8de551922ed468fae77f4271c0ba7ff859ac
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ export function useAutoConnectCore(
setConnectionStatus("disconnected");
}
} catch (e) {
setConnectionStatus("disconnected");
if (e instanceof Error) {
console.warn("Error auto connecting wallet:", e.message);
throw e;
Comment on lines +124 to +127
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

}
setConnectionStatus("disconnected");
}
} else {
setConnectionStatus("disconnected");
Expand Down
Loading