Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh - Coinbase dependency upgrade to 4.0 #2204

Merged
merged 10 commits into from
Jun 4, 2024
Merged
14 changes: 10 additions & 4 deletions docs/src/routes/docs/[...4]wallets/[...6]coinbase/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,29 @@ npm install @web3-onboard/coinbase

```typescript
type CoinbaseWalletOptions = {
/** @optional Use dark theme */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase Use dark theme */
darkMode?: boolean
/** @optional whether to connect mobile web app via WalletLink, defaults to false */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether to connect mobile web app via WalletLink, defaults to false */
enableMobileWalletLink?: boolean
/** @optional whether or not to reload dapp automatically after disconnect, defaults to true */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether or not to reload dapp automatically after disconnect, defaults to true */
reloadOnDisconnect?: boolean
/** Type of Coinbase wallets to support - options : 'all' | 'smartWalletOnly' | 'eoaOnly' - Default to `all` */
supportedWalletType?: 'all' | 'smartWalletOnly' | 'eoaOnly'
}
```

## Smart Wallet

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).

## Usage

```typescript
import Onboard from '@web3-onboard/core'
import coinbaseWalletModule from '@web3-onboard/coinbase'

// initialize the module with options
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true })
const coinbaseWalletSdk = coinbaseWalletModule()

// can also initialize with no options...
// const coinbaseWalletSdk = coinbaseWalletSdk()
Expand Down
15 changes: 11 additions & 4 deletions packages/coinbase/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @web3-onboard/coinbase

## Wallet module for connecting Coinbase Wallet SDK to web3-onboard

See [Coinbase Wallet Developer Docs](https://docs.cloud.coinbase.com/wallet-sdk/docs)

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

```typescript
type CoinbaseWalletOptions = {
/** @optional Use dark theme */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase Use dark theme */
darkMode?: boolean
/** @optional whether to connect mobile web app via WalletLink, defaults to false */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether to connect mobile web app via WalletLink, defaults to false */
enableMobileWalletLink?: boolean
/** @optional whether or not to reload dapp automatically after disconnect, defaults to true */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether or not to reload dapp automatically after disconnect, defaults to true */
reloadOnDisconnect?: boolean
/** Type of Coinbase wallets to support - options : 'all' | 'smartWalletOnly' | 'eoaOnly' - Default to `all` */
supportedWalletType?: 'all' | 'smartWalletOnly' | 'eoaOnly'
}
```

## Smart Wallet

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).

## Usage

```typescript
import Onboard from '@web3-onboard/core'
import coinbaseWalletModule from '@web3-onboard/coinbase'

// initialize the module with options
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true })
const coinbaseWalletSdk = coinbaseWalletModule()

// can also initialize with no options...
// const coinbaseWalletSdk = coinbaseWalletModule()
Expand Down
7 changes: 4 additions & 3 deletions packages/coinbase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/coinbase",
"version": "2.3.0",
"version": "2.4.0-alpha.1",
"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.",
"keywords": [
"Ethereum",
Expand Down Expand Up @@ -31,7 +31,8 @@
"confirmed",
"Injected Wallet",
"Crypto",
"Crypto Wallet"
"Crypto Wallet",
"Smart Wallet"
],
"repository": {
"type": "git",
Expand All @@ -58,7 +59,7 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@coinbase/wallet-sdk": "3.9.2",
"@coinbase/wallet-sdk": "4.0.3",
"@web3-onboard/common": "^2.4.0"
}
}
59 changes: 44 additions & 15 deletions packages/coinbase/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import { WalletInit } from '@web3-onboard/common'
import {
createEIP1193Provider,
fromHex,
type WalletInit,
type WalletInterface
} from '@web3-onboard/common'

