Skip to content

Commit 5b2b95f

Browse files
authored
Merge pull request #2204 from blocknative/enh/cb_4.0_upgrade
Enh - Coinbase dependency upgrade to 4.0
2 parents 1b409a8 + bc2a0ff commit 5b2b95f

File tree

8 files changed

+77
-35
lines changed

8 files changed

+77
-35
lines changed

docs/src/routes/docs/[...4]wallets/[...6]coinbase/+page.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,29 @@ npm install @web3-onboard/coinbase
2929

3030
```typescript
3131
type CoinbaseWalletOptions = {
32-
/** @optional Use dark theme */
32+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase Use dark theme */
3333
darkMode?: boolean
34-
/** @optional whether to connect mobile web app via WalletLink, defaults to false */
34+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether to connect mobile web app via WalletLink, defaults to false */
3535
enableMobileWalletLink?: boolean
36-
/** @optional whether or not to reload dapp automatically after disconnect, defaults to true */
36+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether or not to reload dapp automatically after disconnect, defaults to true */
3737
reloadOnDisconnect?: boolean
38+
/** Type of Coinbase wallets to support - options : 'all' | 'smartWalletOnly' | 'eoaOnly' - Default to `all` */
39+
supportedWalletType?: 'all' | 'smartWalletOnly' | 'eoaOnly'
3840
}
3941
```
4042
43+
## Smart Wallet
44+
45+
Starting at `@web3-onboard/coinbase` version 2.3.0 smart wallet support has been added. A smart wallet lives in your browser, no extensions or app installs needed. Use passkeys for signing, with enterprise-grade security without complex seed phrases. One wallet, one address, works universally across major L2s and onchain apps. [More info on Coinbase smart wallets](https://www.coinbase.com/wallet/smart-wallet).
46+
4147
## Usage
4248
4349
```typescript
4450
import Onboard from '@web3-onboard/core'
4551
import coinbaseWalletModule from '@web3-onboard/coinbase'
4652

4753
// initialize the module with options
48-
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true })
54+
const coinbaseWalletSdk = coinbaseWalletModule()
4955

5056
// can also initialize with no options...
5157
// const coinbaseWalletSdk = coinbaseWalletSdk()

packages/coinbase/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# @web3-onboard/coinbase
22

33
## Wallet module for connecting Coinbase Wallet SDK to web3-onboard
4+
45
See [Coinbase Wallet Developer Docs](https://docs.cloud.coinbase.com/wallet-sdk/docs)
56

67
### Install
@@ -11,23 +12,29 @@ See [Coinbase Wallet Developer Docs](https://docs.cloud.coinbase.com/wallet-sdk/
1112

1213
```typescript
1314
type CoinbaseWalletOptions = {
14-
/** @optional Use dark theme */
15+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase Use dark theme */
1516
darkMode?: boolean
16-
/** @optional whether to connect mobile web app via WalletLink, defaults to false */
17+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether to connect mobile web app via WalletLink, defaults to false */
1718
enableMobileWalletLink?: boolean
18-
/** @optional whether or not to reload dapp automatically after disconnect, defaults to true */
19+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether or not to reload dapp automatically after disconnect, defaults to true */
1920
reloadOnDisconnect?: boolean
21+
/** Type of Coinbase wallets to support - options : 'all' | 'smartWalletOnly' | 'eoaOnly' - Default to `all` */
22+
supportedWalletType?: 'all' | 'smartWalletOnly' | 'eoaOnly'
2023
}
2124
```
2225
26+
## Smart Wallet
27+
28+
Starting at `@web3-onboard/coinbase` version 2.3.0 smart wallet support has been added. A smart wallet lives in your browser, no extensions or app installs needed. Use passkeys for signing, with enterprise-grade security without complex seed phrases. One wallet, one address, works universally across major L2s and onchain apps. [More info on Coinbase smart wallets](https://www.coinbase.com/wallet/smart-wallet).
29+
2330
## Usage
2431
2532
```typescript
2633
import Onboard from '@web3-onboard/core'
2734
import coinbaseWalletModule from '@web3-onboard/coinbase'
2835

2936
// initialize the module with options
30-
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true })
37+
const coinbaseWalletSdk = coinbaseWalletModule()
3138

