Skip to content

Commit efabd3b

Browse files
committed
Update handler of chainId within eth_chainId
1 parent 5690fcc commit efabd3b

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

packages/coinbase/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/coinbase",
3-
"version": "2.3.0-alpha.3",
3+
"version": "2.3.0-alpha.4",
44
"description": "Coinbase SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",

packages/coinbase/src/index.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type {
2-
EIP1193Provider,
3-
WalletInit,
4-
WalletInterface
1+
import {
2+
createEIP1193Provider,
3+
fromHex,
4+
type WalletInit,
5+
type WalletInterface
56
} from '@web3-onboard/common'
67

78
function coinbaseWallet({
@@ -27,9 +28,9 @@ function coinbaseWallet({
2728
chains,
2829
appMetadata
2930
}): Promise<WalletInterface> => {
30-
if (enableMobileWalletLink || reloadOnDisconnect) {
31+
if (enableMobileWalletLink || reloadOnDisconnect || darkMode) {
3132
console.warn(
32-
'enableMobileWalletLink and reloadOnDisconnect are deprecated after version 2.2.7 of @web3-onboard/coinbase'
33+
'darkMode, enableMobileWalletLink and reloadOnDisconnect init props are deprecated after version 2.2.7 of @web3-onboard/coinbase'
3334
)
3435
}
3536
const { name, icon } = appMetadata || {}
@@ -50,9 +51,8 @@ function coinbaseWallet({
5051
const base64 = window.btoa(icon || '')
5152
const appLogoUrl = `data:image/svg+xml;base64,${base64}`
5253

53-
const appChainIds = chains.map(
54-
// @ts-ignore - treating hex strings as numbers as they are expected to be hex numbers
55-
({ id }) => id as number
54+
const appChainIds = chains.map(({ id }) =>
55+
fromHex(id as `0x${string}`, 'number')
5656
)
5757

5858
const instance = new CoinbaseWalletSDKConstructor({
@@ -89,9 +89,20 @@ function coinbaseWallet({
8989

9090
return coinbaseWalletProvider
9191
}
92+
const provider = createEIP1193Provider(coinbaseWalletProvider, {
93+
eth_chainId: ({ baseRequest }) =>
94+
baseRequest({ method: 'eth_chainId' }).then(id => {
95+
if (isHex(id)) {
96+
return id
97+
} else {
98+
return toHex(id)
99+
}
100+
})
101+
})
102+
provider.removeListener = (event, func) => {}
92103

93104
return {
94-
provider: coinbaseWalletProvider as EIP1193Provider,
105+
provider,
95106
instance
96107
}
97108
}

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@web3-onboard/capsule": "2.1.0-alpha.2",
3434
"@web3-onboard/cede-store": "^2.3.0-alpha.2",
3535
"@web3-onboard/core": "^2.22.0-alpha.5",
36-
"@web3-onboard/coinbase": "^2.3.0-alpha.3",
36+
"@web3-onboard/coinbase": "^2.3.0-alpha.4",
3737
"@web3-onboard/dcent": "^2.2.7",
3838
"@web3-onboard/enkrypt": "^2.1.0-alpha.2",
3939
"@web3-onboard/fortmatic": "^2.1.0-alpha.2",

0 commit comments

Comments
 (0)