@wagmi/core 0.4.8 → 0.5.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/README.md +5 -5
- package/chains/dist/wagmi-core-chains.cjs.dev.js +2 -2
- package/chains/dist/wagmi-core-chains.cjs.prod.js +2 -2
- package/chains/dist/wagmi-core-chains.esm.js +2 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +28 -26
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +28 -26
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +5 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +22 -23
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +22 -23
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +7 -8
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +33 -31
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +33 -31
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +6 -4
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +24 -25
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +24 -25
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +5 -6
- package/dist/{chains-7e6dc59c.cjs.dev.js → chains-13baf029.cjs.prod.js} +4 -4
- package/dist/{chains-fd2c546c.esm.js → chains-4b1a6cf8.esm.js} +4 -4
- package/dist/{chains-f7bb3211.cjs.prod.js → chains-a1aae67e.cjs.dev.js} +4 -4
- package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +0 -1
- package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +3 -3
- package/dist/declarations/src/actions/contracts/deprecatedWriteContract.d.ts +16 -0
- package/dist/declarations/src/actions/{tokens → contracts}/fetchToken.d.ts +1 -0
- package/dist/declarations/src/actions/contracts/index.d.ts +4 -1
- package/dist/declarations/src/actions/contracts/prepareWriteContract.d.ts +37 -0
- package/dist/declarations/src/actions/contracts/writeContract.d.ts +44 -8
- package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +2 -1
- package/dist/declarations/src/actions/index.d.ts +2 -3
- package/dist/declarations/src/actions/transactions/deprecatedSendTransaction.d.ts +12 -0
- package/dist/declarations/src/actions/transactions/fetchTransaction.d.ts +21 -0
- package/dist/declarations/src/actions/transactions/index.d.ts +4 -1
- package/dist/declarations/src/actions/transactions/prepareSendTransaction.d.ts +36 -0
- package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +43 -8
- package/dist/declarations/src/client.d.ts +3 -3
- package/dist/declarations/src/connectors/base.d.ts +1 -2
- package/dist/declarations/src/connectors/coinbaseWallet.d.ts +2 -2
- package/dist/declarations/src/connectors/index.d.ts +1 -1
- package/dist/declarations/src/connectors/injected.d.ts +4 -4
- package/dist/declarations/src/connectors/metaMask.d.ts +1 -1
- package/dist/declarations/src/connectors/mock/provider.d.ts +3 -2
- package/dist/declarations/src/connectors/walletConnect.d.ts +3 -2
- package/dist/declarations/src/constants/index.d.ts +1 -1
- package/dist/declarations/src/constants/rpcs.d.ts +2 -2
- package/dist/declarations/src/errors.d.ts +10 -3
- package/dist/declarations/src/index.d.ts +5 -5
- package/dist/declarations/src/providers/alchemy.d.ts +2 -3
- package/dist/declarations/src/providers/infura.d.ts +2 -3
- package/dist/declarations/src/providers/jsonRpc.d.ts +1 -2
- package/dist/declarations/src/providers/public.d.ts +2 -4
- package/dist/declarations/src/types/index.d.ts +133 -129
- package/dist/declarations/src/utils/configureChains.d.ts +3 -1
- package/dist/declarations/src/utils/getInjectedName.d.ts +2 -1
- package/dist/{client-a6e61429.cjs.prod.js → getProvider-5b369460.cjs.prod.js} +449 -56
- package/dist/{client-a05fd511.esm.js → getProvider-dda5b21b.esm.js} +383 -14
- package/dist/{client-71ece661.cjs.dev.js → getProvider-e4848469.cjs.dev.js} +449 -56
- package/dist/{rpcs-1fd0a12f.cjs.prod.js → rpcs-3d4e8104.cjs.dev.js} +9 -9
- package/dist/{rpcs-f1d24f0e.cjs.dev.js → rpcs-4b3a7778.cjs.prod.js} +9 -9
- package/dist/{rpcs-b73a8f60.esm.js → rpcs-5dc0ea1f.esm.js} +8 -8
- package/dist/wagmi-core.cjs.dev.js +591 -298
- package/dist/wagmi-core.cjs.prod.js +591 -298
- package/dist/wagmi-core.esm.js +499 -213
- package/package.json +8 -4
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +5 -7
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +5 -7
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +5 -7
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +5 -7
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +5 -7
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +5 -7
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +0 -2
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +0 -2
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.cjs.dev.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.cjs.prod.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.esm.js +0 -2
- package/dist/base-797ad073.cjs.prod.js +0 -343
- package/dist/base-90b7f3e4.cjs.dev.js +0 -343
- package/dist/base-b565d5d4.esm.js +0 -316
- package/dist/declarations/src/actions/tokens/index.d.ts +0 -1
|
@@ -1,8 +1,306 @@
|
|
|
1
|
-
import { e as Connector, _ as _defineProperty, j as _classPrivateFieldInitSpec, n as normalizeChainId, k as _classPrivateFieldGet, l as _classPrivateFieldSet, c as ConnectorNotFoundError, U as UserRejectedRequestError, R as ResourceUnavailableError, f as ChainNotConfiguredError, A as AddChainError, i as SwitchChainError, m as _classPrivateMethodInitSpec, o as _classPrivateMethodGet } from './base-b565d5d4.esm.js';
|
|
2
|
-
import create from 'zustand/vanilla';
|
|
3
1
|
import { subscribeWithSelector, persist } from 'zustand/middleware';
|
|
2
|
+
import create from 'zustand/vanilla';
|
|
4
3
|
import { providers } from 'ethers';
|
|
5
4
|
import { getAddress, hexValue } from 'ethers/lib/utils';
|
|
5
|
+
import EventEmitter from 'eventemitter3';
|
|
6
|
+
import { d as defaultChains } from './chains-4b1a6cf8.esm.js';
|
|
7
|
+
|
|
8
|
+
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
9
|
+
if (privateCollection.has(obj)) {
|
|
10
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function _classPrivateMethodInitSpec(obj, privateSet) {
|
|
15
|
+
_checkPrivateRedeclaration(obj, privateSet);
|
|
16
|
+
privateSet.add(obj);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) {
|
|
20
|
+
_checkPrivateRedeclaration(obj, privateMap);
|
|
21
|
+
privateMap.set(obj, value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _defineProperty(obj, key, value) {
|
|
25
|
+
if (key in obj) {
|
|
26
|
+
Object.defineProperty(obj, key, {
|
|
27
|
+
value: value,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
obj[key] = value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
40
|
+
if (descriptor.get) {
|
|
41
|
+
return descriptor.get.call(receiver);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return descriptor.value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
48
|
+
if (!privateMap.has(receiver)) {
|
|
49
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return privateMap.get(receiver);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _classPrivateFieldGet(receiver, privateMap) {
|
|
56
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
57
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
61
|
+
if (!privateSet.has(receiver)) {
|
|
62
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return fn;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
69
|
+
if (descriptor.set) {
|
|
70
|
+
descriptor.set.call(receiver, value);
|
|
71
|
+
} else {
|
|
72
|
+
if (!descriptor.writable) {
|
|
73
|
+
throw new TypeError("attempted to set read only private field");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
descriptor.value = value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
81
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
82
|
+
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors per EIP-1474.
|
|
88
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474
|
|
89
|
+
*/
|
|
90
|
+
class RpcError extends Error {
|
|
91
|
+
constructor(
|
|
92
|
+
/** Number error code */
|
|
93
|
+
code,
|
|
94
|
+
/** Human-readable string */
|
|
95
|
+
message,
|
|
96
|
+
/** Low-level error */
|
|
97
|
+
internal,
|
|
98
|
+
/** Other useful information about error */
|
|
99
|
+
data) {
|
|
100
|
+
if (!Number.isInteger(code)) throw new Error('"code" must be an integer.');
|
|
101
|
+
if (!message || typeof message !== 'string') throw new Error('"message" must be a nonempty string.');
|
|
102
|
+
super(message);
|
|
103
|
+
|
|
104
|
+
_defineProperty(this, "code", void 0);
|
|
105
|
+
|
|
106
|
+
_defineProperty(this, "data", void 0);
|
|
107
|
+
|
|
108
|
+
_defineProperty(this, "internal", void 0);
|
|
109
|
+
|
|
110
|
+
this.code = code;
|
|
111
|
+
this.data = data;
|
|
112
|
+
this.internal = internal;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Error subclass implementing Ethereum Provider errors per EIP-1193.
|
|
118
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
class ProviderRpcError extends RpcError {
|
|
122
|
+
/**
|
|
123
|
+
* Create an Ethereum Provider JSON-RPC error.
|
|
124
|
+
* `code` must be an integer in the 1000 <= 4999 range.
|
|
125
|
+
*/
|
|
126
|
+
constructor(
|
|
127
|
+
/**
|
|
128
|
+
* Number error code
|
|
129
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#error-standards
|
|
130
|
+
*/
|
|
131
|
+
code,
|
|
132
|
+
/** Human-readable string */
|
|
133
|
+
message,
|
|
134
|
+
/** Low-level error */
|
|
135
|
+
internal,
|
|
136
|
+
/** Other useful information about error */
|
|
137
|
+
data) {
|
|
138
|
+
if (!(Number.isInteger(code) && code >= 1000 && code <= 4999)) throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');
|
|
139
|
+
super(code, message, internal, data);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
class AddChainError extends Error {
|
|
144
|
+
constructor() {
|
|
145
|
+
super(...arguments);
|
|
146
|
+
|
|
147
|
+
_defineProperty(this, "name", 'AddChainError');
|
|
148
|
+
|
|
149
|
+
_defineProperty(this, "message", 'Error adding chain');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
class ChainDoesNotSupportMulticallError extends Error {
|
|
154
|
+
constructor(_ref) {
|
|
155
|
+
let {
|
|
156
|
+
blockNumber,
|
|
157
|
+
chain
|
|
158
|
+
} = _ref;
|
|
159
|
+
super("Chain \"".concat(chain.name, "\" does not support multicall").concat(blockNumber ? " on block ".concat(blockNumber) : '', "."));
|
|
160
|
+
|
|
161
|
+
_defineProperty(this, "name", 'ChainDoesNotSupportMulticall');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
class ChainMismatchError extends Error {
|
|
166
|
+
constructor(_ref2) {
|
|
167
|
+
let {
|
|
168
|
+
activeChain,
|
|
169
|
+
targetChain
|
|
170
|
+
} = _ref2;
|
|
171
|
+
super("Chain mismatch: Expected \"".concat(targetChain, "\", received \"").concat(activeChain, "\"."));
|
|
172
|
+
|
|
173
|
+
_defineProperty(this, "name", 'ChainMismatchError');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
class ChainNotConfiguredError extends Error {
|
|
178
|
+
constructor() {
|
|
179
|
+
super(...arguments);
|
|
180
|
+
|
|
181
|
+
_defineProperty(this, "name", 'ChainNotConfigured');
|
|
182
|
+
|
|
183
|
+
_defineProperty(this, "message", 'Chain not configured');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
}
|
|
187
|
+
class ConnectorAlreadyConnectedError extends Error {
|
|
188
|
+
constructor() {
|
|
189
|
+
super(...arguments);
|
|
190
|
+
|
|
191
|
+
_defineProperty(this, "name", 'ConnectorAlreadyConnectedError');
|
|
192
|
+
|
|
193
|
+
_defineProperty(this, "message", 'Connector already connected');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
class ConnectorNotFoundError extends Error {
|
|
198
|
+
constructor() {
|
|
199
|
+
super(...arguments);
|
|
200
|
+
|
|
201
|
+
_defineProperty(this, "name", 'ConnectorNotFoundError');
|
|
202
|
+
|
|
203
|
+
_defineProperty(this, "message", 'Connector not found');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
class ContractMethodDoesNotExistError extends Error {
|
|
208
|
+
constructor(_ref3) {
|
|
209
|
+
var _chain$blockExplorers;
|
|
210
|
+
|
|
211
|
+
let {
|
|
212
|
+
addressOrName,
|
|
213
|
+
chainId,
|
|
214
|
+
functionName
|
|
215
|
+
} = _ref3;
|
|
216
|
+
const {
|
|
217
|
+
chains,
|
|
218
|
+
network
|
|
219
|
+
} = getProvider();
|
|
220
|
+
const chain = chains === null || chains === void 0 ? void 0 : chains.find(_ref4 => {
|
|
221
|
+
let {
|
|
222
|
+
id
|
|
223
|
+
} = _ref4;
|
|
224
|
+
return id === (chainId || network.chainId);
|
|
225
|
+
});
|
|
226
|
+
const blockExplorer = chain === null || chain === void 0 ? void 0 : (_chain$blockExplorers = chain.blockExplorers) === null || _chain$blockExplorers === void 0 ? void 0 : _chain$blockExplorers.default;
|
|
227
|
+
super(["Function \"".concat(functionName, "\" on contract \"").concat(addressOrName, "\" does not exist."), ...(blockExplorer ? ['', "".concat(blockExplorer === null || blockExplorer === void 0 ? void 0 : blockExplorer.name, ": ").concat(blockExplorer === null || blockExplorer === void 0 ? void 0 : blockExplorer.url, "/address/").concat(addressOrName, "#readContract")] : [])].join('\n'));
|
|
228
|
+
|
|
229
|
+
_defineProperty(this, "name", 'ContractMethodDoesNotExistError');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
class ContractMethodNoResultError extends Error {
|
|
234
|
+
constructor(_ref5) {
|
|
235
|
+
var _chain$blockExplorers2;
|
|
236
|
+
|
|
237
|
+
let {
|
|
238
|
+
addressOrName,
|
|
239
|
+
chainId,
|
|
240
|
+
functionName
|
|
241
|
+
} = _ref5;
|
|
242
|
+
const {
|
|
243
|
+
chains,
|
|
244
|
+
network
|
|
245
|
+
} = getProvider();
|
|
246
|
+
const chain = chains === null || chains === void 0 ? void 0 : chains.find(_ref6 => {
|
|
247
|
+
let {
|
|
248
|
+
id
|
|
249
|
+
} = _ref6;
|
|
250
|
+
return id === (chainId || network.chainId);
|
|
251
|
+
});
|
|
252
|
+
const blockExplorer = chain === null || chain === void 0 ? void 0 : (_chain$blockExplorers2 = chain.blockExplorers) === null || _chain$blockExplorers2 === void 0 ? void 0 : _chain$blockExplorers2.default;
|
|
253
|
+
super(["Function \"".concat(functionName, "\" on contract \"").concat(addressOrName, "\" returned an empty response."), '', "Are you sure the function \"".concat(functionName, "\" exists on this contract?"), ...(blockExplorer ? ['', "".concat(blockExplorer === null || blockExplorer === void 0 ? void 0 : blockExplorer.name, ": ").concat(blockExplorer === null || blockExplorer === void 0 ? void 0 : blockExplorer.url, "/address/").concat(addressOrName, "#readContract")] : [])].join('\n'));
|
|
254
|
+
|
|
255
|
+
_defineProperty(this, "name", 'ContractMethodNoResultError');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
}
|
|
259
|
+
class ProviderChainsNotFound extends Error {
|
|
260
|
+
constructor() {
|
|
261
|
+
super(...arguments);
|
|
262
|
+
|
|
263
|
+
_defineProperty(this, "name", 'ProviderChainsNotFound');
|
|
264
|
+
|
|
265
|
+
_defineProperty(this, "message", ['No chains were found on the wagmi provider. Some functions that require a chain may not work.', '', 'It is recommended to add a list of chains to the provider in `createClient`.', '', 'Example:', '', '```', "import { getDefaultProvider } from 'ethers'", "import { chain, createClient } from 'wagmi'", '', 'createClient({', ' provider: Object.assign(getDefaultProvider(), { chains: [chain.mainnet] })', '})', '```'].join('\n'));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
}
|
|
269
|
+
class ResourceUnavailableError extends RpcError {
|
|
270
|
+
constructor(error) {
|
|
271
|
+
super(-32002, 'Resource unavailable', error);
|
|
272
|
+
|
|
273
|
+
_defineProperty(this, "name", 'ResourceUnavailable');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
class SwitchChainError extends ProviderRpcError {
|
|
278
|
+
constructor(error) {
|
|
279
|
+
super(4902, 'Error switching chain', error);
|
|
280
|
+
|
|
281
|
+
_defineProperty(this, "name", 'SwitchChainError');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
}
|
|
285
|
+
class SwitchChainNotSupportedError extends Error {
|
|
286
|
+
constructor(_ref7) {
|
|
287
|
+
let {
|
|
288
|
+
connector
|
|
289
|
+
} = _ref7;
|
|
290
|
+
super("\"".concat(connector.name, "\" does not support programmatic chain switching."));
|
|
291
|
+
|
|
292
|
+
_defineProperty(this, "name", 'SwitchChainNotSupportedError');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
}
|
|
296
|
+
class UserRejectedRequestError extends ProviderRpcError {
|
|
297
|
+
constructor(error) {
|
|
298
|
+
super(4001, 'User rejected request', error);
|
|
299
|
+
|
|
300
|
+
_defineProperty(this, "name", 'UserRejectedRequestError');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
}
|
|
6
304
|
|
|
7
305
|
function getInjectedName(ethereum) {
|
|
8
306
|
var _ethereum$providers, _getName;
|
|
@@ -50,7 +348,59 @@ function getInjectedName(ethereum) {
|
|
|
50
348
|
return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
|
|
51
349
|
}
|
|
52
350
|
|
|
53
|
-
|
|
351
|
+
function normalizeChainId(chainId) {
|
|
352
|
+
if (typeof chainId === 'string') return Number.parseInt(chainId, chainId.trim().substring(0, 2) === '0x' ? 16 : 10);
|
|
353
|
+
if (typeof chainId === 'bigint') return Number(chainId);
|
|
354
|
+
return chainId;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
class Connector extends EventEmitter {
|
|
358
|
+
/** Unique connector id */
|
|
359
|
+
|
|
360
|
+
/** Connector name */
|
|
361
|
+
|
|
362
|
+
/** Chains connector supports */
|
|
363
|
+
|
|
364
|
+
/** Options to use with connector */
|
|
365
|
+
|
|
366
|
+
/** Whether connector is usable */
|
|
367
|
+
constructor(_ref) {
|
|
368
|
+
let {
|
|
369
|
+
chains = defaultChains,
|
|
370
|
+
options
|
|
371
|
+
} = _ref;
|
|
372
|
+
super();
|
|
373
|
+
|
|
374
|
+
_defineProperty(this, "id", void 0);
|
|
375
|
+
|
|
376
|
+
_defineProperty(this, "name", void 0);
|
|
377
|
+
|
|
378
|
+
_defineProperty(this, "chains", void 0);
|
|
379
|
+
|
|
380
|
+
_defineProperty(this, "options", void 0);
|
|
381
|
+
|
|
382
|
+
_defineProperty(this, "ready", void 0);
|
|
383
|
+
|
|
384
|
+
this.chains = chains;
|
|
385
|
+
this.options = options;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
getBlockExplorerUrls(chain) {
|
|
389
|
+
var _chain$blockExplorers;
|
|
390
|
+
|
|
391
|
+
const {
|
|
392
|
+
default: blockExplorer,
|
|
393
|
+
...blockExplorers
|
|
394
|
+
} = (_chain$blockExplorers = chain.blockExplorers) !== null && _chain$blockExplorers !== void 0 ? _chain$blockExplorers : {};
|
|
395
|
+
if (blockExplorer) return [blockExplorer.url, ...Object.values(blockExplorers).map(x => x.url)];
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
isChainUnsupported(chainId) {
|
|
400
|
+
return !this.chains.some(x => x.id === chainId);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
}
|
|
54
404
|
|
|
55
405
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
56
406
|
|
|
@@ -85,6 +435,8 @@ class InjectedConnector extends Connector {
|
|
|
85
435
|
value: void 0
|
|
86
436
|
});
|
|
87
437
|
|
|
438
|
+
_defineProperty(this, "shimDisconnectKey", 'injected.shimDisconnect');
|
|
439
|
+
|
|
88
440
|
_defineProperty(this, "onAccountsChanged", accounts => {
|
|
89
441
|
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
90
442
|
account: getAddress(accounts[0])
|
|
@@ -116,17 +468,15 @@ class InjectedConnector extends Connector {
|
|
|
116
468
|
|
|
117
469
|
this.emit('disconnect'); // Remove shim signalling wallet is disconnected
|
|
118
470
|
|
|
119
|
-
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimDisconnectKey);
|
|
471
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(this.shimDisconnectKey);
|
|
120
472
|
});
|
|
121
473
|
|
|
122
474
|
let name = 'Injected';
|
|
123
|
-
|
|
124
|
-
if (typeof window !== 'undefined') {
|
|
125
|
-
const overrideName = options.name;
|
|
475
|
+
const overrideName = options.name;
|
|
476
|
+
if (typeof overrideName === 'string') name = overrideName;else if (typeof window !== 'undefined') {
|
|
126
477
|
const detectedName = getInjectedName(window.ethereum);
|
|
127
|
-
if (overrideName) name =
|
|
478
|
+
if (overrideName) name = overrideName(detectedName);else name = typeof detectedName === 'string' ? detectedName : detectedName[0];
|
|
128
479
|
}
|
|
129
|
-
|
|
130
480
|
this.id = 'injected';
|
|
131
481
|
this.name = name;
|
|
132
482
|
}
|
|
@@ -163,7 +513,7 @@ class InjectedConnector extends Connector {
|
|
|
163
513
|
} // Add shim to storage signalling wallet is connected
|
|
164
514
|
|
|
165
515
|
|
|
166
|
-
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimDisconnectKey, true);
|
|
516
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(this.shimDisconnectKey, true);
|
|
167
517
|
return {
|
|
168
518
|
account,
|
|
169
519
|
chain: {
|
|
@@ -188,7 +538,7 @@ class InjectedConnector extends Connector {
|
|
|
188
538
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
189
539
|
provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
|
|
190
540
|
|
|
191
|
-
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimDisconnectKey);
|
|
541
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(this.shimDisconnectKey);
|
|
192
542
|
}
|
|
193
543
|
|
|
194
544
|
async getAccount() {
|
|
@@ -224,7 +574,7 @@ class InjectedConnector extends Connector {
|
|
|
224
574
|
var _this$options5, _getClient$storage4;
|
|
225
575
|
|
|
226
576
|
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
|
|
227
|
-
!((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
|
|
577
|
+
!((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(this.shimDisconnectKey))) return false;
|
|
228
578
|
const provider = await this.getProvider();
|
|
229
579
|
if (!provider) throw new ConnectorNotFoundError();
|
|
230
580
|
const accounts = await provider.request({
|
|
@@ -456,6 +806,8 @@ class Client {
|
|
|
456
806
|
_classPrivateFieldSet(this, _lastUsedConnector, storage === null || storage === void 0 ? void 0 : storage.getItem('wallet'));
|
|
457
807
|
|
|
458
808
|
_classPrivateMethodGet(this, _addEffects, _addEffects2).call(this);
|
|
809
|
+
|
|
810
|
+
if (autoConnect && typeof window !== 'undefined') setTimeout(async () => await this.autoConnect(), 0);
|
|
459
811
|
}
|
|
460
812
|
|
|
461
813
|
get chains() {
|
|
@@ -530,7 +882,13 @@ class Client {
|
|
|
530
882
|
|
|
531
883
|
_classPrivateFieldSet(this, _isAutoConnecting, true);
|
|
532
884
|
|
|
533
|
-
|
|
885
|
+
this.setState(x => {
|
|
886
|
+
var _x$data;
|
|
887
|
+
|
|
888
|
+
return { ...x,
|
|
889
|
+
status: (_x$data = x.data) !== null && _x$data !== void 0 && _x$data.account ? 'reconnecting' : 'connecting'
|
|
890
|
+
};
|
|
891
|
+
}); // Try last used connector first
|
|
534
892
|
|
|
535
893
|
const sorted = _classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === _classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
|
|
536
894
|
let connected = false;
|
|
@@ -644,4 +1002,15 @@ function getClient() {
|
|
|
644
1002
|
return client;
|
|
645
1003
|
}
|
|
646
1004
|
|
|
647
|
-
|
|
1005
|
+
function getProvider() {
|
|
1006
|
+
let {
|
|
1007
|
+
chainId
|
|
1008
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1009
|
+
const client = getClient();
|
|
1010
|
+
if (chainId && typeof client.config.provider === 'function') return client.config.provider({
|
|
1011
|
+
chainId
|
|
1012
|
+
});
|
|
1013
|
+
return client.provider;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
export { AddChainError as A, ConnectorAlreadyConnectedError as C, InjectedConnector as I, ProviderChainsNotFound as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _classPrivateMethodInitSpec as _, ConnectorNotFoundError as a, ChainMismatchError as b, ContractMethodDoesNotExistError as c, getProvider as d, ChainDoesNotSupportMulticallError as e, ContractMethodNoResultError as f, getClient as g, createClient as h, Client as i, Connector as j, ChainNotConfiguredError as k, ProviderRpcError as l, RpcError as m, normalizeChainId as n, SwitchChainError as o, createStorage as p, noopStorage as q, _defineProperty as r, _classPrivateFieldInitSpec as s, _classPrivateFieldGet as t, _classPrivateFieldSet as u, _classPrivateMethodGet as v };
|