@wagmi/connectors 2.6.2-cjs → 2.6.3
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/coinbaseWallet/package.json +1 -1
- package/dist/chunk-OQILYQDO.js +4 -4
- package/dist/chunk-QRUHVNWK.js +73 -73
- package/dist/chunk-QYMCVNHT.js +14 -14
- package/dist/chunk-ZCAPXGBX.js +10 -10
- package/dist/coinbaseWallet.js +58 -58
- package/dist/index.js +16 -16
- package/dist/injected.js +9 -9
- package/dist/ledger.js +83 -83
- package/dist/metaMask.js +37 -37
- package/dist/mock/index.js +63 -63
- package/dist/safe.js +46 -46
- package/dist/walletConnect.d.ts +6 -1
- package/dist/walletConnect.js +109 -111
- package/dist/walletConnectLegacy.js +58 -58
- package/injected/package.json +1 -1
- package/ledger/package.json +1 -1
- package/metaMask/package.json +1 -1
- package/mock/package.json +1 -1
- package/package.json +44 -4
- package/safe/package.json +1 -1
- package/walletConnect/package.json +1 -1
- package/walletConnectLegacy/package.json +1 -1
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-QRUHVNWK.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChainNotConfiguredForConnectorError,
|
|
3
|
+
ConnectorNotFoundError
|
|
4
|
+
} from "./chunk-ZCAPXGBX.js";
|
|
5
|
+
import {
|
|
6
|
+
normalizeChainId
|
|
7
|
+
} from "./chunk-OQILYQDO.js";
|
|
8
|
+
import {
|
|
9
|
+
Connector,
|
|
10
|
+
__privateAdd,
|
|
11
|
+
__privateGet,
|
|
12
|
+
__privateSet,
|
|
13
|
+
__publicField
|
|
14
|
+
} from "./chunk-QYMCVNHT.js";
|
|
15
15
|
|
|
16
16
|
// src/injected.ts
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
import {
|
|
18
|
+
ResourceUnavailableRpcError,
|
|
19
|
+
SwitchChainError,
|
|
20
|
+
UserRejectedRequestError,
|
|
21
|
+
createWalletClient,
|
|
22
|
+
custom,
|
|
23
|
+
getAddress,
|
|
24
|
+
numberToHex
|
|
25
|
+
} from "viem";
|
|
26
26
|
|
|
27
27
|
// src/utils/getInjectedName.ts
|
|
28
28
|
function getInjectedName(ethereum) {
|
|
@@ -110,7 +110,7 @@ function getInjectedName(ethereum) {
|
|
|
110
110
|
if (provider.isMetaMask)
|
|
111
111
|
return "MetaMask";
|
|
112
112
|
};
|
|
113
|
-
if (
|
|
113
|
+
if (ethereum.providers?.length) {
|
|
114
114
|
const nameSet = /* @__PURE__ */ new Set();
|
|
115
115
|
let unknownCount = 1;
|
|
116
116
|
for (const provider of ethereum.providers) {
|
|
@@ -124,14 +124,14 @@ function getInjectedName(ethereum) {
|
|
|
124
124
|
const names = [...nameSet];
|
|
125
125
|
if (names.length)
|
|
126
126
|
return names;
|
|
127
|
-
return
|
|
127
|
+
return names[0] ?? "Injected";
|
|
128
128
|
}
|
|
129
|
-
return
|
|
129
|
+
return getName(ethereum) ?? "Injected";
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// src/injected.ts
|
|
133
133
|
var _provider;
|
|
134
|
-
var InjectedConnector = class extends
|
|
134
|
+
var InjectedConnector = class extends Connector {
|
|
135
135
|
constructor({
|
|
136
136
|
chains,
|
|
137
137
|
options: options_
|
|
@@ -142,32 +142,32 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
142
142
|
if (typeof window === "undefined")
|
|
143
143
|
return;
|
|
144
144
|
const ethereum = window.ethereum;
|
|
145
|
-
if (
|
|
145
|
+
if (ethereum?.providers)
|
|
146
146
|
return ethereum.providers[0];
|
|
147
147
|
return ethereum;
|
|
148
148
|
},
|
|
149
149
|
...options_
|
|
150
150
|
};
|
|
151
151
|
super({ chains, options });
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
__publicField(this, "id", "injected");
|
|
153
|
+
__publicField(this, "name");
|
|
154
|
+
__publicField(this, "ready");
|
|
155
|
+
__privateAdd(this, _provider, void 0);
|
|
156
|
+
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
157
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
158
158
|
if (accounts.length === 0)
|
|
159
159
|
this.emit("disconnect");
|
|
160
160
|
else
|
|
161
161
|
this.emit("change", {
|
|
162
|
-
account:
|
|
162
|
+
account: getAddress(accounts[0])
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
|
-
|
|
166
|
-
const id =
|
|
165
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
166
|
+
const id = normalizeChainId(chainId);
|
|
167
167
|
const unsupported = this.isChainUnsupported(id);
|
|
168
168
|
this.emit("change", { chain: { id, unsupported } });
|
|
169
169
|
});
|
|
170
|
-
|
|
170
|
+
__publicField(this, "onDisconnect", async (error) => {
|
|
171
171
|
if (error.code === 1013) {
|
|
172
172
|
const provider = await this.getProvider();
|
|
173
173
|
if (provider) {
|
|
@@ -178,7 +178,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
178
178
|
}
|
|
179
179
|
this.emit("disconnect");
|
|
180
180
|
if (this.options.shimDisconnect)
|
|
181
|
-
|
|
181
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
182
182
|
});
|
|
183
183
|
const provider = options.getProvider();
|
|
184
184
|
if (typeof options.name === "string")
|
|
@@ -201,7 +201,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
201
201
|
try {
|
|
202
202
|
const provider = await this.getProvider();
|
|
203
203
|
if (!provider)
|
|
204
|
-
throw new
|
|
204
|
+
throw new ConnectorNotFoundError();
|
|
205
205
|
if (provider.on) {
|
|
206
206
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
207
207
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -211,7 +211,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
211
211
|
const accounts = await provider.request({
|
|
212
212
|
method: "eth_requestAccounts"
|
|
213
213
|
});
|
|
214
|
-
const account =
|
|
214
|
+
const account = getAddress(accounts[0]);
|
|
215
215
|
let id = await this.getChainId();
|
|
216
216
|
let unsupported = this.isChainUnsupported(id);
|
|
217
217
|
if (chainId && id !== chainId) {
|
|
@@ -220,46 +220,46 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
220
220
|
unsupported = this.isChainUnsupported(id);
|
|
221
221
|
}
|
|
222
222
|
if (this.options.shimDisconnect)
|
|
223
|
-
|
|
223
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
224
224
|
return { account, chain: { id, unsupported } };
|
|
225
225
|
} catch (error) {
|
|
226
226
|
if (this.isUserRejectedRequestError(error))
|
|
227
|
-
throw new
|
|
227
|
+
throw new UserRejectedRequestError(error);
|
|
228
228
|
if (error.code === -32002)
|
|
229
|
-
throw new
|
|
229
|
+
throw new ResourceUnavailableRpcError(error);
|
|
230
230
|
throw error;
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
async disconnect() {
|
|
234
234
|
const provider = await this.getProvider();
|
|
235
|
-
if (!
|
|
235
|
+
if (!provider?.removeListener)
|
|
236
236
|
return;
|
|
237
237
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
238
238
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
239
239
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
240
240
|
if (this.options.shimDisconnect)
|
|
241
|
-
|
|
241
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
242
242
|
}
|
|
243
243
|
async getAccount() {
|
|
244
244
|
const provider = await this.getProvider();
|
|
245
245
|
if (!provider)
|
|
246
|
-
throw new
|
|
246
|
+
throw new ConnectorNotFoundError();
|
|
247
247
|
const accounts = await provider.request({
|
|
248
248
|
method: "eth_accounts"
|
|
249
249
|
});
|
|
250
|
-
return
|
|
250
|
+
return getAddress(accounts[0]);
|
|
251
251
|
}
|
|
252
252
|
async getChainId() {
|
|
253
253
|
const provider = await this.getProvider();
|
|
254
254
|
if (!provider)
|
|
255
|
-
throw new
|
|
256
|
-
return provider.request({ method: "eth_chainId" }).then(
|
|
255
|
+
throw new ConnectorNotFoundError();
|
|
256
|
+
return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
|
|
257
257
|
}
|
|
258
258
|
async getProvider() {
|
|
259
259
|
const provider = this.options.getProvider();
|
|
260
260
|
if (provider)
|
|
261
|
-
|
|
262
|
-
return
|
|
261
|
+
__privateSet(this, _provider, provider);
|
|
262
|
+
return __privateGet(this, _provider);
|
|
263
263
|
}
|
|
264
264
|
async getWalletClient({
|
|
265
265
|
chainId
|
|
@@ -271,30 +271,30 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
271
271
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
272
272
|
if (!provider)
|
|
273
273
|
throw new Error("provider is required.");
|
|
274
|
-
return
|
|
274
|
+
return createWalletClient({
|
|
275
275
|
account,
|
|
276
276
|
chain,
|
|
277
|
-
transport:
|
|
277
|
+
transport: custom(provider)
|
|
278
278
|
});
|
|
279
279
|
}
|
|
280
280
|
async isAuthorized() {
|
|
281
281
|
try {
|
|
282
|
-
if (this.options.shimDisconnect && !
|
|
282
|
+
if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
|
|
283
283
|
return false;
|
|
284
284
|
const provider = await this.getProvider();
|
|
285
285
|
if (!provider)
|
|
286
|
-
throw new
|
|
286
|
+
throw new ConnectorNotFoundError();
|
|
287
287
|
const account = await this.getAccount();
|
|
288
288
|
return !!account;
|
|
289
|
-
} catch
|
|
289
|
+
} catch {
|
|
290
290
|
return false;
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
async switchChain(chainId) {
|
|
294
294
|
const provider = await this.getProvider();
|
|
295
295
|
if (!provider)
|
|
296
|
-
throw new
|
|
297
|
-
const id =
|
|
296
|
+
throw new ConnectorNotFoundError();
|
|
297
|
+
const id = numberToHex(chainId);
|
|
298
298
|
try {
|
|
299
299
|
await Promise.all([
|
|
300
300
|
provider.request({
|
|
@@ -303,26 +303,26 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
303
303
|
}),
|
|
304
304
|
new Promise(
|
|
305
305
|
(res) => this.on("change", ({ chain }) => {
|
|
306
|
-
if (
|
|
306
|
+
if (chain?.id === chainId)
|
|
307
307
|
res();
|
|
308
308
|
})
|
|
309
309
|
)
|
|
310
310
|
]);
|
|
311
|
-
return
|
|
311
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
312
312
|
id: chainId,
|
|
313
313
|
name: `Chain ${id}`,
|
|
314
314
|
network: `${id}`,
|
|
315
315
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
316
316
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
317
|
-
}
|
|
317
|
+
};
|
|
318
318
|
} catch (error) {
|
|
319
319
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
320
320
|
if (!chain)
|
|
321
|
-
throw new
|
|
321
|
+
throw new ChainNotConfiguredForConnectorError({
|
|
322
322
|
chainId,
|
|
323
323
|
connectorId: this.id
|
|
324
324
|
});
|
|
325
|
-
if (error.code === 4902 ||
|
|
325
|
+
if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
|
|
326
326
|
try {
|
|
327
327
|
await provider.request({
|
|
328
328
|
method: "wallet_addEthereumChain",
|
|
@@ -331,24 +331,24 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
331
331
|
chainId: id,
|
|
332
332
|
chainName: chain.name,
|
|
333
333
|
nativeCurrency: chain.nativeCurrency,
|
|
334
|
-
rpcUrls: [
|
|
334
|
+
rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
|
|
335
335
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
336
336
|
}
|
|
337
337
|
]
|
|
338
338
|
});
|
|
339
339
|
const currentChainId = await this.getChainId();
|
|
340
340
|
if (currentChainId !== chainId)
|
|
341
|
-
throw new
|
|
341
|
+
throw new UserRejectedRequestError(
|
|
342
342
|
new Error("User rejected switch after adding network.")
|
|
343
343
|
);
|
|
344
344
|
return chain;
|
|
345
345
|
} catch (error2) {
|
|
346
|
-
throw new
|
|
346
|
+
throw new UserRejectedRequestError(error2);
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
if (this.isUserRejectedRequestError(error))
|
|
350
|
-
throw new
|
|
351
|
-
throw new
|
|
350
|
+
throw new UserRejectedRequestError(error);
|
|
351
|
+
throw new SwitchChainError(error);
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
async watchAsset({
|
|
@@ -359,7 +359,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
359
359
|
}) {
|
|
360
360
|
const provider = await this.getProvider();
|
|
361
361
|
if (!provider)
|
|
362
|
-
throw new
|
|
362
|
+
throw new ConnectorNotFoundError();
|
|
363
363
|
return provider.request({
|
|
364
364
|
method: "wallet_watchAsset",
|
|
365
365
|
params: {
|
|
@@ -379,6 +379,6 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
379
379
|
};
|
|
380
380
|
_provider = new WeakMap();
|
|
381
381
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
382
|
+
export {
|
|
383
|
+
InjectedConnector
|
|
384
|
+
};
|
package/dist/chunk-QYMCVNHT.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => {
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -28,11 +28,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// src/base.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var Connector = class extends
|
|
31
|
+
import { default as EventEmitter } from "eventemitter3";
|
|
32
|
+
import { goerli, mainnet } from "viem/chains";
|
|
33
|
+
var Connector = class extends EventEmitter {
|
|
34
34
|
constructor({
|
|
35
|
-
chains = [
|
|
35
|
+
chains = [mainnet, goerli],
|
|
36
36
|
options
|
|
37
37
|
}) {
|
|
38
38
|
super();
|
|
@@ -43,7 +43,7 @@ var Connector = class extends _eventemitter32.default {
|
|
|
43
43
|
this.options = options;
|
|
44
44
|
}
|
|
45
45
|
getBlockExplorerUrls(chain) {
|
|
46
|
-
const { default: blockExplorer, ...blockExplorers } =
|
|
46
|
+
const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers ?? {};
|
|
47
47
|
if (blockExplorer)
|
|
48
48
|
return [
|
|
49
49
|
blockExplorer.url,
|
|
@@ -58,11 +58,11 @@ var Connector = class extends _eventemitter32.default {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
export {
|
|
62
|
+
__publicField,
|
|
63
|
+
__privateGet,
|
|
64
|
+
__privateAdd,
|
|
65
|
+
__privateSet,
|
|
66
|
+
__privateMethod,
|
|
67
|
+
Connector
|
|
68
|
+
};
|
package/dist/chunk-ZCAPXGBX.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "./chunk-QYMCVNHT.js";
|
|
4
4
|
|
|
5
5
|
// src/errors.ts
|
|
6
6
|
var ChainNotConfiguredForConnectorError = class extends Error {
|
|
@@ -9,18 +9,18 @@ var ChainNotConfiguredForConnectorError = class extends Error {
|
|
|
9
9
|
connectorId
|
|
10
10
|
}) {
|
|
11
11
|
super(`Chain "${chainId}" not configured for connector "${connectorId}".`);
|
|
12
|
-
|
|
12
|
+
__publicField(this, "name", "ChainNotConfiguredForConnectorError");
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
var ConnectorNotFoundError = class extends Error {
|
|
16
16
|
constructor() {
|
|
17
17
|
super(...arguments);
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
__publicField(this, "name", "ConnectorNotFoundError");
|
|
19
|
+
__publicField(this, "message", "Connector not found");
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
export {
|
|
24
|
+
ChainNotConfiguredForConnectorError,
|
|
25
|
+
ConnectorNotFoundError
|
|
26
|
+
};
|