-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix: Proposal to repair refresh/reconnect problem #3165
Conversation
🦋 Changeset detectedLatest commit: 7b12275 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@richtera is attempting to deploy a commit to the wagmi Team on Vercel. A member of the Team first needs to authorize it. |
cb2b1e7
to
d9e57d4
Compare
3458dd0
to
e34d52c
Compare
f3df26d
to
7e60b5e
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
if (!isReconnecting) { | ||
accounts = await this.getAccounts().catch(() => null) | ||
let accounts: readonly Address[] = [] | ||
if (isReconnecting) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the actual change is. !isReconnecting
to isReconnecting
. The rest of the typescript specific type related stuff was to get lint a d build to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored so only the necessary changes are in the PR. This line is really the only line which needs changing.
5db6835
to
7b12275
Compare
I removed all of the typescript changes, my local biome config was a little bit different than yours so that it required more changes. |
Maybe to provide context.
For context, I created the ethereum provider object back in 2016, as well as worked on web3.js, which lead to your library. Maybe this gives more relevance ot this change request that we need. @jxom @tmm |
Basically during a reconnect we don't want this to happen
We do want this to happen as the comment already is indicating
Therefore I believe the condition on this line was in error since it was running when isReconnecting was false.
|
@jxom @tmm I just tried to inject the provider with normal EIP 6963 messaging and the same problem persists. I really think the issue is with this "if" statement. Have you been able to look at it any further. I would rather not change our wallet to not respond to eth_requestAccounts without showing a dialog to the user. This would make it a lot harder to be able to change accounts and there is already eth_accounts which does the job and in fact is already being called inside of the "if" clause in question. I am not quite sure how to proceed. It seems clear that the condition should be reversed unless there is something else going on I am not aware of. async connect({ chainId, isReconnecting } = {}) {
.
.
.
let accounts: readonly Address[] | null = null
/**
* This section of the code really only makes sense for isReconnecting and not for !isReconnecting
* because if the user is not reconnecting then this.getAccounts() will be empty for sure.
*/
if (!isReconnecting) {
accounts = await this.getAccounts().catch(() => null)
// Attempt to show another prompt for selecting account if already connected and `shimDisconnect` flag is enabled
const isAuthorized = shimDisconnect && !!accounts?.length
if (isAuthorized)
try {
const permissions = await provider.request({
method: 'wallet_requestPermissions',
params: [{ eth_accounts: {} }],
})
accounts = (permissions[0]?.caveats?.[0]?.value as string[])?.map(
(x) => getAddress(x),
)
} catch (err) {
const error = err as RpcError
// Not all injected providers support `wallet_requestPermissions` (e.g. MetaMask iOS).
// Only bubble up error if user rejects request
if (error.code === UserRejectedRequestError.code)
throw new UserRejectedRequestError(error)
// Or prompt is already open
if (error.code === ResourceUnavailableRpcError.code) throw error
}
}
.
.
.
}, |
Sorry about the late response here. I have opened a new PR up at #3779 to address this issue. Let me know what you think! |
Description
When refreshing the page or tag the code runs autoConnect. Currently the providers are not being passed the desired chainId
and address making it not possible for the provider to check whether they are already connected and not prompting the user.
Adding these two fields during the "reconnecting" state and then implementing the code in the injected provider to check
if it's connected to the correct thing.
Additional Information
Your ENS/address:
A lot of these changes are stale since they are in files which have been deleted.