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