Skip to content

Commit 83e93ed

Browse files
Adds coinbase-wallet-sdk (#904)
* Adds coinbase-wallet-sdk * Add documentation link * updates * Updates reference * [feedback] rename * [feedback] update walletlink version * Delete yarn.lock * Add CI Co-authored-by: Aaron Barnard <abarnard@protonmail.com>
1 parent c7b9a8b commit 83e93ed

File tree

10 files changed

+175
-2
lines changed

10 files changed

+175
-2
lines changed

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ jobs:
191191
working_directory: ~/web3-onboard-monorepo/packages/magic
192192
steps:
193193
- node-build-steps
194+
build-coinbase:
195+
docker:
196+
- image: cimg/node:16.13.1
197+
working_directory: ~/web3-onboard-monorepo/packages/coinbase
198+
steps:
199+
- node-build-steps
194200

195201
workflows:
196202
version: 2
@@ -259,3 +265,7 @@ workflows:
259265
jobs:
260266
- build-magic:
261267
<<: *deploy_production_filters
268+
coinbase:
269+
jobs:
270+
- build-coinbase:
271+
<<: *deploy_production_filters

packages/coinbase/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# @web3-onboard/coinbase
2+
3+
## Wallet module for connecting Coinbase Wallet SDK to web3-onboard
4+
See [Coinbase Wallet Developer Docs](https://docs.cloud.coinbase.com/wallet-sdk/docs)
5+
6+
### Install
7+
8+
`npm i @web3-onboard/coinbase`
9+
10+
## Options
11+
12+
```typescript
13+
type CoinbaseWalletOptions = {
14+
darkMode: boolean // default = false
15+
}
16+
```
17+
18+
## Usage
19+
20+
```typescript
21+
import Onboard from '@web3-onboard/core'
22+
import coinbaseWalletModule from '@web3-onboard/coinbase'
23+
24+
// initialize the module with options
25+
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true })
26+
27+
// can also initialize with no options...
28+
// const coinbaseWalletSdk = coinbaseWalletSdk()
29+
30+
const onboard = Onboard({
31+
// ... other Onboard options
32+
wallets: [
33+
coinbaseWalletSdk
34+
//... other wallets
35+
]
36+
})
37+
38+
const connectedWallets = await onboard.connectWallet()
39+
console.log(connectedWallets)
40+
```

packages/coinbase/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@web3-onboard/coinbase",
3+
"version": "2.0.0",
4+
"description": "Coinbase Wallet module for web3-onboard",
5+
"module": "dist/index.js",
6+
"browser": "dist/index.js",
7+
"main": "dist/index.js",
8+
"type": "module",
9+
"typings": "dist/index.d.ts",
10+
"files": [
11+
"dist"
12+
],
13+
"scripts": {
14+
"build": "tsc",
15+
"dev": "tsc -w",
16+
"type-check": "tsc --noEmit"
17+
},
18+
"license": "MIT",
19+
"devDependencies": {
20+
"typescript": "^4.5.5"
21+
},
22+
"dependencies": {
23+
"@web3-onboard/common": "^2.0.0",
24+
"@coinbase/wallet-sdk": "^3.0.5"
25+
}
26+
}

packages/coinbase/src/icon.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default `
2+
<svg width="100%" height="100%" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
3+
<path d="M20 40C31.0457 40 40 31.0457 40 20C40 8.9543 31.0457 0 20 0C8.9543 0 0 8.9543 0 20C0 31.0457 8.9543 40 20 40Z" fill="#1652F0"/>
4+
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.45508 20.0006C5.45508 28.0338 11.9673 34.546 20.0006 34.546C28.0338 34.546 34.546 28.0338 34.546 20.0006C34.546 11.9673 28.0338 5.45508 20.0006 5.45508C11.9673 5.45508 5.45508 11.9673 5.45508 20.0006ZM17.3137 15.3145C16.2091 15.3145 15.3137 16.2099 15.3137 17.3145V22.6882C15.3137 23.7928 16.2091 24.6882 17.3137 24.6882H22.6874C23.792 24.6882 24.6874 23.7928 24.6874 22.6882V17.3145C24.6874 16.2099 23.792 15.3145 22.6874 15.3145H17.3137Z" fill="white"/>
5+
</svg>
6+
`

packages/coinbase/src/index.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { WalletInit } from '@web3-onboard/common'
2+
3+
function coinbaseWallet(options?: { darkMode?: boolean }): WalletInit {
4+
const { darkMode = false } = options || {}
5+
6+
return () => {
7+
return {
8+
label: 'Coinbase',
9+
getIcon: async () => (await import('./icon.js')).default,
10+
getInterface: async ({ chains, appMetadata }) => {
11+
const [chain] = chains
12+
const { name, icon } = appMetadata || {}
13+
14+
const { CoinbaseWalletSDK } = await import('@coinbase/wallet-sdk')
15+
16+
const base64 = window.btoa(icon || '')
17+
const appLogoUrl = `data:image/svg+xml;base64,${base64}`
18+
19+
const instance = new CoinbaseWalletSDK({
20+
appName: name || '',
21+
appLogoUrl,
22+
darkMode
23+
})
24+
25+
const coinbaseWalletProvider = instance.makeWeb3Provider(
26+
chain.rpcUrl,
27+
parseInt(chain.id)
28+
)
29+
30+
// patch the chainChanged event
31+
const on = coinbaseWalletProvider.on.bind(coinbaseWalletProvider)
32+
coinbaseWalletProvider.on = (event, listener) => {
33+
on(event, val => {
34+
if (event === 'chainChanged') {
35+
listener(`0x${(val as number).toString(16)}`)
36+
return
37+
}
38+
39+
listener(val)
40+
})
41+
42+
return coinbaseWalletProvider
43+
}
44+
45+
return {
46+
provider: coinbaseWalletProvider,
47+
instance
48+
}
49+
}
50+
}
51+
}
52+
}
53+
54+
export default coinbaseWallet

packages/coinbase/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["src/**/*"],
4+
5+
"compilerOptions": {
6+
"outDir": "dist",
7+
"rootDir": "src",
8+
"declarationDir": "dist",
9+
"paths": {
10+
"*": ["./src/*", "./node_modules/*"]
11+
},
12+
"typeRoots": ["node_modules/@types"],
13+
}
14+
}

