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

Fix: on connect function #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Fix: on connect function #1

wants to merge 2 commits into from

Conversation

EdouardBougon
Copy link
Owner

@EdouardBougon EdouardBougon commented Aug 2, 2024

Issue 1: Async state accounts and connect event
Dessription:
- Why we have a redirect deeplink after we come back to the application
- When the user select its account, during the state initialization, an event "connect" is emit before the accounts are saved in the state
- So when the wagmi connector receive this event, it try to get account (here)
- But in the request function, as the account is not cached or in the state, it will do a regular request (here)
- And finally, in the write function, as eth_accounts is a "method to redirect", it will redirect to metamask (here)

Solution:
- In the function SDKProvider._handleChainChanged test if the account are saved before emiting the 'connect' event. (here)
- If not, do nothing
- At the end of the function initializeStateAsync emit a connect event, not only when cach is enabled (here)
- In the write function, exlude eth_accounts from the redirect (here)
- In the wagmi provider, in onConnect throw an error if not account selected, instead of just return
- We shouldn't have this case anymore
- (The wagmi connect event type require the chainId and the account information)

See metamask sdk PR: MetaMask/metamask-sdk#977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant