@wagmi/connectors 3.1.2-cjs → 3.1.2
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/chunk-2UFLHRLT.js +65 -65
- package/dist/chunk-OQILYQDO.js +4 -4
- package/dist/chunk-UGBGYVBH.js +5 -5
- package/dist/chunk-W65LBPLT.js +13 -13
- package/dist/coinbaseWallet.js +51 -51
- package/dist/index.js +16 -16
- package/dist/injected.js +9 -9
- package/dist/ledger.js +75 -75
- package/dist/metaMask.js +34 -34
- package/dist/mock/index.js +55 -55
- package/dist/safe.js +42 -42
- package/dist/walletConnect.js +101 -101
- package/dist/walletConnectLegacy.js +51 -51
- package/package.json +2 -1
package/dist/chunk-2UFLHRLT.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChainNotConfiguredForConnectorError,
|
|
3
|
+
ConnectorNotFoundError
|
|
4
|
+
} from "./chunk-UGBGYVBH.js";
|
|
5
|
+
import {
|
|
6
|
+
normalizeChainId
|
|
7
|
+
} from "./chunk-OQILYQDO.js";
|
|
8
|
+
import {
|
|
9
|
+
Connector,
|
|
10
|
+
__privateAdd,
|
|
11
|
+
__privateGet,
|
|
12
|
+
__privateSet
|
|
13
|
+
} from "./chunk-W65LBPLT.js";
|
|
14
14
|
|
|
15
15
|
// src/injected.ts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
import {
|
|
17
|
+
ResourceUnavailableRpcError,
|
|
18
|
+
SwitchChainError,
|
|
19
|
+
UserRejectedRequestError,
|
|
20
|
+
createWalletClient,
|
|
21
|
+
custom,
|
|
22
|
+
getAddress,
|
|
23
|
+
numberToHex
|
|
24
|
+
} from "viem";
|
|
25
25
|
|
|
26
26
|
// src/utils/getInjectedName.ts
|
|
27
27
|
function getInjectedName(ethereum) {
|
|
@@ -119,7 +119,7 @@ function getInjectedName(ethereum) {
|
|
|
119
119
|
if (provider.isMetaMask)
|
|
120
120
|
return "MetaMask";
|
|
121
121
|
};
|
|
122
|
-
if (
|
|
122
|
+
if (ethereum.providers?.length) {
|
|
123
123
|
const nameSet = /* @__PURE__ */ new Set();
|
|
124
124
|
let unknownCount = 1;
|
|
125
125
|
for (const provider of ethereum.providers) {
|
|
@@ -133,14 +133,14 @@ function getInjectedName(ethereum) {
|
|
|
133
133
|
const names = [...nameSet];
|
|
134
134
|
if (names.length)
|
|
135
135
|
return names;
|
|
136
|
-
return
|
|
136
|
+
return names[0] ?? "Injected";
|
|
137
137
|
}
|
|
138
|
-
return
|
|
138
|
+
return getName(ethereum) ?? "Injected";
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// src/injected.ts
|
|
142
142
|
var _provider;
|
|
143
|
-
var InjectedConnector = class extends
|
|
143
|
+
var InjectedConnector = class extends Connector {
|
|
144
144
|
constructor({
|
|
145
145
|
chains,
|
|
146
146
|
options: options_
|
|
@@ -151,7 +151,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
151
151
|
if (typeof window === "undefined")
|
|
152
152
|
return;
|
|
153
153
|
const ethereum = window.ethereum;
|
|
154
|
-
if (
|
|
154
|
+
if (ethereum?.providers)
|
|
155
155
|
return ethereum.providers[0];
|
|
156
156
|
return ethereum;
|
|
157
157
|
},
|
|
@@ -159,18 +159,18 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
159
159
|
};
|
|
160
160
|
super({ chains, options });
|
|
161
161
|
this.id = "injected";
|
|
162
|
-
|
|
162
|
+
__privateAdd(this, _provider, void 0);
|
|
163
163
|
this.shimDisconnectKey = `${this.id}.shimDisconnect`;
|
|
164
164
|
this.onAccountsChanged = (accounts) => {
|
|
165
165
|
if (accounts.length === 0)
|
|
166
166
|
this.emit("disconnect");
|
|
167
167
|
else
|
|
168
168
|
this.emit("change", {
|
|
169
|
-
account:
|
|
169
|
+
account: getAddress(accounts[0])
|
|
170
170
|
});
|
|
171
171
|
};
|
|
172
172
|
this.onChainChanged = (chainId) => {
|
|
173
|
-
const id =
|
|
173
|
+
const id = normalizeChainId(chainId);
|
|
174
174
|
const unsupported = this.isChainUnsupported(id);
|
|
175
175
|
this.emit("change", { chain: { id, unsupported } });
|
|
176
176
|
};
|
|
@@ -185,7 +185,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
185
185
|
}
|
|
186
186
|
this.emit("disconnect");
|
|
187
187
|
if (this.options.shimDisconnect)
|
|
188
|
-
|
|
188
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
189
189
|
};
|
|
190
190
|
const provider = options.getProvider();
|
|
191
191
|
if (typeof options.name === "string")
|
|
@@ -208,7 +208,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
208
208
|
try {
|
|
209
209
|
const provider = await this.getProvider();
|
|
210
210
|
if (!provider)
|
|
211
|
-
throw new
|
|
211
|
+
throw new ConnectorNotFoundError();
|
|
212
212
|
if (provider.on) {
|
|
213
213
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
214
214
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -218,7 +218,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
218
218
|
const accounts = await provider.request({
|
|
219
219
|
method: "eth_requestAccounts"
|
|
220
220
|
});
|
|
221
|
-
const account =
|
|
221
|
+
const account = getAddress(accounts[0]);
|
|
222
222
|
let id = await this.getChainId();
|
|
223
223
|
let unsupported = this.isChainUnsupported(id);
|
|
224
224
|
if (chainId && id !== chainId) {
|
|
@@ -227,46 +227,46 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
227
227
|
unsupported = this.isChainUnsupported(id);
|
|
228
228
|
}
|
|
229
229
|
if (this.options.shimDisconnect)
|
|
230
|
-
|
|
230
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
231
231
|
return { account, chain: { id, unsupported } };
|
|
232
232
|
} catch (error) {
|
|
233
233
|
if (this.isUserRejectedRequestError(error))
|
|
234
|
-
throw new
|
|
234
|
+
throw new UserRejectedRequestError(error);
|
|
235
235
|
if (error.code === -32002)
|
|
236
|
-
throw new
|
|
236
|
+
throw new ResourceUnavailableRpcError(error);
|
|
237
237
|
throw error;
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
async disconnect() {
|
|
241
241
|
const provider = await this.getProvider();
|
|
242
|
-
if (!
|
|
242
|
+
if (!provider?.removeListener)
|
|
243
243
|
return;
|
|
244
244
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
245
245
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
246
246
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
247
247
|
if (this.options.shimDisconnect)
|
|
248
|
-
|
|
248
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
249
249
|
}
|
|
250
250
|
async getAccount() {
|
|
251
251
|
const provider = await this.getProvider();
|
|
252
252
|
if (!provider)
|
|
253
|
-
throw new
|
|
253
|
+
throw new ConnectorNotFoundError();
|
|
254
254
|
const accounts = await provider.request({
|
|
255
255
|
method: "eth_accounts"
|
|
256
256
|
});
|
|
257
|
-
return
|
|
257
|
+
return getAddress(accounts[0]);
|
|
258
258
|
}
|
|
259
259
|
async getChainId() {
|
|
260
260
|
const provider = await this.getProvider();
|
|
261
261
|
if (!provider)
|
|
262
|
-
throw new
|
|
263
|
-
return provider.request({ method: "eth_chainId" }).then(
|
|
262
|
+
throw new ConnectorNotFoundError();
|
|
263
|
+
return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
|
|
264
264
|
}
|
|
265
265
|
async getProvider() {
|
|
266
266
|
const provider = this.options.getProvider();
|
|
267
267
|
if (provider)
|
|
268
|
-
|
|
269
|
-
return
|
|
268
|
+
__privateSet(this, _provider, provider);
|
|
269
|
+
return __privateGet(this, _provider);
|
|
270
270
|
}
|
|
271
271
|
async getWalletClient({
|
|
272
272
|
chainId
|
|
@@ -278,30 +278,30 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
278
278
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
279
279
|
if (!provider)
|
|
280
280
|
throw new Error("provider is required.");
|
|
281
|
-
return
|
|
281
|
+
return createWalletClient({
|
|
282
282
|
account,
|
|
283
283
|
chain,
|
|
284
|
-
transport:
|
|
284
|
+
transport: custom(provider)
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
async isAuthorized() {
|
|
288
288
|
try {
|
|
289
|
-
if (this.options.shimDisconnect && !
|
|
289
|
+
if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
|
|
290
290
|
return false;
|
|
291
291
|
const provider = await this.getProvider();
|
|
292
292
|
if (!provider)
|
|
293
|
-
throw new
|
|
293
|
+
throw new ConnectorNotFoundError();
|
|
294
294
|
const account = await this.getAccount();
|
|
295
295
|
return !!account;
|
|
296
|
-
} catch
|
|
296
|
+
} catch {
|
|
297
297
|
return false;
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
async switchChain(chainId) {
|
|
301
301
|
const provider = await this.getProvider();
|
|
302
302
|
if (!provider)
|
|
303
|
-
throw new
|
|
304
|
-
const id =
|
|
303
|
+
throw new ConnectorNotFoundError();
|
|
304
|
+
const id = numberToHex(chainId);
|
|
305
305
|
try {
|
|
306
306
|
await Promise.all([
|
|
307
307
|
provider.request({
|
|
@@ -310,26 +310,26 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
310
310
|
}),
|
|
311
311
|
new Promise(
|
|
312
312
|
(res) => this.on("change", ({ chain }) => {
|
|
313
|
-
if (
|
|
313
|
+
if (chain?.id === chainId)
|
|
314
314
|
res();
|
|
315
315
|
})
|
|
316
316
|
)
|
|
317
317
|
]);
|
|
318
|
-
return
|
|
318
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
319
319
|
id: chainId,
|
|
320
320
|
name: `Chain ${id}`,
|
|
321
321
|
network: `${id}`,
|
|
322
322
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
323
323
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
324
|
-
}
|
|
324
|
+
};
|
|
325
325
|
} catch (error) {
|
|
326
326
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
327
327
|
if (!chain)
|
|
328
|
-
throw new
|
|
328
|
+
throw new ChainNotConfiguredForConnectorError({
|
|
329
329
|
chainId,
|
|
330
330
|
connectorId: this.id
|
|
331
331
|
});
|
|
332
|
-
if (error.code === 4902 ||
|
|
332
|
+
if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
|
|
333
333
|
try {
|
|
334
334
|
await provider.request({
|
|
335
335
|
method: "wallet_addEthereumChain",
|
|
@@ -338,24 +338,24 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
338
338
|
chainId: id,
|
|
339
339
|
chainName: chain.name,
|
|
340
340
|
nativeCurrency: chain.nativeCurrency,
|
|
341
|
-
rpcUrls: [
|
|
341
|
+
rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
|
|
342
342
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
343
343
|
}
|
|
344
344
|
]
|
|
345
345
|
});
|
|
346
346
|
const currentChainId = await this.getChainId();
|
|
347
347
|
if (currentChainId !== chainId)
|
|
348
|
-
throw new
|
|
348
|
+
throw new UserRejectedRequestError(
|
|
349
349
|
new Error("User rejected switch after adding network.")
|
|
350
350
|
);
|
|
351
351
|
return chain;
|
|
352
352
|
} catch (error2) {
|
|
353
|
-
throw new
|
|
353
|
+
throw new UserRejectedRequestError(error2);
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
if (this.isUserRejectedRequestError(error))
|
|
357
|
-
throw new
|
|
358
|
-
throw new
|
|
357
|
+
throw new UserRejectedRequestError(error);
|
|
358
|
+
throw new SwitchChainError(error);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
async watchAsset({
|
|
@@ -366,7 +366,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
366
366
|
}) {
|
|
367
367
|
const provider = await this.getProvider();
|
|
368
368
|
if (!provider)
|
|
369
|
-
throw new
|
|
369
|
+
throw new ConnectorNotFoundError();
|
|
370
370
|
return provider.request({
|
|
371
371
|
method: "wallet_watchAsset",
|
|
372
372
|
params: {
|
|
@@ -386,6 +386,6 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
386
386
|
};
|
|
387
387
|
_provider = new WeakMap();
|
|
388
388
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
389
|
+
export {
|
|
390
|
+
InjectedConnector
|
|
391
|
+
};
|
package/dist/chunk-OQILYQDO.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/normalizeChainId.ts
|
|
2
2
|
function normalizeChainId(chainId) {
|
|
3
3
|
if (typeof chainId === "string")
|
|
4
4
|
return Number.parseInt(
|
|
@@ -10,6 +10,6 @@ function normalizeChainId(chainId) {
|
|
|
10
10
|
return chainId;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export {
|
|
14
|
+
normalizeChainId
|
|
15
|
+
};
|
package/dist/chunk-UGBGYVBH.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/errors.ts
|
|
2
2
|
var ChainNotConfiguredForConnectorError = class extends Error {
|
|
3
3
|
constructor({
|
|
4
4
|
chainId,
|
|
@@ -16,7 +16,7 @@ var ConnectorNotFoundError = class extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
export {
|
|
20
|
+
ChainNotConfiguredForConnectorError,
|
|
21
|
+
ConnectorNotFoundError
|
|
22
|
+
};
|
package/dist/chunk-W65LBPLT.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
var __accessCheck = (obj, member, msg) => {
|
|
2
2
|
if (!member.has(obj))
|
|
3
3
|
throw TypeError("Cannot " + msg);
|
|
4
4
|
};
|
|
@@ -22,11 +22,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
// src/base.ts
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var Connector = class extends
|
|
25
|
+
import { default as EventEmitter } from "eventemitter3";
|
|
26
|
+
import { goerli, mainnet } from "viem/chains";
|
|
27
|
+
var Connector = class extends EventEmitter {
|
|
28
28
|
constructor({
|
|
29
|
-
chains = [
|
|
29
|
+
chains = [mainnet, goerli],
|
|
30
30
|
options
|
|
31
31
|
}) {
|
|
32
32
|
super();
|
|
@@ -34,7 +34,7 @@ var Connector = class extends _eventemitter32.default {
|
|
|
34
34
|
this.options = options;
|
|
35
35
|
}
|
|
36
36
|
getBlockExplorerUrls(chain) {
|
|
37
|
-
const { default: blockExplorer, ...blockExplorers } =
|
|
37
|
+
const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers ?? {};
|
|
38
38
|
if (blockExplorer)
|
|
39
39
|
return [
|
|
40
40
|
blockExplorer.url,
|
|
@@ -49,10 +49,10 @@ var Connector = class extends _eventemitter32.default {
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
export {
|
|
53
|
+
__privateGet,
|
|
54
|
+
__privateAdd,
|
|
55
|
+
__privateSet,
|
|
56
|
+
__privateMethod,
|
|
57
|
+
Connector
|
|
58
|
+
};
|
package/dist/coinbaseWallet.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChainNotConfiguredForConnectorError
|
|
3
|
+
} from "./chunk-UGBGYVBH.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizeChainId
|
|
6
|
+
} from "./chunk-OQILYQDO.js";
|
|
7
|
+
import {
|
|
8
|
+
Connector,
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateSet
|
|
12
|
+
} from "./chunk-W65LBPLT.js";
|
|
13
13
|
|
|
14
14
|
// src/coinbaseWallet.ts
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
import {
|
|
16
|
+
SwitchChainError,
|
|
17
|
+
UserRejectedRequestError,
|
|
18
|
+
createWalletClient,
|
|
19
|
+
custom,
|
|
20
|
+
getAddress,
|
|
21
|
+
numberToHex
|
|
22
|
+
} from "viem";
|
|
23
23
|
var _client, _provider;
|
|
24
|
-
var CoinbaseWalletConnector = class extends
|
|
24
|
+
var CoinbaseWalletConnector = class extends Connector {
|
|
25
25
|
constructor({ chains, options }) {
|
|
26
26
|
super({
|
|
27
27
|
chains,
|
|
@@ -33,16 +33,16 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
33
33
|
this.id = "coinbaseWallet";
|
|
34
34
|
this.name = "Coinbase Wallet";
|
|
35
35
|
this.ready = true;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
__privateAdd(this, _client, void 0);
|
|
37
|
+
__privateAdd(this, _provider, void 0);
|
|
38
38
|
this.onAccountsChanged = (accounts) => {
|
|
39
39
|
if (accounts.length === 0)
|
|
40
40
|
this.emit("disconnect");
|
|
41
41
|
else
|
|
42
|
-
this.emit("change", { account:
|
|
42
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
43
43
|
};
|
|
44
44
|
this.onChainChanged = (chainId) => {
|
|
45
|
-
const id =
|
|
45
|
+
const id = normalizeChainId(chainId);
|
|
46
46
|
const unsupported = this.isChainUnsupported(id);
|
|
47
47
|
this.emit("change", { chain: { id, unsupported } });
|
|
48
48
|
};
|
|
@@ -58,7 +58,7 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
58
58
|
provider.on("disconnect", this.onDisconnect);
|
|
59
59
|
this.emit("message", { type: "connecting" });
|
|
60
60
|
const accounts = await provider.enable();
|
|
61
|
-
const account =
|
|
61
|
+
const account = getAddress(accounts[0]);
|
|
62
62
|
let id = await this.getChainId();
|
|
63
63
|
let unsupported = this.isChainUnsupported(id);
|
|
64
64
|
if (chainId && id !== chainId) {
|
|
@@ -74,12 +74,12 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
74
74
|
if (/(user closed modal|accounts received is empty)/i.test(
|
|
75
75
|
error.message
|
|
76
76
|
))
|
|
77
|
-
throw new
|
|
77
|
+
throw new UserRejectedRequestError(error);
|
|
78
78
|
throw error;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
async disconnect() {
|
|
82
|
-
if (!
|
|
82
|
+
if (!__privateGet(this, _provider))
|
|
83
83
|
return;
|
|
84
84
|
const provider = await this.getProvider();
|
|
85
85
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
@@ -93,32 +93,32 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
93
93
|
const accounts = await provider.request({
|
|
94
94
|
method: "eth_accounts"
|
|
95
95
|
});
|
|
96
|
-
return
|
|
96
|
+
return getAddress(accounts[0]);
|
|
97
97
|
}
|
|
98
98
|
async getChainId() {
|
|
99
99
|
const provider = await this.getProvider();
|
|
100
|
-
const chainId =
|
|
100
|
+
const chainId = normalizeChainId(provider.chainId);
|
|
101
101
|
return chainId;
|
|
102
102
|
}
|
|
103
103
|
async getProvider() {
|
|
104
|
-
if (!
|
|
105
|
-
let CoinbaseWalletSDK = (await
|
|
104
|
+
if (!__privateGet(this, _provider)) {
|
|
105
|
+
let CoinbaseWalletSDK = (await import("@coinbase/wallet-sdk")).default;
|
|
106
106
|
if (typeof CoinbaseWalletSDK !== "function" && typeof CoinbaseWalletSDK.default === "function")
|
|
107
107
|
CoinbaseWalletSDK = CoinbaseWalletSDK.default;
|
|
108
|
-
|
|
108
|
+
__privateSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
109
109
|
class WalletProvider {
|
|
110
110
|
}
|
|
111
111
|
class Client {
|
|
112
112
|
}
|
|
113
|
-
const walletExtensionChainId =
|
|
113
|
+
const walletExtensionChainId = __privateGet(this, _client).walletExtension?.getChainId();
|
|
114
114
|
const chain = this.chains.find(
|
|
115
115
|
(chain2) => this.options.chainId ? chain2.id === this.options.chainId : chain2.id === walletExtensionChainId
|
|
116
116
|
) || this.chains[0];
|
|
117
|
-
const chainId = this.options.chainId ||
|
|
118
|
-
const jsonRpcUrl = this.options.jsonRpcUrl ||
|
|
119
|
-
|
|
117
|
+
const chainId = this.options.chainId || chain?.id;
|
|
118
|
+
const jsonRpcUrl = this.options.jsonRpcUrl || chain?.rpcUrls.default.http[0];
|
|
119
|
+
__privateSet(this, _provider, __privateGet(this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
|
|
120
120
|
}
|
|
121
|
-
return
|
|
121
|
+
return __privateGet(this, _provider);
|
|
122
122
|
}
|
|
123
123
|
async getWalletClient({
|
|
124
124
|
chainId
|
|
@@ -130,39 +130,39 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
130
130
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
131
131
|
if (!provider)
|
|
132
132
|
throw new Error("provider is required.");
|
|
133
|
-
return
|
|
133
|
+
return createWalletClient({
|
|
134
134
|
account,
|
|
135
135
|
chain,
|
|
136
|
-
transport:
|
|
136
|
+
transport: custom(provider)
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
async isAuthorized() {
|
|
140
140
|
try {
|
|
141
141
|
const account = await this.getAccount();
|
|
142
142
|
return !!account;
|
|
143
|
-
} catch
|
|
143
|
+
} catch {
|
|
144
144
|
return false;
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
async switchChain(chainId) {
|
|
148
148
|
const provider = await this.getProvider();
|
|
149
|
-
const id =
|
|
149
|
+
const id = numberToHex(chainId);
|
|
150
150
|
try {
|
|
151
151
|
await provider.request({
|
|
152
152
|
method: "wallet_switchEthereumChain",
|
|
153
153
|
params: [{ chainId: id }]
|
|
154
154
|
});
|
|
155
|
-
return
|
|
155
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
156
156
|
id: chainId,
|
|
157
157
|
name: `Chain ${id}`,
|
|
158
158
|
network: `${id}`,
|
|
159
159
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
160
160
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
161
|
-
}
|
|
161
|
+
};
|
|
162
162
|
} catch (error) {
|
|
163
163
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
164
164
|
if (!chain)
|
|
165
|
-
throw new
|
|
165
|
+
throw new ChainNotConfiguredForConnectorError({
|
|
166
166
|
chainId,
|
|
167
167
|
connectorId: this.id
|
|
168
168
|
});
|
|
@@ -175,17 +175,17 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
175
175
|
chainId: id,
|
|
176
176
|
chainName: chain.name,
|
|
177
177
|
nativeCurrency: chain.nativeCurrency,
|
|
178
|
-
rpcUrls: [
|
|
178
|
+
rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
|
|
179
179
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
180
180
|
}
|
|
181
181
|
]
|
|
182
182
|
});
|
|
183
183
|
return chain;
|
|
184
184
|
} catch (error2) {
|
|
185
|
-
throw new
|
|
185
|
+
throw new UserRejectedRequestError(error2);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
throw new
|
|
188
|
+
throw new SwitchChainError(error);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
async watchAsset({
|
|
@@ -211,6 +211,6 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
211
211
|
};
|
|
212
212
|
_client = new WeakMap();
|
|
213
213
|
_provider = new WeakMap();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
export {
|
|
215
|
+
CoinbaseWalletConnector
|
|
216
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChainNotConfiguredForConnectorError,
|
|
3
|
+
ConnectorNotFoundError
|
|
4
|
+
} from "./chunk-UGBGYVBH.js";
|
|
5
|
+
import {
|
|
6
|
+
normalizeChainId
|
|
7
|
+
} from "./chunk-OQILYQDO.js";
|
|
8
|
+
import {
|
|
9
|
+
Connector
|
|
10
|
+
} from "./chunk-W65LBPLT.js";
|
|
11
|
+
export {
|
|
12
|
+
ChainNotConfiguredForConnectorError,
|
|
13
|
+
Connector,
|
|
14
|
+
ConnectorNotFoundError,
|
|
15
|
+
normalizeChainId
|
|
16
|
+
};
|
package/dist/injected.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import {
|
|
2
|
+
InjectedConnector
|
|
3
|
+
} from "./chunk-2UFLHRLT.js";
|
|
4
|
+
import "./chunk-UGBGYVBH.js";
|
|
5
|
+
import "./chunk-OQILYQDO.js";
|
|
6
|
+
import "./chunk-W65LBPLT.js";
|
|
7
|
+
export {
|
|
8
|
+
InjectedConnector
|
|
9
|
+
};
|