You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I checked there isn't already an issue for the bug I encountered.
Describe the bug
Hello! Here is a bug was discovered I want to bring here as an issue with a proposed solution.
If you set shimDisconnect flag as true while creating injected() connector and try to connect multiple accounts from Metamask to your dapp it will get the list of the accounts from wallet_requestPermissions response
The difference is that eth_requestAccounts returns an array where an item on the first position is the currently selected account in your wallet, independently to how addresses are sorted in the wallet. In other hand, wallet_requestPermissions returns the accounts list sorted in the same way as it displayed in your account selection dialog. So it leads to a bug that appears when you select 2+ accounts during connect, and your current account is any of them but first from the list. The wagmi state receives the first account from the list as current account which is not valid. Then if you refresh the page and if you have the reconnect option enabled wagmi will gather accounts in the right way with eth_requestAccounts, because wallet_requestPermissions is being called only at manual the connect phase.
My suggestion here is to make extra eth_requestAccounts request after wallet_requestPermissions to gather an accounts list because it seems like that the permissions list was not meant to be sorted in the same way by the wallet side.
Create a few accounts in your wallet that can be connected with injected connector, I do use Metamask.
Setup wagmi with injected connector and enable shimDisconnect option for it.
Set your current account in the wallet to any but first from the list.
Try to connect the wallet to the dapp, check 2 or more accounts from the list, there is must be at least one account permission checked above the currently selected account.
Check the current account at the wagmi state, using useAccount for example, it should display an account that was first on the permission list, not the actual current account from your wallet.
Refresh the page, and after reconnection the account will be actual now.
What Wagmi package(s) are you using?
@wagmi/connectors, @wagmi/core
Wagmi Package(s) Version(s)
latest
Viem Version
latest
TypeScript Version
5.4.5
Anything else?
Framework is React
Metamask version: 11.16.14
The text was updated successfully, but these errors were encountered:
This issue has been locked since it has been closed for more than 14 days.
If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Wagmi version. If you have any questions or comments you can create a new discussion thread.
Check existing issues
Describe the bug
Hello! Here is a bug was discovered I want to bring here as an issue with a proposed solution.
If you set
shimDisconnect
flag astrue
while creatinginjected()
connector and try to connect multiple accounts from Metamask to your dapp it will get the list of the accounts fromwallet_requestPermissions
responsewagmi/packages/core/src/connectors/injected.ts
Lines 177 to 182 in 9049366
But the list from this response is not sorted in the same way as it is sorted when you get it from
eth_requestAccounts
wagmi/packages/core/src/connectors/injected.ts
Lines 197 to 200 in 9049366
The difference is that
eth_requestAccounts
returns an array where an item on the first position is the currently selected account in your wallet, independently to how addresses are sorted in the wallet. In other hand,wallet_requestPermissions
returns the accounts list sorted in the same way as it displayed in your account selection dialog. So it leads to a bug that appears when you select 2+ accounts during connect, and your current account is any of them but first from the list. The wagmi state receives the first account from the list as current account which is not valid. Then if you refresh the page and if you have the reconnect option enabled wagmi will gather accounts in the right way witheth_requestAccounts
, becausewallet_requestPermissions
is being called only at manual the connect phase.My suggestion here is to make extra
eth_requestAccounts
request afterwallet_requestPermissions
to gather an accounts list because it seems like that the permissions list was not meant to be sorted in the same way by the wallet side.Link to Minimal Reproducible Example
https://stackblitz.com/edit/new-wagmi-kq3bh1?file=src%2Fwagmi.ts
Steps To Reproduce
injected
connector, I do use Metamask.injected
connector and enableshimDisconnect
option for it.useAccount
for example, it should display an account that was first on the permission list, not the actual current account from your wallet.What Wagmi package(s) are you using?
@wagmi/connectors, @wagmi/core
Wagmi Package(s) Version(s)
latest
Viem Version
latest
TypeScript Version
5.4.5
Anything else?
Framework is React
Metamask version: 11.16.14
The text was updated successfully, but these errors were encountered: