Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue 1: Async state accounts and
connect
eventDessription:
- 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 aconnect
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