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