@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,14 +1,313 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-90b7f3e4.cjs.dev.js');
|
|
4
|
-
var create = require('zustand/vanilla');
|
|
5
3
|
var middleware = require('zustand/middleware');
|
|
4
|
+
var create = require('zustand/vanilla');
|
|
6
5
|
var ethers = require('ethers');
|
|
7
6
|
var utils = require('ethers/lib/utils');
|
|
7
|
+
var EventEmitter = require('eventemitter3');
|
|
8
|
+
var chains = require('./chains-a1aae67e.cjs.dev.js');
|
|
8
9
|
|
|
9
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
10
11
|
|
|
11
12
|
var create__default = /*#__PURE__*/_interopDefault(create);
|
|
13
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
|
|
14
|
+
|
|
15
|
+
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
16
|
+
if (privateCollection.has(obj)) {
|
|
17
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _classPrivateMethodInitSpec(obj, privateSet) {
|
|
22
|
+
_checkPrivateRedeclaration(obj, privateSet);
|
|
23
|
+
privateSet.add(obj);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) {
|
|
27
|
+
_checkPrivateRedeclaration(obj, privateMap);
|
|
28
|
+
privateMap.set(obj, value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _defineProperty(obj, key, value) {
|
|
32
|
+
if (key in obj) {
|
|
33
|
+
Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
obj[key] = value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
47
|
+
if (descriptor.get) {
|
|
48
|
+
return descriptor.get.call(receiver);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return descriptor.value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
55
|
+
if (!privateMap.has(receiver)) {
|
|
56
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return privateMap.get(receiver);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _classPrivateFieldGet(receiver, privateMap) {
|
|
63
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
64
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
|
68
|
+
if (!privateSet.has(receiver)) {
|
|
69
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return fn;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
76
|
+
if (descriptor.set) {
|
|
77
|
+
descriptor.set.call(receiver, value);
|
|
78
|
+
} else {
|
|
79
|
+
if (!descriptor.writable) {
|
|
80
|
+
throw new TypeError("attempted to set read only private field");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
descriptor.value = value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
88
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
89
|
+
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors per EIP-1474.
|
|
95
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474
|
|
96
|
+
*/
|
|
97
|
+
class RpcError extends Error {
|
|
98
|
+
constructor(
|
|
99
|
+
/** Number error code */
|
|
100
|
+
code,
|
|
101
|
+
/** Human-readable string */
|
|
102
|
+
message,
|
|
103
|
+
/** Low-level error */
|
|
104
|
+
internal,
|
|
105
|
+
/** Other useful information about error */
|
|
106
|
+
data) {
|
|
107
|
+
if (!Number.isInteger(code)) throw new Error('"code" must be an integer.');
|
|
108
|
+
if (!message || typeof message !== 'string') throw new Error('"message" must be a nonempty string.');
|
|
109
|
+
super(message);
|
|
110
|
+
|
|
111
|
+
_defineProperty(this, "code", void 0);
|
|
112
|
+
|
|
113
|
+
_defineProperty(this, "data", void 0);
|
|
114
|
+
|
|
115
|
+
_defineProperty(this, "internal", void 0);
|
|
116
|
+
|
|
117
|
+
this.code = code;
|
|
118
|
+
this.data = data;
|
|
119
|
+
this.internal = internal;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Error subclass implementing Ethereum Provider errors per EIP-1193.
|
|
125
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
class ProviderRpcError extends RpcError {
|
|
129
|
+
/**
|
|
130
|
+
* Create an Ethereum Provider JSON-RPC error.
|
|
131
|
+
* `code` must be an integer in the 1000 <= 4999 range.
|
|
132
|
+
*/
|
|
133
|
+
constructor(
|
|
134
|
+
/**
|
|
135
|
+
* Number error code
|
|
136
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#error-standards
|
|
137
|
+
*/
|
|
138
|
+
code,
|
|
139
|
+
/** Human-readable string */
|
|
140
|
+
message,
|
|
141
|
+
/** Low-level error */
|
|
142
|
+
internal,
|
|
143
|
+
/** Other useful information about error */
|
|
144
|
+
data) {
|
|
145
|
+
if (!(Number.isInteger(code) && code >= 1000 && code <= 4999)) throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');
|
|
146
|
+
super(code, message, internal, data);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
class AddChainError extends Error {
|
|
151
|
+
constructor() {
|
|
152
|
+
super(...arguments);
|
|
153
|
+
|
|
154
|
+
_defineProperty(this, "name", 'AddChainError');
|
|
155
|
+
|
|
156
|
+
_defineProperty(this, "message", 'Error adding chain');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
class ChainDoesNotSupportMulticallError extends Error {
|
|
161
|
+
constructor(_ref) {
|
|
162
|
+
let {
|
|
163
|
+
blockNumber,
|
|
164
|
+
chain
|
|
165
|
+
} = _ref;
|
|
166
|
+
super("Chain \"".concat(chain.name, "\" does not support multicall").concat(blockNumber ? " on block ".concat(blockNumber) : '', "."));
|
|
167
|
+
|
|
168
|
+
_defineProperty(this, "name", 'ChainDoesNotSupportMulticall');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
class ChainMismatchError extends Error {
|
|
173
|
+
constructor(_ref2) {
|
|
174
|
+
let {
|
|
175
|
+
activeChain,
|
|
176
|
+
targetChain
|
|
177
|
+
} = _ref2;
|
|
178
|
+
super("Chain mismatch: Expected \"".concat(targetChain, "\", received \"").concat(activeChain, "\"."));
|
|
179
|
+
|
|
180
|
+
_defineProperty(this, "name", 'ChainMismatchError');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
class ChainNotConfiguredError extends Error {
|
|
185
|
+
constructor() {
|
|
186
|
+
super(...arguments);
|
|
187
|
+
|
|
188
|
+
_defineProperty(this, "name", 'ChainNotConfigured');
|
|
189
|
+
|
|
190
|
+
_defineProperty(this, "message", 'Chain not configured');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
class ConnectorAlreadyConnectedError extends Error {
|
|
195
|
+
constructor() {
|
|
196
|
+
super(...arguments);
|
|
197
|
+
|
|
198
|
+
_defineProperty(this, "name", 'ConnectorAlreadyConnectedError');
|
|
199
|
+
|
|
200
|
+
_defineProperty(this, "message", 'Connector already connected');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
class ConnectorNotFoundError extends Error {
|
|
205
|
+
constructor() {
|
|
206
|
+
super(...arguments);
|
|
207
|
+
|
|
208
|
+
_defineProperty(this, "name", 'ConnectorNotFoundError');
|
|
209
|
+
|
|
210
|
+
_defineProperty(this, "message", 'Connector not found');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
class ContractMethodDoesNotExistError extends Error {
|
|
215
|
+
constructor(_ref3) {
|
|
216
|
+
var _chain$blockExplorers;
|
|
217
|
+
|
|
218
|
+
let {
|
|
219
|
+
addressOrName,
|
|
220
|
+
chainId,
|
|
221
|
+
functionName
|
|
222
|
+
} = _ref3;
|
|
223
|
+
const {
|
|
224
|
+
chains,
|
|
225
|
+
network
|
|
226
|
+
} = getProvider();
|
|
227
|
+
const chain = chains === null || chains === void 0 ? void 0 : chains.find(_ref4 => {
|
|
228
|
+
let {
|
|
229
|
+
id
|
|
230
|
+
} = _ref4;
|
|
231
|
+
return id === (chainId || network.chainId);
|
|
232
|
+
});
|
|
233
|
+
const blockExplorer = chain === null || chain === void 0 ? void 0 : (_chain$blockExplorers = chain.blockExplorers) === null || _chain$blockExplorers === void 0 ? void 0 : _chain$blockExplorers.default;
|
|
234
|
+
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'));
|
|
235
|
+
|
|
236
|
+
_defineProperty(this, "name", 'ContractMethodDoesNotExistError');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
class ContractMethodNoResultError extends Error {
|
|
241
|
+
constructor(_ref5) {
|
|
242
|
+
var _chain$blockExplorers2;
|
|
243
|
+
|
|
244
|
+
let {
|
|
245
|
+
addressOrName,
|
|
246
|
+
chainId,
|
|
247
|
+
functionName
|
|
248
|
+
} = _ref5;
|
|
249
|
+
const {
|
|
250
|
+
chains,
|
|
251
|
+
network
|
|
252
|
+
} = getProvider();
|
|
253
|
+
const chain = chains === null || chains === void 0 ? void 0 : chains.find(_ref6 => {
|
|
254
|
+
let {
|
|
255
|
+
id
|
|
256
|
+
} = _ref6;
|
|
257
|
+
return id === (chainId || network.chainId);
|
|
258
|
+
});
|
|
259
|
+
const blockExplorer = chain === null || chain === void 0 ? void 0 : (_chain$blockExplorers2 = chain.blockExplorers) === null || _chain$blockExplorers2 === void 0 ? void 0 : _chain$blockExplorers2.default;
|
|
260
|
+
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'));
|
|
261
|
+
|
|
262
|
+
_defineProperty(this, "name", 'ContractMethodNoResultError');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
class ProviderChainsNotFound extends Error {
|
|
267
|
+
constructor() {
|
|
268
|
+
super(...arguments);
|
|
269
|
+
|
|
270
|
+
_defineProperty(this, "name", 'ProviderChainsNotFound');
|
|
271
|
+
|
|
272
|
+
_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'));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
class ResourceUnavailableError extends RpcError {
|
|
277
|
+
constructor(error) {
|
|
278
|
+
super(-32002, 'Resource unavailable', error);
|
|
279
|
+
|
|
280
|
+
_defineProperty(this, "name", 'ResourceUnavailable');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
}
|
|
284
|
+
class SwitchChainError extends ProviderRpcError {
|
|
285
|
+
constructor(error) {
|
|
286
|
+
super(4902, 'Error switching chain', error);
|
|
287
|
+
|
|
288
|
+
_defineProperty(this, "name", 'SwitchChainError');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
class SwitchChainNotSupportedError extends Error {
|
|
293
|
+
constructor(_ref7) {
|
|
294
|
+
let {
|
|
295
|
+
connector
|
|
296
|
+
} = _ref7;
|
|
297
|
+
super("\"".concat(connector.name, "\" does not support programmatic chain switching."));
|
|
298
|
+
|
|
299
|
+
_defineProperty(this, "name", 'SwitchChainNotSupportedError');
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
class UserRejectedRequestError extends ProviderRpcError {
|
|
304
|
+
constructor(error) {
|
|
305
|
+
super(4001, 'User rejected request', error);
|
|
306
|
+
|
|
307
|
+
_defineProperty(this, "name", 'UserRejectedRequestError');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
}
|
|
12
311
|
|
|
13
312
|
function getInjectedName(ethereum) {
|
|
14
313
|
var _ethereum$providers, _getName;
|
|
@@ -56,13 +355,65 @@ function getInjectedName(ethereum) {
|
|
|
56
355
|
return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
|
|
57
356
|
}
|
|
58
357
|
|
|
59
|
-
|
|
358
|
+
function normalizeChainId(chainId) {
|
|
359
|
+
if (typeof chainId === 'string') return Number.parseInt(chainId, chainId.trim().substring(0, 2) === '0x' ? 16 : 10);
|
|
360
|
+
if (typeof chainId === 'bigint') return Number(chainId);
|
|
361
|
+
return chainId;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
class Connector extends EventEmitter__default["default"] {
|
|
365
|
+
/** Unique connector id */
|
|
366
|
+
|
|
367
|
+
/** Connector name */
|
|
368
|
+
|
|
369
|
+
/** Chains connector supports */
|
|
370
|
+
|
|
371
|
+
/** Options to use with connector */
|
|
372
|
+
|
|
373
|
+
/** Whether connector is usable */
|
|
374
|
+
constructor(_ref) {
|
|
375
|
+
let {
|
|
376
|
+
chains: chains$1 = chains.defaultChains,
|
|
377
|
+
options
|
|
378
|
+
} = _ref;
|
|
379
|
+
super();
|
|
380
|
+
|
|
381
|
+
_defineProperty(this, "id", void 0);
|
|
382
|
+
|
|
383
|
+
_defineProperty(this, "name", void 0);
|
|
384
|
+
|
|
385
|
+
_defineProperty(this, "chains", void 0);
|
|
386
|
+
|
|
387
|
+
_defineProperty(this, "options", void 0);
|
|
388
|
+
|
|
389
|
+
_defineProperty(this, "ready", void 0);
|
|
390
|
+
|
|
391
|
+
this.chains = chains$1;
|
|
392
|
+
this.options = options;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
getBlockExplorerUrls(chain) {
|
|
396
|
+
var _chain$blockExplorers;
|
|
397
|
+
|
|
398
|
+
const {
|
|
399
|
+
default: blockExplorer,
|
|
400
|
+
...blockExplorers
|
|
401
|
+
} = (_chain$blockExplorers = chain.blockExplorers) !== null && _chain$blockExplorers !== void 0 ? _chain$blockExplorers : {};
|
|
402
|
+
if (blockExplorer) return [blockExplorer.url, ...Object.values(blockExplorers).map(x => x.url)];
|
|
403
|
+
return [];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
isChainUnsupported(chainId) {
|
|
407
|
+
return !this.chains.some(x => x.id === chainId);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
}
|
|
60
411
|
|
|
61
412
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
62
413
|
|
|
63
414
|
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
64
415
|
|
|
65
|
-
class InjectedConnector extends
|
|
416
|
+
class InjectedConnector extends Connector {
|
|
66
417
|
constructor() {
|
|
67
418
|
let {
|
|
68
419
|
chains,
|
|
@@ -75,30 +426,32 @@ class InjectedConnector extends base.Connector {
|
|
|
75
426
|
options
|
|
76
427
|
});
|
|
77
428
|
|
|
78
|
-
|
|
429
|
+
_defineProperty(this, "id", void 0);
|
|
79
430
|
|
|
80
|
-
|
|
431
|
+
_defineProperty(this, "name", void 0);
|
|
81
432
|
|
|
82
|
-
|
|
433
|
+
_defineProperty(this, "ready", typeof window != 'undefined' && !!window.ethereum);
|
|
83
434
|
|
|
84
|
-
|
|
435
|
+
_classPrivateFieldInitSpec(this, _provider, {
|
|
85
436
|
writable: true,
|
|
86
437
|
value: void 0
|
|
87
438
|
});
|
|
88
439
|
|
|
89
|
-
|
|
440
|
+
_classPrivateFieldInitSpec(this, _switchingChains, {
|
|
90
441
|
writable: true,
|
|
91
442
|
value: void 0
|
|
92
443
|
});
|
|
93
444
|
|
|
94
|
-
|
|
445
|
+
_defineProperty(this, "shimDisconnectKey", 'injected.shimDisconnect');
|
|
446
|
+
|
|
447
|
+
_defineProperty(this, "onAccountsChanged", accounts => {
|
|
95
448
|
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
96
449
|
account: utils.getAddress(accounts[0])
|
|
97
450
|
});
|
|
98
451
|
});
|
|
99
452
|
|
|
100
|
-
|
|
101
|
-
const id =
|
|
453
|
+
_defineProperty(this, "onChainChanged", chainId => {
|
|
454
|
+
const id = normalizeChainId(chainId);
|
|
102
455
|
const unsupported = this.isChainUnsupported(id);
|
|
103
456
|
this.emit('change', {
|
|
104
457
|
chain: {
|
|
@@ -108,31 +461,29 @@ class InjectedConnector extends base.Connector {
|
|
|
108
461
|
});
|
|
109
462
|
});
|
|
110
463
|
|
|
111
|
-
|
|
464
|
+
_defineProperty(this, "onDisconnect", () => {
|
|
112
465
|
var _this$options, _this$options2, _getClient$storage;
|
|
113
466
|
|
|
114
467
|
// We need this as MetaMask can emit the "disconnect" event
|
|
115
468
|
// upon switching chains. This workaround ensures that the
|
|
116
469
|
// user currently isn't in the process of switching chains.
|
|
117
|
-
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect &&
|
|
118
|
-
|
|
470
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect && _classPrivateFieldGet(this, _switchingChains)) {
|
|
471
|
+
_classPrivateFieldSet(this, _switchingChains, false);
|
|
119
472
|
|
|
120
473
|
return;
|
|
121
474
|
}
|
|
122
475
|
|
|
123
476
|
this.emit('disconnect'); // Remove shim signalling wallet is disconnected
|
|
124
477
|
|
|
125
|
-
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);
|
|
478
|
+
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);
|
|
126
479
|
});
|
|
127
480
|
|
|
128
481
|
let name = 'Injected';
|
|
129
|
-
|
|
130
|
-
if (typeof window !== 'undefined') {
|
|
131
|
-
const overrideName = options.name;
|
|
482
|
+
const overrideName = options.name;
|
|
483
|
+
if (typeof overrideName === 'string') name = overrideName;else if (typeof window !== 'undefined') {
|
|
132
484
|
const detectedName = getInjectedName(window.ethereum);
|
|
133
|
-
if (overrideName) name =
|
|
485
|
+
if (overrideName) name = overrideName(detectedName);else name = typeof detectedName === 'string' ? detectedName : detectedName[0];
|
|
134
486
|
}
|
|
135
|
-
|
|
136
487
|
this.id = 'injected';
|
|
137
488
|
this.name = name;
|
|
138
489
|
}
|
|
@@ -146,7 +497,7 @@ class InjectedConnector extends base.Connector {
|
|
|
146
497
|
var _this$options3, _getClient$storage2;
|
|
147
498
|
|
|
148
499
|
const provider = await this.getProvider();
|
|
149
|
-
if (!provider) throw new
|
|
500
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
150
501
|
|
|
151
502
|
if (provider.on) {
|
|
152
503
|
provider.on('accountsChanged', this.onAccountsChanged);
|
|
@@ -169,7 +520,7 @@ class InjectedConnector extends base.Connector {
|
|
|
169
520
|
} // Add shim to storage signalling wallet is connected
|
|
170
521
|
|
|
171
522
|
|
|
172
|
-
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);
|
|
523
|
+
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);
|
|
173
524
|
return {
|
|
174
525
|
account,
|
|
175
526
|
chain: {
|
|
@@ -179,8 +530,8 @@ class InjectedConnector extends base.Connector {
|
|
|
179
530
|
provider
|
|
180
531
|
};
|
|
181
532
|
} catch (error) {
|
|
182
|
-
if (this.isUserRejectedRequestError(error)) throw new
|
|
183
|
-
if (error.code === -32002) throw new
|
|
533
|
+
if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
|
|
534
|
+
if (error.code === -32002) throw new ResourceUnavailableError(error);
|
|
184
535
|
throw error;
|
|
185
536
|
}
|
|
186
537
|
}
|
|
@@ -194,12 +545,12 @@ class InjectedConnector extends base.Connector {
|
|
|
194
545
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
195
546
|
provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
|
|
196
547
|
|
|
197
|
-
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);
|
|
548
|
+
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);
|
|
198
549
|
}
|
|
199
550
|
|
|
200
551
|
async getAccount() {
|
|
201
552
|
const provider = await this.getProvider();
|
|
202
|
-
if (!provider) throw new
|
|
553
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
203
554
|
const accounts = await provider.request({
|
|
204
555
|
method: 'eth_requestAccounts'
|
|
205
556
|
}); // return checksum address
|
|
@@ -209,15 +560,15 @@ class InjectedConnector extends base.Connector {
|
|
|
209
560
|
|
|
210
561
|
async getChainId() {
|
|
211
562
|
const provider = await this.getProvider();
|
|
212
|
-
if (!provider) throw new
|
|
563
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
213
564
|
return await provider.request({
|
|
214
565
|
method: 'eth_chainId'
|
|
215
|
-
}).then(
|
|
566
|
+
}).then(normalizeChainId);
|
|
216
567
|
}
|
|
217
568
|
|
|
218
569
|
async getProvider() {
|
|
219
|
-
if (typeof window !== 'undefined' && !!window.ethereum)
|
|
220
|
-
return
|
|
570
|
+
if (typeof window !== 'undefined' && !!window.ethereum) _classPrivateFieldSet(this, _provider, window.ethereum);
|
|
571
|
+
return _classPrivateFieldGet(this, _provider);
|
|
221
572
|
}
|
|
222
573
|
|
|
223
574
|
async getSigner() {
|
|
@@ -230,9 +581,9 @@ class InjectedConnector extends base.Connector {
|
|
|
230
581
|
var _this$options5, _getClient$storage4;
|
|
231
582
|
|
|
232
583
|
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
|
|
233
|
-
!((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
|
|
584
|
+
!((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(this.shimDisconnectKey))) return false;
|
|
234
585
|
const provider = await this.getProvider();
|
|
235
|
-
if (!provider) throw new
|
|
586
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
236
587
|
const accounts = await provider.request({
|
|
237
588
|
method: 'eth_accounts'
|
|
238
589
|
});
|
|
@@ -246,9 +597,9 @@ class InjectedConnector extends base.Connector {
|
|
|
246
597
|
async switchChain(chainId) {
|
|
247
598
|
var _this$options6;
|
|
248
599
|
|
|
249
|
-
if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect)
|
|
600
|
+
if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect) _classPrivateFieldSet(this, _switchingChains, true);
|
|
250
601
|
const provider = await this.getProvider();
|
|
251
|
-
if (!provider) throw new
|
|
602
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
252
603
|
const id = utils.hexValue(chainId);
|
|
253
604
|
|
|
254
605
|
try {
|
|
@@ -272,7 +623,7 @@ class InjectedConnector extends base.Connector {
|
|
|
272
623
|
var _data, _data$originalError;
|
|
273
624
|
|
|
274
625
|
const chain = this.chains.find(x => x.id === chainId);
|
|
275
|
-
if (!chain) throw new
|
|
626
|
+
if (!chain) throw new ChainNotConfiguredError(); // Indicates chain is not added to provider
|
|
276
627
|
|
|
277
628
|
if (error.code === 4902 || // Unwrapping for MetaMask Mobile
|
|
278
629
|
// https://github.com/MetaMask/metamask-mobile/issues/2944#issuecomment-976988719
|
|
@@ -292,13 +643,13 @@ class InjectedConnector extends base.Connector {
|
|
|
292
643
|
});
|
|
293
644
|
return chain;
|
|
294
645
|
} catch (addError) {
|
|
295
|
-
if (this.isUserRejectedRequestError(addError)) throw new
|
|
296
|
-
throw new
|
|
646
|
+
if (this.isUserRejectedRequestError(addError)) throw new UserRejectedRequestError(error);
|
|
647
|
+
throw new AddChainError();
|
|
297
648
|
}
|
|
298
649
|
}
|
|
299
650
|
|
|
300
|
-
if (this.isUserRejectedRequestError(error)) throw new
|
|
301
|
-
throw new
|
|
651
|
+
if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
|
|
652
|
+
throw new SwitchChainError(error);
|
|
302
653
|
}
|
|
303
654
|
}
|
|
304
655
|
|
|
@@ -310,7 +661,7 @@ class InjectedConnector extends base.Connector {
|
|
|
310
661
|
symbol
|
|
311
662
|
} = _ref;
|
|
312
663
|
const provider = await this.getProvider();
|
|
313
|
-
if (!provider) throw new
|
|
664
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
314
665
|
return await provider.request({
|
|
315
666
|
method: 'wallet_watchAsset',
|
|
316
667
|
params: {
|
|
@@ -388,20 +739,20 @@ class Client {
|
|
|
388
739
|
webSocketProvider: _webSocketProvider
|
|
389
740
|
} = _ref;
|
|
390
741
|
|
|
391
|
-
|
|
742
|
+
_classPrivateMethodInitSpec(this, _addEffects);
|
|
392
743
|
|
|
393
|
-
|
|
744
|
+
_defineProperty(this, "config", void 0);
|
|
394
745
|
|
|
395
|
-
|
|
746
|
+
_defineProperty(this, "storage", void 0);
|
|
396
747
|
|
|
397
|
-
|
|
748
|
+
_defineProperty(this, "store", void 0);
|
|
398
749
|
|
|
399
|
-
|
|
750
|
+
_classPrivateFieldInitSpec(this, _isAutoConnecting, {
|
|
400
751
|
writable: true,
|
|
401
752
|
value: void 0
|
|
402
753
|
});
|
|
403
754
|
|
|
404
|
-
|
|
755
|
+
_classPrivateFieldInitSpec(this, _lastUsedConnector, {
|
|
405
756
|
writable: true,
|
|
406
757
|
value: void 0
|
|
407
758
|
});
|
|
@@ -459,9 +810,11 @@ class Client {
|
|
|
459
810
|
};
|
|
460
811
|
this.storage = storage;
|
|
461
812
|
|
|
462
|
-
|
|
813
|
+
_classPrivateFieldSet(this, _lastUsedConnector, storage === null || storage === void 0 ? void 0 : storage.getItem('wallet'));
|
|
814
|
+
|
|
815
|
+
_classPrivateMethodGet(this, _addEffects, _addEffects2).call(this);
|
|
463
816
|
|
|
464
|
-
|
|
817
|
+
if (autoConnect && typeof window !== 'undefined') setTimeout(async () => await this.autoConnect(), 0);
|
|
465
818
|
}
|
|
466
819
|
|
|
467
820
|
get chains() {
|
|
@@ -525,20 +878,26 @@ class Client {
|
|
|
525
878
|
|
|
526
879
|
if (this.connector) await ((_this$connector$disco = (_this$connector = this.connector).disconnect) === null || _this$connector$disco === void 0 ? void 0 : _this$connector$disco.call(_this$connector));
|
|
527
880
|
|
|
528
|
-
|
|
881
|
+
_classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
529
882
|
|
|
530
883
|
this.clearState();
|
|
531
884
|
this.store.destroy();
|
|
532
885
|
}
|
|
533
886
|
|
|
534
887
|
async autoConnect() {
|
|
535
|
-
if (
|
|
888
|
+
if (_classPrivateFieldGet(this, _isAutoConnecting)) return;
|
|
536
889
|
|
|
537
|
-
|
|
890
|
+
_classPrivateFieldSet(this, _isAutoConnecting, true);
|
|
538
891
|
|
|
539
|
-
|
|
892
|
+
this.setState(x => {
|
|
893
|
+
var _x$data;
|
|
894
|
+
|
|
895
|
+
return { ...x,
|
|
896
|
+
status: (_x$data = x.data) !== null && _x$data !== void 0 && _x$data.account ? 'reconnecting' : 'connecting'
|
|
897
|
+
};
|
|
898
|
+
}); // Try last used connector first
|
|
540
899
|
|
|
541
|
-
const sorted =
|
|
900
|
+
const sorted = _classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === _classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
|
|
542
901
|
let connected = false;
|
|
543
902
|
|
|
544
903
|
for (const connector of sorted) {
|
|
@@ -562,7 +921,7 @@ class Client {
|
|
|
562
921
|
status: 'disconnected'
|
|
563
922
|
}));
|
|
564
923
|
|
|
565
|
-
|
|
924
|
+
_classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
566
925
|
|
|
567
926
|
return this.data;
|
|
568
927
|
}
|
|
@@ -650,10 +1009,44 @@ function getClient() {
|
|
|
650
1009
|
return client;
|
|
651
1010
|
}
|
|
652
1011
|
|
|
1012
|
+
function getProvider() {
|
|
1013
|
+
let {
|
|
1014
|
+
chainId
|
|
1015
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1016
|
+
const client = getClient();
|
|
1017
|
+
if (chainId && typeof client.config.provider === 'function') return client.config.provider({
|
|
1018
|
+
chainId
|
|
1019
|
+
});
|
|
1020
|
+
return client.provider;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
exports.AddChainError = AddChainError;
|
|
1024
|
+
exports.ChainDoesNotSupportMulticallError = ChainDoesNotSupportMulticallError;
|
|
1025
|
+
exports.ChainMismatchError = ChainMismatchError;
|
|
1026
|
+
exports.ChainNotConfiguredError = ChainNotConfiguredError;
|
|
653
1027
|
exports.Client = Client;
|
|
1028
|
+
exports.Connector = Connector;
|
|
1029
|
+
exports.ConnectorAlreadyConnectedError = ConnectorAlreadyConnectedError;
|
|
1030
|
+
exports.ConnectorNotFoundError = ConnectorNotFoundError;
|
|
1031
|
+
exports.ContractMethodDoesNotExistError = ContractMethodDoesNotExistError;
|
|
1032
|
+
exports.ContractMethodNoResultError = ContractMethodNoResultError;
|
|
654
1033
|
exports.InjectedConnector = InjectedConnector;
|
|
1034
|
+
exports.ProviderChainsNotFound = ProviderChainsNotFound;
|
|
1035
|
+
exports.ProviderRpcError = ProviderRpcError;
|
|
1036
|
+
exports.ResourceUnavailableError = ResourceUnavailableError;
|
|
1037
|
+
exports.RpcError = RpcError;
|
|
1038
|
+
exports.SwitchChainError = SwitchChainError;
|
|
1039
|
+
exports.SwitchChainNotSupportedError = SwitchChainNotSupportedError;
|
|
1040
|
+
exports.UserRejectedRequestError = UserRejectedRequestError;
|
|
1041
|
+
exports._classPrivateFieldGet = _classPrivateFieldGet;
|
|
1042
|
+
exports._classPrivateFieldInitSpec = _classPrivateFieldInitSpec;
|
|
1043
|
+
exports._classPrivateFieldSet = _classPrivateFieldSet;
|
|
1044
|
+
exports._classPrivateMethodGet = _classPrivateMethodGet;
|
|
1045
|
+
exports._classPrivateMethodInitSpec = _classPrivateMethodInitSpec;
|
|
1046
|
+
exports._defineProperty = _defineProperty;
|
|
655
1047
|
exports.createClient = createClient;
|
|
656
1048
|
exports.createStorage = createStorage;
|
|
657
1049
|
exports.getClient = getClient;
|
|
1050
|
+
exports.getProvider = getProvider;
|
|
658
1051
|
exports.noopStorage = noopStorage;
|
|
659
|
-
exports.
|
|
1052
|
+
exports.normalizeChainId = normalizeChainId;
|