Skip to content

Commit

Permalink
fix: getConnectorClient account comparison (#3763)
Browse files Browse the repository at this point in the history
* fix: compare checksummed addresses in getConnectorClient

* chore: up

* chore: changeset

---------

Co-authored-by: Razvan Gabriel <razvan.gabriel.apostu@gmail.com>
  • Loading branch information
tmm and razgraf authored Mar 27, 2024
1 parent dbd6446 commit a59069e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-owls-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/core": patch
---

Fixed `getConnectorClient` internal address comparison.
13 changes: 12 additions & 1 deletion packages/core/src/actions/getConnectorClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ test('parameters: connector', async () => {

test.todo('custom connector client')

test('behavior: account address is checksummed', async () => {
await connect(config, { connector })
const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
const client = await getConnectorClient(config, { account })
expect(client.account.address).toMatchInlineSnapshot(
'"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"',
)
expect(client.account.address).not.toBe(account)
await disconnect(config, { connector })
})

test('behavior: not connected', async () => {
await expect(
getConnectorClient(config),
Expand All @@ -39,7 +50,7 @@ test('behavior: account does not exist on connector', async () => {
await expect(
getConnectorClient(config, { account: address.usdcHolder }),
).rejects.toThrowErrorMatchingInlineSnapshot(`
"Account \\"0x5414d89a8bf7e99d732bc52f3e6a3ef461c0c078\\" not found for connector \\"Mock Connector\\".
"Account \\"0x5414d89a8bF7E99d732BC52f3e6A3Ef461c0C078\\" not found for connector \\"Mock Connector\\".
Version: @wagmi/core@x.y.z"
`)
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/actions/getConnectorClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
createClient,
custom,
} from 'viem'
import { getAddress, parseAccount } from 'viem/utils'

import { parseAccount } from 'viem/utils'
import type { Config, Connection } from '../createConfig.js'
import type { ErrorType } from '../errors/base.js'
import {
Expand Down Expand Up @@ -84,6 +84,8 @@ export async function getConnectorClient<

// Default using `custom` transport
const account = parseAccount(parameters.account ?? connection.accounts[0]!)
account.address = getAddress(account.address) // TODO: Checksum address as part of `parseAccount`?

const chain = config.chains.find((chain) => chain.id === chainId)
const provider = (await connection.connector.getProvider({ chainId })) as {
request(...args: any): Promise<any>
Expand Down

0 comments on commit a59069e

Please sign in to comment.