packages/walletlink/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# @web3-onboard/walletlink
22

3-
## Wallet module for connecting WalletLink to web3-onboard
3+
## (Deprecated) Wallet module for connecting WalletLink to web3-onboard
4+
_Use [@web3-onboard/coinbase-wallet-sdk](../coinbase/README.md)_
45

56
### Install
67

packages/walletlink/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/walletlink",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "WalletLink module for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",

packages/walletlink/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ function walletLink(options?: { darkMode?: boolean }): WalletInit {
5151
}
5252
}
5353

54+
/**
55+
* @deprecated Use @web3-onboard/coinbase
56+
*/
5457
export default walletLink

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@
191191
"@babel/helper-validator-identifier" "^7.16.7"
192192
to-fast-properties "^2.0.0"
193193

194+
"@coinbase/wallet-sdk@^3.0.5":
195+
version "3.0.5"
196+
resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-3.0.5.tgz#d9eb49b482570e93ef9fd0bfe15c5582e28b3063"
197+
integrity sha512-MsPhgS9b9DpNQdbuYEFDZToPVhh8OQZFkLH59LpYHXRxRIjQDsGGjXcLC50jfW06ElBbtB9adl5RlJTmXb9KbA==
198+
dependencies:
199+
"@metamask/safe-event-emitter" "2.0.0"
200+
bind-decorator "^1.0.11"
201+
bn.js "^5.1.1"
202+
clsx "^1.1.0"
203+
eth-block-tracker "4.4.3"
204+
eth-json-rpc-filters "4.2.2"
205+
eth-rpc-errors "4.0.2"
206+
js-sha256 "0.9.0"
207+
json-rpc-engine "6.1.0"
208+
keccak "^3.0.1"
209+
preact "^10.5.9"
210+
rxjs "^6.6.3"
211+
stream-browserify "^3.0.0"
212+
194213
"@cspotcode/source-map-consumer@0.8.0":
195214
version "0.8.0"
196215
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b"

0 commit comments

Comments
 (0)