function coinbaseWallet({
supportedWalletType = 'all',
darkMode = false,
enableMobileWalletLink = false,
reloadOnDisconnect = true
}: {
/** @optional Use dark theme */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase Use dark theme */
darkMode?: boolean
/** @optional whether to connect mobile web app via WalletLink, defaults to false */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether to connect mobile web app via WalletLink, defaults to false */
enableMobileWalletLink?: boolean
/** @optional whether or not to reload dapp automatically after disconnect, defaults to true */
/** @deprecated Deprecated after version 2.2.7 of @web3-onboard/coinbase whether or not to reload dapp automatically after disconnect, defaults to true */
reloadOnDisconnect?: boolean
/** Type of Coinbase wallets to support - options : 'all' | 'smartWalletOnly' | 'eoaOnly' - Default to `all` */
supportedWalletType?: 'all' | 'smartWalletOnly' | 'eoaOnly'
} = {}): WalletInit {
return () => {
return {
label: 'Coinbase Wallet',
getIcon: async () => (await import('./icon.js')).default,
getInterface: async ({ chains, appMetadata }) => {
const [chain] = chains
getInterface: async ({
chains,
appMetadata
}): Promise<WalletInterface> => {
if (enableMobileWalletLink || reloadOnDisconnect || darkMode) {
console.warn(
'darkMode, enableMobileWalletLink and reloadOnDisconnect init props are deprecated after version 2.2.7 of @web3-onboard/coinbase'
)
}
const { name, icon } = appMetadata || {}

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

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

const appChainIds = chains.map(({ id }) =>
fromHex(id as `0x${string}`, 'number')
)

const instance = new CoinbaseWalletSDKConstructor({
appName: name || '',
appLogoUrl,
darkMode,
enableMobileWalletLink,
reloadOnDisconnect
appChainIds
})

const coinbaseWalletProvider = instance.makeWeb3Provider(
chain.rpcUrl,
parseInt(chain.id)
)
const coinbaseWalletProvider = instance.makeWeb3Provider({
options: supportedWalletType
})

// patch the chainChanged event
const on = coinbaseWalletProvider.on.bind(coinbaseWalletProvider)

coinbaseWalletProvider.on = (event, listener) => {
// @ts-ignore
on(event, val => {
if (event === 'chainChanged') {
listener(`0x${(val as number).toString(16)}`)
let hexVal: string
if (isHex(val)) {
hexVal = val
} else {
hexVal = toHex(val)
}

// @ts-ignore
listener(hexVal)
return
Adamj1232 marked this conversation as resolved.
Show resolved Hide resolved
}

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

return coinbaseWalletProvider
}
const provider = createEIP1193Provider(coinbaseWalletProvider)
provider.removeListener = (event, func) => {}

return {
provider: coinbaseWalletProvider,
provider,
instance
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export {

export * from './types.js'
export * from './validation.js'
export { parseEther, isHex, toHex, fromHex } from 'viem'
3 changes: 2 additions & 1 deletion packages/common/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ConnectionInfo } from 'ethers/lib/utils'
import EventEmitter from 'eventemitter3'
import type { TypedData as EIP712TypedData } from 'eip-712'
import type { Address } from 'viem'
export type { Address } from 'viem'
export type { TypedData as EIP712TypedData } from 'eip-712'

/**
Expand Down Expand Up @@ -300,7 +302,6 @@ export interface EthSignTransactionRequest {
params: [TransactionObject]
}

export type Address = `0x${string}`
type Message = string
export interface EthSignMessageRequest {
method: 'eth_sign'
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@web3-onboard/capsule": "2.1.0",
"@web3-onboard/cede-store": "^2.3.0",
"@web3-onboard/core": "2.22.0",
"@web3-onboard/coinbase": "^2.3.0",
"@web3-onboard/coinbase": "^2.4.0-alpha.1",
"@web3-onboard/dcent": "^2.2.7",
"@web3-onboard/enkrypt": "^2.1.0",
"@web3-onboard/fortmatic": "^2.1.0",
Expand Down
11 changes: 4 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,13 @@
preact "^10.16.0"
sha.js "^2.4.11"

"@coinbase/wallet-sdk@3.9.2":
version "3.9.2"
resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-3.9.2.tgz#757d6652d0972eb8804c50e3923a05242833caf1"
integrity sha512-SyfUlG0DzgRu2WQ8+c7DpFEIe8Bt/nxyP1hcExDUXF7cHaopdAU43djT8SLIWH8Li40ZK9VBGVuNIK/pwHR9LA==
"@coinbase/wallet-sdk@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-4.0.3.tgz#fd52dd4c168c35979c7b3294018a6f78d163a593"
integrity sha512-y/OGEjlvosikjfB+wk+4CVb9OxD1ob9cidEBLI5h8Hxaf/Qoob2XoVT1uvhtAzBx34KpGYSd+alKvh/GCRre4Q==
dependencies:
bn.js "^5.2.1"
buffer "^6.0.3"
clsx "^1.2.1"
eth-block-tracker "^7.1.0"
eth-json-rpc-filters "^6.0.0"
eventemitter3 "^5.0.1"
keccak "^3.0.3"
preact "^10.16.0"
Expand Down
Loading