Skip to content

Commit

Permalink
Coinbase Wallet: Add Support for Instant Onboarding mode (#4440)
Browse files Browse the repository at this point in the history
* Update coinbaseWallet.ts

* add changeset

* refactor: types

* test: types

---------

Co-authored-by: Tom Meagher <[email protected]>
  • Loading branch information
johanneskares and tmm authored Dec 16, 2024
1 parent 7469614 commit e3f63a0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-radios-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/connectors": minor
---

Added Coinbase Smart Wallet "Instant Onboarding" mode to `coinbaseWallet`.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"test": "vitest",
"test:build": "bun scripts/generateProxyPackages.ts && pnpm run --r --parallel test:build",
"test:cli": "vitest --project @wagmi/cli",
"test:connectors": "vitest --project @wagmi/connectors",
"test:core": "vitest --project @wagmi/core",
"test:create-wagmi": "vitest --project create-wagmi",
"test:cov": "vitest run --coverage",
Expand Down
11 changes: 9 additions & 2 deletions packages/connectors/src/coinbaseWallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { config } from '@wagmi/test'
import { expect, test } from 'vitest'
import { expect, expectTypeOf, test } from 'vitest'

import { coinbaseWallet } from './coinbaseWallet.js'

test('setup', () => {
const connectorFn = coinbaseWallet({ appName: 'wagmi' })
const connectorFn = coinbaseWallet({ appName: 'wagmi', version: '4' })
const connector = config._internal.connectors.setup(connectorFn)
expect(connector.name).toEqual('Coinbase Wallet')

type ConnectFnParameters = NonNullable<
Parameters<(typeof connector)['connect']>[0]
>
expectTypeOf<ConnectFnParameters['instantOnboarding']>().toMatchTypeOf<
boolean | undefined
>()
})
19 changes: 17 additions & 2 deletions packages/connectors/src/coinbaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
} from 'cbw-sdk'
import {
type AddEthereumChainParameter,
type Address,
type Hex,
type ProviderRpcError,
SwitchChainError,
Expand Down Expand Up @@ -80,24 +81,38 @@ function version4(parameters: Version4Parameters) {
// for backwards compatibility
close?(): void
}
type Properties = {
connect(parameters?: {
chainId?: number | undefined
instantOnboarding?: boolean | undefined
isReconnecting?: boolean | undefined
}): Promise<{
accounts: readonly Address[]
chainId: number
}>
}

let walletProvider: Provider | undefined

let accountsChanged: Connector['onAccountsChanged'] | undefined
let chainChanged: Connector['onChainChanged'] | undefined
let disconnect: Connector['onDisconnect'] | undefined

return createConnector<Provider>((config) => ({
return createConnector<Provider, Properties>((config) => ({
id: 'coinbaseWalletSDK',
name: 'Coinbase Wallet',
rdns: 'com.coinbase.wallet',
type: coinbaseWallet.type,
async connect({ chainId } = {}) {
async connect({ chainId, ...rest } = {}) {
try {
const provider = await this.getProvider()
const accounts = (
(await provider.request({
method: 'eth_requestAccounts',
params:
'instantOnboarding' in rest && rest.instantOnboarding
? [{ onboarding: 'instant' }]
: [],
})) as string[]
).map((x) => getAddress(x))

Expand Down

0 comments on commit e3f63a0

Please sign in to comment.