3239
// can also initialize with no options...
3340
// const coinbaseWalletSdk = coinbaseWalletModule()

packages/coinbase/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/coinbase",
3-
"version": "2.3.0",
3+
"version": "2.4.0-alpha.1",
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",
@@ -31,7 +31,8 @@
3131
"confirmed",
3232
"Injected Wallet",
3333
"Crypto",
34-
"Crypto Wallet"
34+
"Crypto Wallet",
35+
"Smart Wallet"
3536
],
3637
"repository": {
3738
"type": "git",
@@ -58,7 +59,7 @@
5859
"typescript": "^5.4.5"
5960
},
6061
"dependencies": {
61-
"@coinbase/wallet-sdk": "3.9.2",
62+
"@coinbase/wallet-sdk": "4.0.3",
6263
"@web3-onboard/common": "^2.4.0"
6364
}
6465
}

packages/coinbase/src/index.ts

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1-
import { WalletInit } from '@web3-onboard/common'
1+
import {
2+
createEIP1193Provider,
3+
fromHex,
4+
type WalletInit,
5+
type WalletInterface
6+
} from '@web3-onboard/common'
27

38
function coinbaseWallet({
9+
supportedWalletType = 'all',
410
darkMode = false,
511
enableMobileWalletLink = false,
612
reloadOnDisconnect = true
713
}: {
8-
/** @optional Use dark theme */
14+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase Use dark theme */
915
darkMode?: boolean
10-
/** @optional whether to connect mobile web app via WalletLink, defaults to false */
16+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether to connect mobile web app via WalletLink, defaults to false */
1117
enableMobileWalletLink?: boolean
12-
/** @optional whether or not to reload dapp automatically after disconnect, defaults to true */
18+
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether or not to reload dapp automatically after disconnect, defaults to true */
1319
reloadOnDisconnect?: boolean
20+
/** Type of Coinbase wallets to support - options : 'all' | 'smartWalletOnly' | 'eoaOnly' - Default to `all` */
21+
supportedWalletType?: 'all' | 'smartWalletOnly' | 'eoaOnly'
1422
} = {}): WalletInit {
1523
return () => {
1624
return {
1725
label: 'Coinbase Wallet',
1826
getIcon: async () => (await import('./icon.js')).default,
19-
getInterface: async ({ chains, appMetadata }) => {
20-
const [chain] = chains
27+
getInterface: async ({
28+
chains,
29+
appMetadata
30+
}): Promise<WalletInterface> => {
31+
if (enableMobileWalletLink || reloadOnDisconnect || darkMode) {
32+
console.warn(
33+
'darkMode, enableMobileWalletLink and reloadOnDisconnect init props are deprecated after version 2.2.7 of @web3-onboard/coinbase'
34+
)
35+
}
2136
const { name, icon } = appMetadata || {}
2237

2338
// according to https://github.com/wagmi-dev/wagmi/issues/383
@@ -31,29 +46,41 @@ function coinbaseWallet({
3146
? (CoinbaseWalletSDK as any).default
3247
: CoinbaseWalletSDK
3348
) as typeof CoinbaseWalletSDK
49+
const { isHex, toHex } = await import('@web3-onboard/common')
3450

3551
const base64 = window.btoa(icon || '')
3652
const appLogoUrl = `data:image/svg+xml;base64,${base64}`
3753

54+
const appChainIds = chains.map(({ id }) =>
55+
fromHex(id as `0x${string}`, 'number')
56+
)
57+
3858
const instance = new CoinbaseWalletSDKConstructor({
3959
appName: name || '',
4060
appLogoUrl,
41-
darkMode,
42-
enableMobileWalletLink,
43-
reloadOnDisconnect
61+
appChainIds
4462
})
4563

46-
const coinbaseWalletProvider = instance.makeWeb3Provider(
47-
chain.rpcUrl,
48-
parseInt(chain.id)
49-
)
64+
const coinbaseWalletProvider = instance.makeWeb3Provider({
65+
options: supportedWalletType
66+
})
5067

5168
// patch the chainChanged event
5269
const on = coinbaseWalletProvider.on.bind(coinbaseWalletProvider)
70+
5371
coinbaseWalletProvider.on = (event, listener) => {
72+
// @ts-ignore
5473
on(event, val => {
5574
if (event === 'chainChanged') {
56-
listener(`0x${(val as number).toString(16)}`)
75+
let hexVal: string
76+
if (isHex(val)) {
77+
hexVal = val
78+
} else {
79+
hexVal = toHex(val)
80+
}
81+
82+
// @ts-ignore
83+
listener(hexVal)
5784
return
5885
}
5986

@@ -62,9 +89,11 @@ function coinbaseWallet({
6289

6390
return coinbaseWalletProvider
6491
}
92+
const provider = createEIP1193Provider(coinbaseWalletProvider)
93+
provider.removeListener = (event, func) => {}
6594

6695
return {
67-
provider: coinbaseWalletProvider,
96+
provider,
6897
instance
6998
}
7099
}

packages/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export {
1313

1414
export * from './types.js'
1515
export * from './validation.js'
16+
export { parseEther, isHex, toHex, fromHex } from 'viem'

packages/common/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { ConnectionInfo } from 'ethers/lib/utils'
22
import EventEmitter from 'eventemitter3'
33
import type { TypedData as EIP712TypedData } from 'eip-712'
4+
import type { Address } from 'viem'
5+
export type { Address } from 'viem'
46
export type { TypedData as EIP712TypedData } from 'eip-712'
57

68
/**
@@ -300,7 +302,6 @@ export interface EthSignTransactionRequest {
300302
params: [TransactionObject]
301303
}
302304

303-
export type Address = `0x${string}`
304305
type Message = string
305306
export interface EthSignMessageRequest {
306307
method: 'eth_sign'

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",
3434
"@web3-onboard/cede-store": "^2.3.0",
3535
"@web3-onboard/core": "2.22.0",
36-
"@web3-onboard/coinbase": "^2.3.0",
36+
"@web3-onboard/coinbase": "^2.4.0-alpha.1",
3737
"@web3-onboard/dcent": "^2.2.7",
3838
"@web3-onboard/enkrypt": "^2.1.0",
3939
"@web3-onboard/fortmatic": "^2.1.0",

yarn.lock

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -783,16 +783,13 @@
783783
preact "^10.16.0"
784784
sha.js "^2.4.11"
785785

786-
"@coinbase/wallet-sdk@3.9.2":
787-
version "3.9.2"
788-
resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-3.9.2.tgz#757d6652d0972eb8804c50e3923a05242833caf1"
789-
integrity sha512-SyfUlG0DzgRu2WQ8+c7DpFEIe8Bt/nxyP1hcExDUXF7cHaopdAU43djT8SLIWH8Li40ZK9VBGVuNIK/pwHR9LA==
786+
"@coinbase/wallet-sdk@4.0.3":
787+
version "4.0.3"
788+
resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-4.0.3.tgz#fd52dd4c168c35979c7b3294018a6f78d163a593"
789+
integrity sha512-y/OGEjlvosikjfB+wk+4CVb9OxD1ob9cidEBLI5h8Hxaf/Qoob2XoVT1uvhtAzBx34KpGYSd+alKvh/GCRre4Q==
790790
dependencies:
791-
bn.js "^5.2.1"
792791
buffer "^6.0.3"
793792
clsx "^1.2.1"
794-
eth-block-tracker "^7.1.0"
795-
eth-json-rpc-filters "^6.0.0"
796793
eventemitter3 "^5.0.1"
797794
keccak "^3.0.3"
798795
preact "^10.16.0"

0 commit comments

Comments
 (0)