Skip to content

Commit

Permalink
tmm/fix get address mapping (#3510)
Browse files Browse the repository at this point in the history
* fix: getAddress mapping

* chore: changeset

* chore: remove changeset
  • Loading branch information
tmm authored Jan 24, 2024
1 parent 134eb4a commit 660ff80
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
6 changes: 0 additions & 6 deletions .changeset/funny-owls-perform.md

This file was deleted.

8 changes: 8 additions & 0 deletions .changeset/loud-cooks-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@wagmi/connectors": patch
"@wagmi/core": patch
"create-wagmi": patch
"wagmi": patch
---

Fixed issue where connectors returning multiple addresses didn't checksum correctly.
9 changes: 6 additions & 3 deletions packages/connectors/src/coinbaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function coinbaseWallet(parameters: CoinbaseWalletParameters) {
(await provider.request({
method: 'eth_requestAccounts',
})) as string[]
).map(getAddress)
).map((x) => getAddress(x))

provider.on('accountsChanged', this.onAccountsChanged)
provider.on('chainChanged', this.onChainChanged)
Expand Down Expand Up @@ -105,7 +105,7 @@ export function coinbaseWallet(parameters: CoinbaseWalletParameters) {
await provider.request<string[]>({
method: 'eth_accounts',
})
).map(getAddress)
).map((x) => getAddress(x))
},
async getChainId() {
const provider = await this.getProvider()
Expand Down Expand Up @@ -190,7 +190,10 @@ export function coinbaseWallet(parameters: CoinbaseWalletParameters) {
},
onAccountsChanged(accounts) {
if (accounts.length === 0) config.emitter.emit('disconnect')
else config.emitter.emit('change', { accounts: accounts.map(getAddress) })
else
config.emitter.emit('change', {
accounts: accounts.map((x) => getAddress(x)),
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
Expand Down
13 changes: 9 additions & 4 deletions packages/connectors/src/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
method: 'wallet_requestPermissions',
params: [{ eth_accounts: {} }],
})) as WalletPermission[]
accounts = permissions[0]?.caveats?.[0]?.value?.map(getAddress)
accounts = (permissions[0]?.caveats?.[0]?.value as string[])?.map(
(x) => getAddress(x),
)
} catch (err) {
const error = err as RpcError
// Not all injected providers support `wallet_requestPermissions` (e.g. MetaMask iOS).
Expand All @@ -92,7 +94,7 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
try {
if (!accounts?.length) {
const requestedAccounts = (await sdk.connect()) as string[]
accounts = requestedAccounts.map(getAddress)
accounts = requestedAccounts.map((x) => getAddress(x))
}

provider.removeListener(
Expand Down Expand Up @@ -161,7 +163,7 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
const accounts = (await provider.request({
method: 'eth_accounts',
})) as string[]
return accounts.map(getAddress)
return accounts.map((x) => getAddress(x))
},
async getChainId() {
const provider = await this.getProvider()
Expand Down Expand Up @@ -294,7 +296,10 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
await config.storage?.removeItem('metaMaskSDK.disconnected')
}
// Regular change event
else config.emitter.emit('change', { accounts: accounts.map(getAddress) })
else
config.emitter.emit('change', {
accounts: accounts.map((x) => getAddress(x)),
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
Expand Down
9 changes: 6 additions & 3 deletions packages/connectors/src/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function walletConnect(parameters: WalletConnectParameters) {
}

// If session exists and chains are authorized, enable provider for required chain
const accounts = (await provider.enable()).map(getAddress)
const accounts = (await provider.enable()).map((x) => getAddress(x))
const currentChainId = await this.getChainId()

provider.removeListener('display_uri', this.onDisplayUri)
Expand Down Expand Up @@ -191,7 +191,7 @@ export function walletConnect(parameters: WalletConnectParameters) {
},
async getAccounts() {
const provider = await this.getProvider()
return provider.accounts.map(getAddress)
return provider.accounts.map((x) => getAddress(x))
},
async getProvider({ chainId } = {}) {
async function initProvider() {
Expand Down Expand Up @@ -292,7 +292,10 @@ export function walletConnect(parameters: WalletConnectParameters) {
},
onAccountsChanged(accounts) {
if (accounts.length === 0) this.onDisconnect()
else config.emitter.emit('change', { accounts: accounts.map(getAddress) })
else
config.emitter.emit('change', {
accounts: accounts.map((x) => getAddress(x)),
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/connectors/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export function injected(parameters: InjectedParameters = {}) {
method: 'wallet_requestPermissions',
params: [{ eth_accounts: {} }],
})
accounts = permissions[0]?.caveats?.[0]?.value?.map(getAddress)
accounts = (permissions[0]?.caveats?.[0]?.value as string[])?.map(
(x) => getAddress(x),
)
} catch (err) {
const error = err as RpcError
// Not all injected providers support `wallet_requestPermissions` (e.g. MetaMask iOS).
Expand All @@ -174,7 +176,7 @@ export function injected(parameters: InjectedParameters = {}) {
const requestedAccounts = await provider.request({
method: 'eth_requestAccounts',
})
accounts = requestedAccounts.map(getAddress)
accounts = requestedAccounts.map((x) => getAddress(x))
}

provider.removeListener('connect', this.onConnect.bind(this))
Expand Down Expand Up @@ -233,7 +235,7 @@ export function injected(parameters: InjectedParameters = {}) {
const provider = await this.getProvider()
if (!provider) throw new ProviderNotFoundError()
const accounts = await provider.request({ method: 'eth_accounts' })
return accounts.map(getAddress)
return accounts.map((x) => getAddress(x))
},
async getChainId() {
const provider = await this.getProvider()
Expand Down Expand Up @@ -405,7 +407,10 @@ export function injected(parameters: InjectedParameters = {}) {
await config.storage?.removeItem(`${this.id}.disconnected`)
}
// Regular change event
else config.emitter.emit('change', { accounts: accounts.map(getAddress) })
else
config.emitter.emit('change', {
accounts: accounts.map((x) => getAddress(x)),
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/connectors/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function mock(parameters: MockParameters) {
if (!connected) throw new ConnectorNotConnectedError()
const provider = await this.getProvider()
const accounts = await provider.request({ method: 'eth_accounts' })
return accounts.map(getAddress)
return accounts.map((x) => getAddress(x))
},
async getChainId() {
const provider = await this.getProvider()
Expand All @@ -106,7 +106,10 @@ export function mock(parameters: MockParameters) {
},
onAccountsChanged(accounts) {
if (accounts.length === 0) this.onDisconnect()
else config.emitter.emit('change', { accounts: accounts.map(getAddress) })
else
config.emitter.emit('change', {
accounts: accounts.map((x) => getAddress(x)),
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
Expand Down

0 comments on commit 660ff80

Please sign in to comment.