@wagmi/connectors 2.3.0-cjs → 2.3.0
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-4BSCIAHY.js +73 -73
- package/dist/chunk-OQILYQDO.js +4 -4
- package/dist/chunk-QYMCVNHT.js +14 -14
- package/dist/chunk-ZCAPXGBX.js +10 -10
- package/dist/coinbaseWallet.js +58 -58
- package/dist/index.js +12 -12
- package/dist/injected.js +9 -9
- package/dist/ledger.js +60 -60
- package/dist/metaMask.js +37 -37
- package/dist/mock/index.js +63 -63
- package/dist/safe.js +46 -46
- package/dist/walletConnect.js +105 -105
- 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 +42 -2
- package/safe/package.json +1 -1
- package/walletConnect/package.json +1 -1
- package/walletConnectLegacy/package.json +1 -1
package/dist/chunk-4BSCIAHY.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) {
|
|
@@ -108,7 +108,7 @@ function getInjectedName(ethereum) {
|
|
|
108
108
|
if (provider.isMetaMask)
|
|
109
109
|
return "MetaMask";
|
|
110
110
|
};
|
|
111
|
-
if (
|
|
111
|
+
if (ethereum.providers?.length) {
|
|
112
112
|
const nameSet = /* @__PURE__ */ new Set();
|
|
113
113
|
let unknownCount = 1;
|
|
114
114
|
for (const provider of ethereum.providers) {
|
|
@@ -122,14 +122,14 @@ function getInjectedName(ethereum) {
|
|
|
122
122
|
const names = [...nameSet];
|
|
123
123
|
if (names.length)
|
|
124
124
|
return names;
|
|
125
|
-
return
|
|
125
|
+
return names[0] ?? "Injected";
|
|
126
126
|
}
|
|
127
|
-
return
|
|
127
|
+
return getName(ethereum) ?? "Injected";
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// src/injected.ts
|
|
131
131
|
var _provider;
|
|
132
|
-
var InjectedConnector = class extends
|
|
132
|
+
var InjectedConnector = class extends Connector {
|
|
133
133
|
constructor({
|
|
134
134
|
chains,
|
|
135
135
|
options: options_
|
|
@@ -140,32 +140,32 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
140
140
|
if (typeof window === "undefined")
|
|
141
141
|
return;
|
|
142
142
|
const ethereum = window.ethereum;
|
|
143
|
-
if (
|
|
143
|
+
if (ethereum?.providers)
|
|
144
144
|
return ethereum.providers[0];
|
|
145
145
|
return ethereum;
|
|
146
146
|
},
|
|
147
147
|
...options_
|
|
148
148
|
};
|
|
149
149
|
super({ chains, options });
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
__publicField(this, "id", "injected");
|
|
151
|
+
__publicField(this, "name");
|
|
152
|
+
__publicField(this, "ready");
|
|
153
|
+
__privateAdd(this, _provider, void 0);
|
|
154
|
+
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
155
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
156
156
|
if (accounts.length === 0)
|
|
157
157
|
this.emit("disconnect");
|
|
158
158
|
else
|
|
159
159
|
this.emit("change", {
|
|
160
|
-
account:
|
|
160
|
+
account: getAddress(accounts[0])
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
|
-
|
|
164
|
-
const id =
|
|
163
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
164
|
+
const id = normalizeChainId(chainId);
|
|
165
165
|
const unsupported = this.isChainUnsupported(id);
|
|
166
166
|
this.emit("change", { chain: { id, unsupported } });
|
|
167
167
|
});
|
|
168
|
-
|
|
168
|
+
__publicField(this, "onDisconnect", async (error) => {
|
|
169
169
|
if (error.code === 1013) {
|
|
170
170
|
const provider = await this.getProvider();
|
|
171
171
|
if (provider) {
|
|
@@ -176,7 +176,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
176
176
|
}
|
|
177
177
|
this.emit("disconnect");
|
|
178
178
|
if (this.options.shimDisconnect)
|
|
179
|
-
|
|
179
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
180
180
|
});
|
|
181
181
|
const provider = options.getProvider();
|
|
182
182
|
if (typeof options.name === "string")
|
|
@@ -199,7 +199,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
199
199
|
try {
|
|
200
200
|
const provider = await this.getProvider();
|
|
201
201
|
if (!provider)
|
|
202
|
-
throw new
|
|
202
|
+
throw new ConnectorNotFoundError();
|
|
203
203
|
if (provider.on) {
|
|
204
204
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
205
205
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -209,7 +209,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
209
209
|
const accounts = await provider.request({
|
|
210
210
|
method: "eth_requestAccounts"
|
|
211
211
|
});
|
|
212
|
-
const account =
|
|
212
|
+
const account = getAddress(accounts[0]);
|
|
213
213
|
let id = await this.getChainId();
|
|
214
214
|
let unsupported = this.isChainUnsupported(id);
|
|
215
215
|
if (chainId && id !== chainId) {
|
|
@@ -218,46 +218,46 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
218
218
|
unsupported = this.isChainUnsupported(id);
|
|
219
219
|
}
|
|
220
220
|
if (this.options.shimDisconnect)
|
|
221
|
-
|
|
221
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
222
222
|
return { account, chain: { id, unsupported } };
|
|
223
223
|
} catch (error) {
|
|
224
224
|
if (this.isUserRejectedRequestError(error))
|
|
225
|
-
throw new
|
|
225
|
+
throw new UserRejectedRequestError(error);
|
|
226
226
|
if (error.code === -32002)
|
|
227
|
-
throw new
|
|
227
|
+
throw new ResourceUnavailableRpcError(error);
|
|
228
228
|
throw error;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
async disconnect() {
|
|
232
232
|
const provider = await this.getProvider();
|
|
233
|
-
if (!
|
|
233
|
+
if (!provider?.removeListener)
|
|
234
234
|
return;
|
|
235
235
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
236
236
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
237
237
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
238
238
|
if (this.options.shimDisconnect)
|
|
239
|
-
|
|
239
|
+
this.storage?.removeItem(this.shimDisconnectKey);
|
|
240
240
|
}
|
|
241
241
|
async getAccount() {
|
|
242
242
|
const provider = await this.getProvider();
|
|
243
243
|
if (!provider)
|
|
244
|
-
throw new
|
|
244
|
+
throw new ConnectorNotFoundError();
|
|
245
245
|
const accounts = await provider.request({
|
|
246
246
|
method: "eth_accounts"
|
|
247
247
|
});
|
|
248
|
-
return
|
|
248
|
+
return getAddress(accounts[0]);
|
|
249
249
|
}
|
|
250
250
|
async getChainId() {
|
|
251
251
|
const provider = await this.getProvider();
|
|
252
252
|
if (!provider)
|
|
253
|
-
throw new
|
|
254
|
-
return provider.request({ method: "eth_chainId" }).then(
|
|
253
|
+
throw new ConnectorNotFoundError();
|
|
254
|
+
return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
|
|
255
255
|
}
|
|
256
256
|
async getProvider() {
|
|
257
257
|
const provider = this.options.getProvider();
|
|
258
258
|
if (provider)
|
|
259
|
-
|
|
260
|
-
return
|
|
259
|
+
__privateSet(this, _provider, provider);
|
|
260
|
+
return __privateGet(this, _provider);
|
|
261
261
|
}
|
|
262
262
|
async getWalletClient({ chainId } = {}) {
|
|
263
263
|
const [provider, account] = await Promise.all([
|
|
@@ -267,30 +267,30 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
267
267
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
268
268
|
if (!provider)
|
|
269
269
|
throw new Error("provider is required.");
|
|
270
|
-
return
|
|
270
|
+
return createWalletClient({
|
|
271
271
|
account,
|
|
272
272
|
chain,
|
|
273
|
-
transport:
|
|
273
|
+
transport: custom(provider)
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
276
|
async isAuthorized() {
|
|
277
277
|
try {
|
|
278
|
-
if (this.options.shimDisconnect && !
|
|
278
|
+
if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
|
|
279
279
|
return false;
|
|
280
280
|
const provider = await this.getProvider();
|
|
281
281
|
if (!provider)
|
|
282
|
-
throw new
|
|
282
|
+
throw new ConnectorNotFoundError();
|
|
283
283
|
const account = await this.getAccount();
|
|
284
284
|
return !!account;
|
|
285
|
-
} catch
|
|
285
|
+
} catch {
|
|
286
286
|
return false;
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
async switchChain(chainId) {
|
|
290
290
|
const provider = await this.getProvider();
|
|
291
291
|
if (!provider)
|
|
292
|
-
throw new
|
|
293
|
-
const id =
|
|
292
|
+
throw new ConnectorNotFoundError();
|
|
293
|
+
const id = numberToHex(chainId);
|
|
294
294
|
try {
|
|
295
295
|
await Promise.all([
|
|
296
296
|
provider.request({
|
|
@@ -299,26 +299,26 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
299
299
|
}),
|
|
300
300
|
new Promise(
|
|
301
301
|
(res) => this.on("change", ({ chain }) => {
|
|
302
|
-
if (
|
|
302
|
+
if (chain?.id === chainId)
|
|
303
303
|
res();
|
|
304
304
|
})
|
|
305
305
|
)
|
|
306
306
|
]);
|
|
307
|
-
return
|
|
307
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
308
308
|
id: chainId,
|
|
309
309
|
name: `Chain ${id}`,
|
|
310
310
|
network: `${id}`,
|
|
311
311
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
312
312
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
313
|
-
}
|
|
313
|
+
};
|
|
314
314
|
} catch (error) {
|
|
315
315
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
316
316
|
if (!chain)
|
|
317
|
-
throw new
|
|
317
|
+
throw new ChainNotConfiguredForConnectorError({
|
|
318
318
|
chainId,
|
|
319
319
|
connectorId: this.id
|
|
320
320
|
});
|
|
321
|
-
if (error.code === 4902 ||
|
|
321
|
+
if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
|
|
322
322
|
try {
|
|
323
323
|
await provider.request({
|
|
324
324
|
method: "wallet_addEthereumChain",
|
|
@@ -327,24 +327,24 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
327
327
|
chainId: id,
|
|
328
328
|
chainName: chain.name,
|
|
329
329
|
nativeCurrency: chain.nativeCurrency,
|
|
330
|
-
rpcUrls: [
|
|
330
|
+
rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
|
|
331
331
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
332
332
|
}
|
|
333
333
|
]
|
|
334
334
|
});
|
|
335
335
|
const currentChainId = await this.getChainId();
|
|
336
336
|
if (currentChainId !== chainId)
|
|
337
|
-
throw new
|
|
337
|
+
throw new UserRejectedRequestError(
|
|
338
338
|
new Error("User rejected switch after adding network.")
|
|
339
339
|
);
|
|
340
340
|
return chain;
|
|
341
341
|
} catch (error2) {
|
|
342
|
-
throw new
|
|
342
|
+
throw new UserRejectedRequestError(error2);
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
if (this.isUserRejectedRequestError(error))
|
|
346
|
-
throw new
|
|
347
|
-
throw new
|
|
346
|
+
throw new UserRejectedRequestError(error);
|
|
347
|
+
throw new SwitchChainError(error);
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
async watchAsset({
|
|
@@ -355,7 +355,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
355
355
|
}) {
|
|
356
356
|
const provider = await this.getProvider();
|
|
357
357
|
if (!provider)
|
|
358
|
-
throw new
|
|
358
|
+
throw new ConnectorNotFoundError();
|
|
359
359
|
return provider.request({
|
|
360
360
|
method: "wallet_watchAsset",
|
|
361
361
|
params: {
|
|
@@ -375,6 +375,6 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
375
375
|
};
|
|
376
376
|
_provider = new WeakMap();
|
|
377
377
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
378
|
+
export {
|
|
379
|
+
InjectedConnector
|
|
380
|
+
};
|
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-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
|
+
};
|