@wagmi/connectors 4.3.10 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/coinbaseWallet.js +196 -6
- package/dist/esm/coinbaseWallet.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/coinbaseWallet.d.ts +38 -7
- package/dist/types/coinbaseWallet.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/coinbaseWallet.ts +291 -39
- package/src/version.ts +1 -1
package/dist/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '
|
|
1
|
+
export const version = '5.0.1';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
|
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CoinbaseWalletSDK, ProviderInterface } from '@coinbase/wallet-sdk';
|
|
2
2
|
import type { Evaluate, Mutable, Omit } from '@wagmi/core/internal';
|
|
3
|
-
|
|
3
|
+
import type { CoinbaseWalletProvider as CBW_Provider, CoinbaseWalletSDK as CBW_SDK } from 'cbw-sdk';
|
|
4
|
+
type Version = '3' | '4';
|
|
5
|
+
export type CoinbaseWalletParameters<version extends Version = '3'> = version extends '4' ? Evaluate<{
|
|
6
|
+
headlessMode?: false | undefined;
|
|
7
|
+
/** Coinbase Wallet SDK version */
|
|
8
|
+
version?: version | '3' | undefined;
|
|
9
|
+
} & Version4Parameters> : Evaluate<{
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated `headlessMode` will be removed in the next major version. Upgrade to `version: '4'`.
|
|
12
|
+
*/
|
|
13
|
+
headlessMode?: true | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Coinbase Wallet SDK version
|
|
16
|
+
* @deprecated Version 3 will be removed in the next major version. Upgrade to `version: '4'`.
|
|
17
|
+
* @default '4'
|
|
18
|
+
*/
|
|
19
|
+
version?: version | '4' | undefined;
|
|
20
|
+
} & Version3Parameters>;
|
|
21
|
+
export declare function coinbaseWallet<version extends Version>(parameters?: CoinbaseWalletParameters<version>): version extends '4' ? ReturnType<typeof version4> : ReturnType<typeof version3>;
|
|
22
|
+
export declare namespace coinbaseWallet {
|
|
23
|
+
var type: "coinbaseWallet";
|
|
24
|
+
}
|
|
25
|
+
type Version4Parameters = Mutable<Omit<ConstructorParameters<typeof CoinbaseWalletSDK>[0], 'appChainIds'> & {
|
|
26
|
+
/**
|
|
27
|
+
* Preference for the type of wallet to display.
|
|
28
|
+
* @default 'all'
|
|
29
|
+
*/
|
|
30
|
+
preference?: 'all' | 'smartWalletOnly' | 'eoaOnly' | undefined;
|
|
31
|
+
keysUrl?: string | undefined;
|
|
32
|
+
}>;
|
|
33
|
+
declare function version4(parameters: Version4Parameters): import("@wagmi/core").CreateConnectorFn<ProviderInterface & {
|
|
34
|
+
close?(): void;
|
|
35
|
+
}, {}, {}>;
|
|
36
|
+
type Version3Parameters = Mutable<Omit<ConstructorParameters<typeof CBW_SDK>[0], 'reloadOnDisconnect'>> & {
|
|
4
37
|
/**
|
|
5
38
|
* Fallback Ethereum JSON RPC URL
|
|
6
39
|
* @default ""
|
|
@@ -16,9 +49,7 @@ export type CoinbaseWalletParameters = Evaluate<Mutable<Omit<ConstructorParamete
|
|
|
16
49
|
* @default false
|
|
17
50
|
*/
|
|
18
51
|
reloadOnDisconnect?: boolean | undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export
|
|
22
|
-
var type: "coinbaseWallet";
|
|
23
|
-
}
|
|
52
|
+
};
|
|
53
|
+
declare function version3(parameters: Version3Parameters): import("@wagmi/core").CreateConnectorFn<CBW_Provider, {}, {}>;
|
|
54
|
+
export {};
|
|
24
55
|
//# sourceMappingURL=coinbaseWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinbaseWallet.d.ts","sourceRoot":"","sources":["../../src/coinbaseWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"coinbaseWallet.d.ts","sourceRoot":"","sources":["../../src/coinbaseWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAMhF,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EACV,sBAAsB,IAAI,YAAY,EACtC,iBAAiB,IAAI,OAAO,EAC7B,MAAM,SAAS,CAAA;AAUhB,KAAK,OAAO,GAAG,GAAG,GAAG,GAAG,CAAA;AAExB,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,OAAO,GAAG,GAAG,IAChE,OAAO,SAAS,GAAG,GACf,QAAQ,CACN;IACE,YAAY,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IAChC,kCAAkC;IAClC,OAAO,CAAC,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;CACpC,GAAG,kBAAkB,CACvB,GACD,QAAQ,CACN;IACE;;OAEG;IACH,YAAY,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;CACpC,GAAG,kBAAkB,CACvB,CAAA;AAGP,wBAAgB,cAAc,CAAC,OAAO,SAAS,OAAO,EACpD,UAAU,GAAE,wBAAwB,CAAC,OAAO,CAAa,GACxD,OAAO,SAAS,GAAG,GAClB,UAAU,CAAC,OAAO,QAAQ,CAAC,GAC3B,UAAU,CAAC,OAAO,QAAQ,CAAC,CAI9B;yBARe,cAAc;;;AAU9B,KAAK,kBAAkB,GAAG,OAAO,CAC/B,IAAI,CACF,qBAAqB,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAClD,aAAa,CACd,GAAG;IACF;;;OAGG;IACH,UAAU,CAAC,EAAE,KAAK,GAAG,iBAAiB,GAAG,SAAS,GAAG,SAAS,CAAA;IAC9D,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7B,CACF,CAAA;AAED,iBAAS,QAAQ,CAAC,UAAU,EAAE,kBAAkB;cAGlC,IAAI;WA6MjB;AAED,KAAK,kBAAkB,GAAG,OAAO,CAC/B,IAAI,CACF,qBAAqB,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,EACxC,oBAAoB,CACrB,CACF,GAAG;IACF;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACzC,CAAA;AAED,iBAAS,QAAQ,CAAC,UAAU,EAAE,kBAAkB,iEAuN/C"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "5.0.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wagmi/connectors",
|
|
3
3
|
"description": "Collection of connectors for Wagmi",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"typescript": ">=5.0.4",
|
|
32
32
|
"viem": "2.x",
|
|
33
|
-
"@wagmi/core": "2.
|
|
33
|
+
"@wagmi/core": "2.10.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"typescript": {
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@coinbase/wallet-sdk": "
|
|
41
|
+
"@coinbase/wallet-sdk": "4.0.0",
|
|
42
42
|
"@metamask/sdk": "0.20.3",
|
|
43
43
|
"@safe-global/safe-apps-provider": "0.18.1",
|
|
44
44
|
"@safe-global/safe-apps-sdk": "8.1.0",
|
|
45
45
|
"@walletconnect/ethereum-provider": "2.13.0",
|
|
46
|
-
"@walletconnect/modal": "2.6.2"
|
|
46
|
+
"@walletconnect/modal": "2.6.2",
|
|
47
|
+
"cbw-sdk": "npm:@coinbase/wallet-sdk@3.9.3"
|
|
47
48
|
},
|
|
48
49
|
"contributors": [
|
|
49
50
|
"awkweb.eth <t@wevm.dev>",
|
package/src/coinbaseWallet.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CoinbaseWalletProvider,
|
|
3
|
-
CoinbaseWalletSDK,
|
|
4
|
-
} from '@coinbase/wallet-sdk'
|
|
1
|
+
import type { CoinbaseWalletSDK, ProviderInterface } from '@coinbase/wallet-sdk'
|
|
5
2
|
import {
|
|
6
3
|
ChainNotConfiguredError,
|
|
7
4
|
type Connector,
|
|
8
5
|
createConnector,
|
|
9
6
|
} from '@wagmi/core'
|
|
10
7
|
import type { Evaluate, Mutable, Omit } from '@wagmi/core/internal'
|
|
8
|
+
import type {
|
|
9
|
+
CoinbaseWalletProvider as CBW_Provider,
|
|
10
|
+
CoinbaseWalletSDK as CBW_SDK,
|
|
11
|
+
} from 'cbw-sdk'
|
|
11
12
|
import {
|
|
12
13
|
type AddEthereumChainParameter,
|
|
13
14
|
type ProviderRpcError,
|
|
@@ -17,40 +18,297 @@ import {
|
|
|
17
18
|
numberToHex,
|
|
18
19
|
} from 'viem'
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
type Version = '3' | '4'
|
|
22
|
+
|
|
23
|
+
export type CoinbaseWalletParameters<version extends Version = '3'> =
|
|
24
|
+
version extends '4'
|
|
25
|
+
? Evaluate<
|
|
26
|
+
{
|
|
27
|
+
headlessMode?: false | undefined
|
|
28
|
+
/** Coinbase Wallet SDK version */
|
|
29
|
+
version?: version | '3' | undefined
|
|
30
|
+
} & Version4Parameters
|
|
31
|
+
>
|
|
32
|
+
: Evaluate<
|
|
33
|
+
{
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated `headlessMode` will be removed in the next major version. Upgrade to `version: '4'`.
|
|
36
|
+
*/
|
|
37
|
+
headlessMode?: true | undefined
|
|
38
|
+
/**
|
|
39
|
+
* Coinbase Wallet SDK version
|
|
40
|
+
* @deprecated Version 3 will be removed in the next major version. Upgrade to `version: '4'`.
|
|
41
|
+
* @default '4'
|
|
42
|
+
*/
|
|
43
|
+
version?: version | '4' | undefined
|
|
44
|
+
} & Version3Parameters
|
|
45
|
+
>
|
|
46
|
+
|
|
47
|
+
coinbaseWallet.type = 'coinbaseWallet' as const
|
|
48
|
+
export function coinbaseWallet<version extends Version>(
|
|
49
|
+
parameters: CoinbaseWalletParameters<version> = {} as any,
|
|
50
|
+
): version extends '4'
|
|
51
|
+
? ReturnType<typeof version4>
|
|
52
|
+
: ReturnType<typeof version3> {
|
|
53
|
+
if (parameters.version === '3' || parameters.headlessMode)
|
|
54
|
+
return version3(parameters as Version3Parameters) as any
|
|
55
|
+
return version4(parameters as Version4Parameters) as any
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type Version4Parameters = Mutable<
|
|
59
|
+
Omit<
|
|
60
|
+
ConstructorParameters<typeof CoinbaseWalletSDK>[0],
|
|
61
|
+
'appChainIds' // set via wagmi config
|
|
27
62
|
> & {
|
|
28
63
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @default
|
|
64
|
+
* Preference for the type of wallet to display.
|
|
65
|
+
* @default 'all'
|
|
31
66
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Fallback Ethereum Chain ID
|
|
35
|
-
* @default 1
|
|
36
|
-
*/
|
|
37
|
-
chainId?: number | undefined
|
|
38
|
-
/**
|
|
39
|
-
* Whether or not to reload dapp automatically after disconnect.
|
|
40
|
-
* @default false
|
|
41
|
-
*/
|
|
42
|
-
reloadOnDisconnect?: boolean | undefined
|
|
67
|
+
preference?: 'all' | 'smartWalletOnly' | 'eoaOnly' | undefined
|
|
68
|
+
keysUrl?: string | undefined
|
|
43
69
|
}
|
|
44
70
|
>
|
|
45
71
|
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
function version4(parameters: Version4Parameters) {
|
|
73
|
+
type Provider = ProviderInterface & {
|
|
74
|
+
// for backwards compatibility
|
|
75
|
+
close?(): void
|
|
76
|
+
}
|
|
77
|
+
type Properties = {}
|
|
78
|
+
|
|
79
|
+
let sdk: CoinbaseWalletSDK | undefined
|
|
80
|
+
let walletProvider: Provider | undefined
|
|
81
|
+
|
|
82
|
+
let accountsChanged: Connector['onAccountsChanged'] | undefined
|
|
83
|
+
let chainChanged: Connector['onChainChanged'] | undefined
|
|
84
|
+
let disconnect: Connector['onDisconnect'] | undefined
|
|
85
|
+
|
|
86
|
+
return createConnector<Provider, Properties>((config) => ({
|
|
87
|
+
id: 'coinbaseWalletSDK',
|
|
88
|
+
name: 'Coinbase Wallet',
|
|
89
|
+
supportsSimulation: true,
|
|
90
|
+
type: coinbaseWallet.type,
|
|
91
|
+
async connect({ chainId } = {}) {
|
|
92
|
+
try {
|
|
93
|
+
const provider = await this.getProvider()
|
|
94
|
+
const accounts = (
|
|
95
|
+
(await provider.request({
|
|
96
|
+
method: 'eth_requestAccounts',
|
|
97
|
+
})) as string[]
|
|
98
|
+
).map((x) => getAddress(x))
|
|
99
|
+
|
|
100
|
+
if (!accountsChanged) {
|
|
101
|
+
accountsChanged = this.onAccountsChanged.bind(this)
|
|
102
|
+
provider.on('accountsChanged', accountsChanged)
|
|
103
|
+
}
|
|
104
|
+
if (!chainChanged) {
|
|
105
|
+
chainChanged = this.onChainChanged.bind(this)
|
|
106
|
+
provider.on('chainChanged', chainChanged)
|
|
107
|
+
}
|
|
108
|
+
if (!disconnect) {
|
|
109
|
+
disconnect = this.onDisconnect.bind(this)
|
|
110
|
+
provider.on('disconnect', disconnect)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Switch to chain if provided
|
|
114
|
+
let currentChainId = await this.getChainId()
|
|
115
|
+
if (chainId && currentChainId !== chainId) {
|
|
116
|
+
const chain = await this.switchChain!({ chainId }).catch((error) => {
|
|
117
|
+
if (error.code === UserRejectedRequestError.code) throw error
|
|
118
|
+
return { id: currentChainId }
|
|
119
|
+
})
|
|
120
|
+
currentChainId = chain?.id ?? currentChainId
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return { accounts, chainId: currentChainId }
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (
|
|
126
|
+
/(user closed modal|accounts received is empty|user denied account)/i.test(
|
|
127
|
+
(error as Error).message,
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
throw new UserRejectedRequestError(error as Error)
|
|
131
|
+
throw error
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
async disconnect() {
|
|
135
|
+
const provider = await this.getProvider()
|
|
136
|
+
|
|
137
|
+
if (accountsChanged) {
|
|
138
|
+
provider.removeListener('accountsChanged', accountsChanged)
|
|
139
|
+
accountsChanged = undefined
|
|
140
|
+
}
|
|
141
|
+
if (chainChanged) {
|
|
142
|
+
provider.removeListener('chainChanged', chainChanged)
|
|
143
|
+
chainChanged = undefined
|
|
144
|
+
}
|
|
145
|
+
if (disconnect) {
|
|
146
|
+
provider.removeListener('disconnect', disconnect)
|
|
147
|
+
disconnect = undefined
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
provider.disconnect()
|
|
151
|
+
provider.close?.()
|
|
152
|
+
},
|
|
153
|
+
async getAccounts() {
|
|
154
|
+
const provider = await this.getProvider()
|
|
155
|
+
return (
|
|
156
|
+
await provider.request<string[]>({
|
|
157
|
+
method: 'eth_accounts',
|
|
158
|
+
})
|
|
159
|
+
).map((x) => getAddress(x))
|
|
160
|
+
},
|
|
161
|
+
async getChainId() {
|
|
162
|
+
const provider = await this.getProvider()
|
|
163
|
+
const chainId = await provider.request<number>({
|
|
164
|
+
method: 'eth_chainId',
|
|
165
|
+
})
|
|
166
|
+
return Number(chainId)
|
|
167
|
+
},
|
|
168
|
+
async getProvider() {
|
|
169
|
+
if (!walletProvider) {
|
|
170
|
+
// Unwrap import
|
|
171
|
+
const { default: SDK_ } = await import('@coinbase/wallet-sdk')
|
|
172
|
+
let SDK: typeof SDK_.default
|
|
173
|
+
if (typeof SDK_ !== 'function' && typeof SDK_.default === 'function')
|
|
174
|
+
SDK = SDK_.default
|
|
175
|
+
else SDK = SDK_ as unknown as typeof SDK_.default
|
|
176
|
+
sdk = new SDK({
|
|
177
|
+
...parameters,
|
|
178
|
+
appChainIds: config.chains.map((x) => x.id),
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
walletProvider = sdk.makeWeb3Provider({
|
|
182
|
+
...parameters,
|
|
183
|
+
options: parameters.preference ?? 'all',
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return walletProvider
|
|
188
|
+
},
|
|
189
|
+
async isAuthorized() {
|
|
190
|
+
try {
|
|
191
|
+
const accounts = await this.getAccounts()
|
|
192
|
+
return !!accounts.length
|
|
193
|
+
} catch {
|
|
194
|
+
return false
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
async switchChain({ addEthereumChainParameter, chainId }) {
|
|
198
|
+
const chain = config.chains.find((chain) => chain.id === chainId)
|
|
199
|
+
if (!chain) throw new SwitchChainError(new ChainNotConfiguredError())
|
|
200
|
+
|
|
201
|
+
const provider = await this.getProvider()
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
await provider.request({
|
|
205
|
+
method: 'wallet_switchEthereumChain',
|
|
206
|
+
params: [{ chainId: numberToHex(chain.id) }],
|
|
207
|
+
})
|
|
208
|
+
return chain
|
|
209
|
+
} catch (error) {
|
|
210
|
+
// Indicates chain is not added to provider
|
|
211
|
+
if ((error as ProviderRpcError).code === 4902) {
|
|
212
|
+
try {
|
|
213
|
+
let blockExplorerUrls
|
|
214
|
+
if (addEthereumChainParameter?.blockExplorerUrls)
|
|
215
|
+
blockExplorerUrls = addEthereumChainParameter.blockExplorerUrls
|
|
216
|
+
else
|
|
217
|
+
blockExplorerUrls = chain.blockExplorers?.default.url
|
|
218
|
+
? [chain.blockExplorers?.default.url]
|
|
219
|
+
: []
|
|
220
|
+
|
|
221
|
+
let rpcUrls
|
|
222
|
+
if (addEthereumChainParameter?.rpcUrls?.length)
|
|
223
|
+
rpcUrls = addEthereumChainParameter.rpcUrls
|
|
224
|
+
else rpcUrls = [chain.rpcUrls.default?.http[0] ?? '']
|
|
225
|
+
|
|
226
|
+
const addEthereumChain = {
|
|
227
|
+
blockExplorerUrls,
|
|
228
|
+
chainId: numberToHex(chainId),
|
|
229
|
+
chainName: addEthereumChainParameter?.chainName ?? chain.name,
|
|
230
|
+
iconUrls: addEthereumChainParameter?.iconUrls,
|
|
231
|
+
nativeCurrency:
|
|
232
|
+
addEthereumChainParameter?.nativeCurrency ??
|
|
233
|
+
chain.nativeCurrency,
|
|
234
|
+
rpcUrls,
|
|
235
|
+
} satisfies AddEthereumChainParameter
|
|
236
|
+
|
|
237
|
+
await provider.request({
|
|
238
|
+
method: 'wallet_addEthereumChain',
|
|
239
|
+
params: [addEthereumChain],
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
return chain
|
|
243
|
+
} catch (error) {
|
|
244
|
+
throw new UserRejectedRequestError(error as Error)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
throw new SwitchChainError(error as Error)
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
onAccountsChanged(accounts) {
|
|
252
|
+
if (accounts.length === 0) this.onDisconnect()
|
|
253
|
+
else
|
|
254
|
+
config.emitter.emit('change', {
|
|
255
|
+
accounts: accounts.map((x) => getAddress(x)),
|
|
256
|
+
})
|
|
257
|
+
},
|
|
258
|
+
onChainChanged(chain) {
|
|
259
|
+
const chainId = Number(chain)
|
|
260
|
+
config.emitter.emit('change', { chainId })
|
|
261
|
+
},
|
|
262
|
+
async onDisconnect(_error) {
|
|
263
|
+
config.emitter.emit('disconnect')
|
|
264
|
+
|
|
265
|
+
const provider = await this.getProvider()
|
|
266
|
+
if (accountsChanged) {
|
|
267
|
+
provider.removeListener('accountsChanged', accountsChanged)
|
|
268
|
+
accountsChanged = undefined
|
|
269
|
+
}
|
|
270
|
+
if (chainChanged) {
|
|
271
|
+
provider.removeListener('chainChanged', chainChanged)
|
|
272
|
+
chainChanged = undefined
|
|
273
|
+
}
|
|
274
|
+
if (disconnect) {
|
|
275
|
+
provider.removeListener('disconnect', disconnect)
|
|
276
|
+
disconnect = undefined
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
}))
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
type Version3Parameters = Mutable<
|
|
283
|
+
Omit<
|
|
284
|
+
ConstructorParameters<typeof CBW_SDK>[0],
|
|
285
|
+
'reloadOnDisconnect' // remove property since TSDoc says default is `true`
|
|
286
|
+
>
|
|
287
|
+
> & {
|
|
288
|
+
/**
|
|
289
|
+
* Fallback Ethereum JSON RPC URL
|
|
290
|
+
* @default ""
|
|
291
|
+
*/
|
|
292
|
+
jsonRpcUrl?: string | undefined
|
|
293
|
+
/**
|
|
294
|
+
* Fallback Ethereum Chain ID
|
|
295
|
+
* @default 1
|
|
296
|
+
*/
|
|
297
|
+
chainId?: number | undefined
|
|
298
|
+
/**
|
|
299
|
+
* Whether or not to reload dapp automatically after disconnect.
|
|
300
|
+
* @default false
|
|
301
|
+
*/
|
|
302
|
+
reloadOnDisconnect?: boolean | undefined
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function version3(parameters: Version3Parameters) {
|
|
48
306
|
const reloadOnDisconnect = false
|
|
49
307
|
|
|
50
|
-
type Provider =
|
|
308
|
+
type Provider = CBW_Provider
|
|
51
309
|
type Properties = {}
|
|
52
310
|
|
|
53
|
-
let sdk:
|
|
311
|
+
let sdk: CBW_SDK | undefined
|
|
54
312
|
let walletProvider: Provider | undefined
|
|
55
313
|
|
|
56
314
|
let accountsChanged: Connector['onAccountsChanged'] | undefined
|
|
@@ -139,17 +397,11 @@ export function coinbaseWallet(parameters: CoinbaseWalletParameters) {
|
|
|
139
397
|
},
|
|
140
398
|
async getProvider() {
|
|
141
399
|
if (!walletProvider) {
|
|
142
|
-
const { default:
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
typeof CoinbaseWalletSDK !== 'function' &&
|
|
148
|
-
typeof CoinbaseWalletSDK.default === 'function'
|
|
149
|
-
)
|
|
150
|
-
SDK = CoinbaseWalletSDK.default
|
|
151
|
-
else
|
|
152
|
-
SDK = CoinbaseWalletSDK as unknown as typeof CoinbaseWalletSDK.default
|
|
400
|
+
const { default: SDK_ } = await import('cbw-sdk')
|
|
401
|
+
let SDK: typeof SDK_.default
|
|
402
|
+
if (typeof SDK_ !== 'function' && typeof SDK_.default === 'function')
|
|
403
|
+
SDK = SDK_.default
|
|
404
|
+
else SDK = SDK_ as unknown as typeof SDK_.default
|
|
153
405
|
sdk = new SDK({ reloadOnDisconnect, ...parameters })
|
|
154
406
|
|
|
155
407
|
// Force types to retrieve private `walletExtension` method from the Coinbase Wallet SDK.
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '
|
|
1
|
+
export const version = '5.0.1'
|