Skip to content

Commit

Permalink
fix: #4140
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jul 15, 2024
1 parent 9505402 commit b08013e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-adults-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/core": patch
---

Fixed injected accounts ordering for `'wallet_requestPermissions'`.
7 changes: 7 additions & 0 deletions packages/core/src/connectors/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ export function injected(parameters: InjectedParameters = {}) {
accounts = (permissions[0]?.caveats?.[0]?.value as string[])?.map(
(x) => getAddress(x),
)
// `'wallet_requestPermissions'` can return a different order of accounts than `'eth_accounts'`
// switch to `'eth_accounts'` ordering if more than one account is connected
// https://github.com/wevm/wagmi/issues/4140
if (accounts.length > 0) {
const sortedAccounts = await this.getAccounts()
accounts = sortedAccounts
}
} catch (err) {
const error = err as RpcError
// Not all injected providers support `wallet_requestPermissions` (e.g. MetaMask iOS).
Expand Down

0 comments on commit b08013e

Please sign in to comment.