wagmi 0.2.21 → 0.2.24
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/dist/wagmi.cjs.dev.js +806 -976
- package/dist/wagmi.cjs.prod.js +806 -976
- package/dist/wagmi.esm.js +806 -976
- package/package.json +3 -3
package/dist/wagmi.cjs.dev.js
CHANGED
|
@@ -27,104 +27,27 @@ function _interopNamespace(e) {
|
|
|
27
27
|
|
|
28
28
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Object.defineProperty(obj, key, {
|
|
33
|
-
value: value,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
obj[key] = value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function ownKeys(object, enumerableOnly) {
|
|
46
|
-
var keys = Object.keys(object);
|
|
47
|
-
|
|
48
|
-
if (Object.getOwnPropertySymbols) {
|
|
49
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
50
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
51
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
52
|
-
})), keys.push.apply(keys, symbols);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return keys;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function _objectSpread2(target) {
|
|
59
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
60
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
61
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
62
|
-
_defineProperty(target, key, source[key]);
|
|
63
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
64
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return target;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
72
|
-
try {
|
|
73
|
-
var info = gen[key](arg);
|
|
74
|
-
var value = info.value;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
reject(error);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (info.done) {
|
|
81
|
-
resolve(value);
|
|
82
|
-
} else {
|
|
83
|
-
Promise.resolve(value).then(_next, _throw);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function _asyncToGenerator(fn) {
|
|
88
|
-
return function () {
|
|
89
|
-
var self = this,
|
|
90
|
-
args = arguments;
|
|
91
|
-
return new Promise(function (resolve, reject) {
|
|
92
|
-
var gen = fn.apply(self, args);
|
|
93
|
-
|
|
94
|
-
function _next(value) {
|
|
95
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function _throw(err) {
|
|
99
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
_next(undefined);
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
var useProvider = () => {
|
|
108
|
-
var {
|
|
30
|
+
const useProvider = () => {
|
|
31
|
+
const {
|
|
109
32
|
state
|
|
110
33
|
} = useContext();
|
|
111
34
|
return state.provider;
|
|
112
35
|
};
|
|
113
36
|
|
|
114
|
-
|
|
115
|
-
|
|
37
|
+
const useWebSocketProvider = () => {
|
|
38
|
+
const {
|
|
116
39
|
state
|
|
117
40
|
} = useContext();
|
|
118
41
|
return state.webSocketProvider;
|
|
119
42
|
};
|
|
120
43
|
|
|
121
|
-
|
|
122
|
-
|
|
44
|
+
const useCacheBuster = () => {
|
|
45
|
+
const context = useContext();
|
|
123
46
|
return context.state.cacheBuster;
|
|
124
47
|
};
|
|
125
48
|
|
|
126
|
-
|
|
127
|
-
|
|
49
|
+
const useCancel = () => {
|
|
50
|
+
const cancelCallback = React__namespace.useRef(null);
|
|
128
51
|
React__namespace.useEffect(() => {
|
|
129
52
|
return () => {
|
|
130
53
|
var _cancelCallback$curre;
|
|
@@ -132,7 +55,7 @@ var useCancel = () => {
|
|
|
132
55
|
return (_cancelCallback$curre = cancelCallback.current) === null || _cancelCallback$curre === void 0 ? void 0 : _cancelCallback$curre.call(cancelCallback);
|
|
133
56
|
};
|
|
134
57
|
}, []);
|
|
135
|
-
|
|
58
|
+
const cancel = React__namespace.useCallback(callback => {
|
|
136
59
|
var _cancelCallback$curre2;
|
|
137
60
|
|
|
138
61
|
(_cancelCallback$curre2 = cancelCallback.current) === null || _cancelCallback$curre2 === void 0 ? void 0 : _cancelCallback$curre2.call(cancelCallback);
|
|
@@ -141,11 +64,11 @@ var useCancel = () => {
|
|
|
141
64
|
return cancel;
|
|
142
65
|
};
|
|
143
66
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
67
|
+
const useLocalStorage = function (key) {
|
|
68
|
+
let defaultState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
69
|
+
const [value, setValue] = React__namespace.useState(() => {
|
|
147
70
|
if (typeof localStorage === 'undefined') return defaultState;
|
|
148
|
-
|
|
71
|
+
const value = localStorage.getItem(key);
|
|
149
72
|
|
|
150
73
|
try {
|
|
151
74
|
return value ? JSON.parse(value) : defaultState;
|
|
@@ -154,7 +77,7 @@ var useLocalStorage = function useLocalStorage(key) {
|
|
|
154
77
|
return defaultState;
|
|
155
78
|
}
|
|
156
79
|
});
|
|
157
|
-
|
|
80
|
+
const setLocalStorage = React__namespace.useCallback(newValue => {
|
|
158
81
|
if (newValue === value) return;
|
|
159
82
|
setValue(newValue);
|
|
160
83
|
if (newValue === null) localStorage.removeItem(key);else localStorage.setItem(key, JSON.stringify(newValue));
|
|
@@ -172,62 +95,56 @@ var useLocalStorage = function useLocalStorage(key) {
|
|
|
172
95
|
return [value, setLocalStorage];
|
|
173
96
|
};
|
|
174
97
|
|
|
175
|
-
|
|
98
|
+
const initialState$g = {
|
|
176
99
|
loading: false
|
|
177
100
|
};
|
|
178
|
-
|
|
179
|
-
|
|
101
|
+
const useEnsAvatar = function () {
|
|
102
|
+
let {
|
|
180
103
|
addressOrName,
|
|
181
104
|
skip
|
|
182
105
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
var config_ = config !== null && config !== void 0 ? config : {
|
|
196
|
-
addressOrName
|
|
197
|
-
};
|
|
198
|
-
if (!config_.addressOrName) throw new Error('addressOrName is required');
|
|
199
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
200
|
-
error: undefined,
|
|
201
|
-
loading: true
|
|
202
|
-
}));
|
|
203
|
-
var avatar = yield provider.getAvatar(config_.addressOrName);
|
|
106
|
+
const cacheBuster = useCacheBuster();
|
|
107
|
+
const provider = useProvider();
|
|
108
|
+
const [state, setState] = React__namespace.useState(initialState$g);
|
|
109
|
+
const cancelQuery = useCancel();
|
|
110
|
+
const getEnsAvatar = React__namespace.useCallback(async config => {
|
|
111
|
+
let didCancel = false;
|
|
112
|
+
cancelQuery(() => {
|
|
113
|
+
didCancel = true;
|
|
114
|
+
});
|
|
204
115
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
116
|
+
try {
|
|
117
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
118
|
+
addressOrName
|
|
119
|
+
};
|
|
120
|
+
if (!config_.addressOrName) throw new Error('addressOrName is required');
|
|
121
|
+
setState(x => ({ ...x,
|
|
122
|
+
error: undefined,
|
|
123
|
+
loading: true
|
|
124
|
+
}));
|
|
125
|
+
const avatar = await provider.getAvatar(config_.addressOrName);
|
|
211
126
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
127
|
+
if (!didCancel) {
|
|
128
|
+
setState(x => ({ ...x,
|
|
129
|
+
avatar,
|
|
130
|
+
loading: false
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
215
133
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
loading: false
|
|
220
|
-
}));
|
|
221
|
-
}
|
|
134
|
+
return avatar;
|
|
135
|
+
} catch (error_) {
|
|
136
|
+
const error = error_;
|
|
222
137
|
|
|
223
|
-
|
|
138
|
+
if (!didCancel) {
|
|
139
|
+
setState(x => ({ ...x,
|
|
140
|
+
error,
|
|
141
|
+
loading: false
|
|
142
|
+
}));
|
|
224
143
|
}
|
|
225
|
-
});
|
|
226
144
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}(), [addressOrName, cancelQuery, provider]); // Fetch avatar when deps or chain changes
|
|
145
|
+
return error;
|
|
146
|
+
}
|
|
147
|
+
}, [addressOrName, cancelQuery, provider]); // Fetch avatar when deps or chain changes
|
|
231
148
|
|
|
232
149
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
233
150
|
|
|
@@ -247,68 +164,62 @@ var useEnsAvatar = function useEnsAvatar() {
|
|
|
247
164
|
}, getEnsAvatar];
|
|
248
165
|
};
|
|
249
166
|
|
|
250
|
-
|
|
167
|
+
const initialState$f = {
|
|
251
168
|
loading: false
|
|
252
169
|
};
|
|
253
|
-
|
|
254
|
-
|
|
170
|
+
const useEnsLookup = function () {
|
|
171
|
+
let {
|
|
255
172
|
address,
|
|
256
173
|
skip
|
|
257
174
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
});
|
|
175
|
+
const cacheBuster = useCacheBuster();
|
|
176
|
+
const provider = useProvider();
|
|
177
|
+
const [state, setState] = React__namespace.useState(initialState$f);
|
|
178
|
+
const cancelQuery = useCancel();
|
|
179
|
+
const lookupAddress = React__namespace.useCallback(async config => {
|
|
180
|
+
let didCancel = false;
|
|
181
|
+
cancelQuery(() => {
|
|
182
|
+
didCancel = true;
|
|
183
|
+
});
|
|
268
184
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
185
|
+
try {
|
|
186
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
187
|
+
address
|
|
188
|
+
};
|
|
189
|
+
if (!config_.address) throw new Error('address is required');
|
|
190
|
+
setState(x => ({ ...x,
|
|
191
|
+
error: undefined,
|
|
192
|
+
loading: true
|
|
193
|
+
}));
|
|
194
|
+
const ens = await provider.lookupAddress(config_.address);
|
|
279
195
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
196
|
+
if (!didCancel) {
|
|
197
|
+
setState(x => ({ ...x,
|
|
198
|
+
ens,
|
|
199
|
+
loading: false
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
286
202
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (!didCancel) {
|
|
295
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
296
|
-
error,
|
|
297
|
-
loading: false
|
|
298
|
-
}));
|
|
299
|
-
}
|
|
203
|
+
return {
|
|
204
|
+
data: ens,
|
|
205
|
+
error: undefined
|
|
206
|
+
};
|
|
207
|
+
} catch (error_) {
|
|
208
|
+
const error = error_;
|
|
300
209
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
error
|
|
304
|
-
|
|
210
|
+
if (!didCancel) {
|
|
211
|
+
setState(x => ({ ...x,
|
|
212
|
+
error,
|
|
213
|
+
loading: false
|
|
214
|
+
}));
|
|
305
215
|
}
|
|
306
|
-
});
|
|
307
216
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
217
|
+
return {
|
|
218
|
+
data: undefined,
|
|
219
|
+
error
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}, [address, cancelQuery, provider]); // Resolve name when deps or chain changes
|
|
312
223
|
|
|
313
224
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
314
225
|
|
|
@@ -328,68 +239,62 @@ var useEnsLookup = function useEnsLookup() {
|
|
|
328
239
|
}, lookupAddress];
|
|
329
240
|
};
|
|
330
241
|
|
|
331
|
-
|
|
242
|
+
const initialState$e = {
|
|
332
243
|
loading: false
|
|
333
244
|
};
|
|
334
|
-
|
|
335
|
-
|
|
245
|
+
const useEnsResolveName = function () {
|
|
246
|
+
let {
|
|
336
247
|
name,
|
|
337
248
|
skip
|
|
338
249
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
});
|
|
250
|
+
const cacheBuster = useCacheBuster();
|
|
251
|
+
const provider = useProvider();
|
|
252
|
+
const [state, setState] = React__namespace.useState(initialState$e);
|
|
253
|
+
const cancelQuery = useCancel();
|
|
254
|
+
const resolveName = React__namespace.useCallback(async config => {
|
|
255
|
+
let didCancel = false;
|
|
256
|
+
cancelQuery(() => {
|
|
257
|
+
didCancel = true;
|
|
258
|
+
});
|
|
349
259
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
260
|
+
try {
|
|
261
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
262
|
+
name
|
|
263
|
+
};
|
|
264
|
+
if (!config_.name) throw new Error('name is required');
|
|
265
|
+
setState(x => ({ ...x,
|
|
266
|
+
error: undefined,
|
|
267
|
+
loading: true
|
|
268
|
+
}));
|
|
269
|
+
const address = await provider.resolveName(config_.name);
|
|
360
270
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
271
|
+
if (!didCancel) {
|
|
272
|
+
setState(x => ({ ...x,
|
|
273
|
+
address,
|
|
274
|
+
loading: false
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
367
277
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (!didCancel) {
|
|
376
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
377
|
-
error,
|
|
378
|
-
loading: false
|
|
379
|
-
}));
|
|
380
|
-
}
|
|
278
|
+
return {
|
|
279
|
+
data: address,
|
|
280
|
+
error: undefined
|
|
281
|
+
};
|
|
282
|
+
} catch (error_) {
|
|
283
|
+
const error = error_;
|
|
381
284
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
error
|
|
385
|
-
|
|
285
|
+
if (!didCancel) {
|
|
286
|
+
setState(x => ({ ...x,
|
|
287
|
+
error,
|
|
288
|
+
loading: false
|
|
289
|
+
}));
|
|
386
290
|
}
|
|
387
|
-
});
|
|
388
291
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
292
|
+
return {
|
|
293
|
+
data: undefined,
|
|
294
|
+
error
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}, [name, cancelQuery, provider]); // Resolve name when deps or chain changes
|
|
393
298
|
|
|
394
299
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
395
300
|
|
|
@@ -409,68 +314,62 @@ var useEnsResolveName = function useEnsResolveName() {
|
|
|
409
314
|
}, resolveName];
|
|
410
315
|
};
|
|
411
316
|
|
|
412
|
-
|
|
317
|
+
const initialState$d = {
|
|
413
318
|
loading: false
|
|
414
319
|
};
|
|
415
|
-
|
|
416
|
-
|
|
320
|
+
const useEnsResolver = function () {
|
|
321
|
+
let {
|
|
417
322
|
name,
|
|
418
323
|
skip
|
|
419
324
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
});
|
|
325
|
+
const cacheBuster = useCacheBuster();
|
|
326
|
+
const provider = useProvider();
|
|
327
|
+
const [state, setState] = React__namespace.useState(initialState$d);
|
|
328
|
+
const cancelQuery = useCancel();
|
|
329
|
+
const getEnsResolver = React__namespace.useCallback(async config => {
|
|
330
|
+
let didCancel = false;
|
|
331
|
+
cancelQuery(() => {
|
|
332
|
+
didCancel = true;
|
|
333
|
+
});
|
|
430
334
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
335
|
+
try {
|
|
336
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
337
|
+
name
|
|
338
|
+
};
|
|
339
|
+
if (!config_.name) throw new Error('name is required');
|
|
340
|
+
setState(x => ({ ...x,
|
|
341
|
+
error: undefined,
|
|
342
|
+
loading: true
|
|
343
|
+
}));
|
|
344
|
+
const resolver = await provider.getResolver(config_.name);
|
|
441
345
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
346
|
+
if (!didCancel) {
|
|
347
|
+
setState(x => ({ ...x,
|
|
348
|
+
loading: false,
|
|
349
|
+
resolver
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
448
352
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if (!didCancel) {
|
|
457
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
458
|
-
error,
|
|
459
|
-
loading: false
|
|
460
|
-
}));
|
|
461
|
-
}
|
|
353
|
+
return {
|
|
354
|
+
data: resolver,
|
|
355
|
+
error: undefined
|
|
356
|
+
};
|
|
357
|
+
} catch (error_) {
|
|
358
|
+
const error = error_;
|
|
462
359
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
error
|
|
466
|
-
|
|
360
|
+
if (!didCancel) {
|
|
361
|
+
setState(x => ({ ...x,
|
|
362
|
+
error,
|
|
363
|
+
loading: false
|
|
364
|
+
}));
|
|
467
365
|
}
|
|
468
|
-
});
|
|
469
366
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
367
|
+
return {
|
|
368
|
+
data: undefined,
|
|
369
|
+
error
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}, [cancelQuery, name, provider]); // Fetch avatar when deps or chain changes
|
|
474
373
|
|
|
475
374
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
476
375
|
|
|
@@ -490,18 +389,18 @@ var useEnsResolver = function useEnsResolver() {
|
|
|
490
389
|
}, getEnsResolver];
|
|
491
390
|
};
|
|
492
391
|
|
|
493
|
-
|
|
392
|
+
const useAccount = function () {
|
|
494
393
|
var _globalState$data;
|
|
495
394
|
|
|
496
|
-
|
|
395
|
+
let {
|
|
497
396
|
fetchEns
|
|
498
397
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
499
|
-
|
|
398
|
+
const {
|
|
500
399
|
state: globalState,
|
|
501
400
|
setState
|
|
502
401
|
} = useContext();
|
|
503
|
-
|
|
504
|
-
|
|
402
|
+
const address = (_globalState$data = globalState.data) === null || _globalState$data === void 0 ? void 0 : _globalState$data.account;
|
|
403
|
+
const [{
|
|
505
404
|
data: ens,
|
|
506
405
|
error: ensError,
|
|
507
406
|
loading: ensLoading
|
|
@@ -509,7 +408,7 @@ var useAccount = function useAccount() {
|
|
|
509
408
|
address,
|
|
510
409
|
skip: !fetchEns
|
|
511
410
|
});
|
|
512
|
-
|
|
411
|
+
const [{
|
|
513
412
|
data: avatar,
|
|
514
413
|
error: avatarError,
|
|
515
414
|
loading: avatarLoading
|
|
@@ -517,7 +416,7 @@ var useAccount = function useAccount() {
|
|
|
517
416
|
addressOrName: ens,
|
|
518
417
|
skip: !fetchEns || !ens
|
|
519
418
|
});
|
|
520
|
-
|
|
419
|
+
const disconnect = React__namespace.useCallback(() => {
|
|
521
420
|
setState(x => {
|
|
522
421
|
var _x$connector;
|
|
523
422
|
|
|
@@ -527,8 +426,8 @@ var useAccount = function useAccount() {
|
|
|
527
426
|
};
|
|
528
427
|
});
|
|
529
428
|
}, [setState]);
|
|
530
|
-
|
|
531
|
-
|
|
429
|
+
const error = ensError || avatarError;
|
|
430
|
+
const loading = ensLoading || avatarLoading;
|
|
532
431
|
return [{
|
|
533
432
|
data: address ? {
|
|
534
433
|
address,
|
|
@@ -543,34 +442,34 @@ var useAccount = function useAccount() {
|
|
|
543
442
|
}, disconnect];
|
|
544
443
|
};
|
|
545
444
|
|
|
546
|
-
|
|
445
|
+
const initialState$c = {
|
|
547
446
|
loading: false
|
|
548
447
|
};
|
|
549
|
-
|
|
550
|
-
|
|
448
|
+
const useBlockNumber = function () {
|
|
449
|
+
let {
|
|
551
450
|
skip,
|
|
552
451
|
watch
|
|
553
452
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
453
|
+
const cacheBuster = useCacheBuster();
|
|
454
|
+
const provider = useProvider();
|
|
455
|
+
const webSocketProvider = useWebSocketProvider();
|
|
456
|
+
const [state, setState] = React__namespace.useState(initialState$c);
|
|
457
|
+
const cancelQuery = useCancel();
|
|
458
|
+
const getBlockNumber = React__namespace.useCallback(async () => {
|
|
459
|
+
let didCancel = false;
|
|
561
460
|
cancelQuery(() => {
|
|
562
461
|
didCancel = true;
|
|
563
462
|
});
|
|
564
463
|
|
|
565
464
|
try {
|
|
566
|
-
setState(x =>
|
|
465
|
+
setState(x => ({ ...x,
|
|
567
466
|
error: undefined,
|
|
568
467
|
loading: true
|
|
569
468
|
}));
|
|
570
|
-
|
|
469
|
+
const blockNumber = await provider.getBlockNumber();
|
|
571
470
|
|
|
572
471
|
if (!didCancel) {
|
|
573
|
-
setState(x =>
|
|
472
|
+
setState(x => ({ ...x,
|
|
574
473
|
blockNumber,
|
|
575
474
|
loading: false
|
|
576
475
|
}));
|
|
@@ -581,10 +480,10 @@ var useBlockNumber = function useBlockNumber() {
|
|
|
581
480
|
error: undefined
|
|
582
481
|
};
|
|
583
482
|
} catch (error_) {
|
|
584
|
-
|
|
483
|
+
const error = error_;
|
|
585
484
|
|
|
586
485
|
if (!didCancel) {
|
|
587
|
-
setState(x =>
|
|
486
|
+
setState(x => ({ ...x,
|
|
588
487
|
error,
|
|
589
488
|
loading: false
|
|
590
489
|
}));
|
|
@@ -595,7 +494,7 @@ var useBlockNumber = function useBlockNumber() {
|
|
|
595
494
|
error
|
|
596
495
|
};
|
|
597
496
|
}
|
|
598
|
-
}
|
|
497
|
+
}, [cancelQuery, provider]);
|
|
599
498
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
600
499
|
|
|
601
500
|
React__namespace.useEffect(() => {
|
|
@@ -607,19 +506,19 @@ var useBlockNumber = function useBlockNumber() {
|
|
|
607
506
|
|
|
608
507
|
React__namespace.useEffect(() => {
|
|
609
508
|
if (!watch) return;
|
|
610
|
-
|
|
509
|
+
let didCancel = false;
|
|
611
510
|
|
|
612
|
-
|
|
511
|
+
const listener = blockNumber => {
|
|
613
512
|
// Just to be safe in case the provider implementation
|
|
614
513
|
// calls the event callback after .off() has been called
|
|
615
514
|
if (!didCancel) {
|
|
616
|
-
setState(x =>
|
|
515
|
+
setState(x => ({ ...x,
|
|
617
516
|
blockNumber
|
|
618
517
|
}));
|
|
619
518
|
}
|
|
620
519
|
};
|
|
621
520
|
|
|
622
|
-
|
|
521
|
+
const provider_ = webSocketProvider !== null && webSocketProvider !== void 0 ? webSocketProvider : provider;
|
|
623
522
|
provider_.on('block', listener);
|
|
624
523
|
return () => {
|
|
625
524
|
didCancel = true;
|
|
@@ -633,40 +532,40 @@ var useBlockNumber = function useBlockNumber() {
|
|
|
633
532
|
}, getBlockNumber];
|
|
634
533
|
};
|
|
635
534
|
|
|
636
|
-
|
|
535
|
+
const initialState$b = {
|
|
637
536
|
loading: false
|
|
638
537
|
};
|
|
639
|
-
|
|
640
|
-
|
|
538
|
+
const useFeeData = function () {
|
|
539
|
+
let {
|
|
641
540
|
formatUnits = 'wei',
|
|
642
541
|
skip,
|
|
643
542
|
watch
|
|
644
543
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
645
|
-
|
|
646
|
-
|
|
544
|
+
const provider = useProvider();
|
|
545
|
+
const [{
|
|
647
546
|
data: blockNumber
|
|
648
547
|
}] = useBlockNumber({
|
|
649
548
|
skip: true,
|
|
650
549
|
watch
|
|
651
550
|
});
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
551
|
+
const cacheBuster = useCacheBuster();
|
|
552
|
+
const [state, setState] = React__namespace.useState(initialState$b);
|
|
553
|
+
const cancelQuery = useCancel();
|
|
554
|
+
const getFeeData = React__namespace.useCallback(async () => {
|
|
555
|
+
let didCancel = false;
|
|
657
556
|
cancelQuery(() => {
|
|
658
557
|
didCancel = true;
|
|
659
558
|
});
|
|
660
559
|
|
|
661
560
|
try {
|
|
662
|
-
setState(x =>
|
|
561
|
+
setState(x => ({ ...x,
|
|
663
562
|
error: undefined,
|
|
664
563
|
loading: true
|
|
665
564
|
}));
|
|
666
|
-
|
|
565
|
+
const feeData = await provider.getFeeData();
|
|
667
566
|
|
|
668
567
|
if (!didCancel) {
|
|
669
|
-
setState(x =>
|
|
568
|
+
setState(x => ({ ...x,
|
|
670
569
|
feeData,
|
|
671
570
|
loading: false
|
|
672
571
|
}));
|
|
@@ -677,10 +576,10 @@ var useFeeData = function useFeeData() {
|
|
|
677
576
|
error: undefined
|
|
678
577
|
};
|
|
679
578
|
} catch (error_) {
|
|
680
|
-
|
|
579
|
+
const error = error_;
|
|
681
580
|
|
|
682
581
|
if (!didCancel) {
|
|
683
|
-
setState(x =>
|
|
582
|
+
setState(x => ({ ...x,
|
|
684
583
|
error,
|
|
685
584
|
loading: false
|
|
686
585
|
}));
|
|
@@ -691,7 +590,7 @@ var useFeeData = function useFeeData() {
|
|
|
691
590
|
error
|
|
692
591
|
};
|
|
693
592
|
}
|
|
694
|
-
}
|
|
593
|
+
}, [cancelQuery, provider]); // Fetch feeData on mount or when chain changes
|
|
695
594
|
|
|
696
595
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
697
596
|
|
|
@@ -707,96 +606,90 @@ var useFeeData = function useFeeData() {
|
|
|
707
606
|
getFeeData();
|
|
708
607
|
return cancelQuery;
|
|
709
608
|
}, [blockNumber, cancelQuery, getFeeData, watch]);
|
|
710
|
-
|
|
609
|
+
const formatted = state.feeData ? {
|
|
711
610
|
gasPrice: ethers.utils.formatUnits(state.feeData.gasPrice, formatUnits),
|
|
712
611
|
maxFeePerGas: ethers.utils.formatUnits(state.feeData.maxFeePerGas, formatUnits),
|
|
713
612
|
maxPriorityFeePerGas: ethers.utils.formatUnits(state.feeData.maxPriorityFeePerGas, formatUnits)
|
|
714
613
|
} : undefined;
|
|
715
614
|
return [{
|
|
716
|
-
data: state.feeData ?
|
|
615
|
+
data: state.feeData ? { ...state.feeData,
|
|
717
616
|
formatted
|
|
718
|
-
}
|
|
617
|
+
} : undefined,
|
|
719
618
|
loading: state.loading,
|
|
720
619
|
error: state.error
|
|
721
620
|
}, getFeeData];
|
|
722
621
|
};
|
|
723
622
|
|
|
724
|
-
|
|
623
|
+
const initialState$a = {
|
|
725
624
|
loading: false
|
|
726
625
|
};
|
|
727
|
-
|
|
728
|
-
|
|
626
|
+
const useBalance = function () {
|
|
627
|
+
let {
|
|
729
628
|
addressOrName,
|
|
730
629
|
formatUnits = 'ether',
|
|
731
630
|
skip,
|
|
732
631
|
token,
|
|
733
632
|
watch
|
|
734
633
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
735
|
-
|
|
634
|
+
const {
|
|
736
635
|
state: {
|
|
737
636
|
connector
|
|
738
637
|
}
|
|
739
638
|
} = useContext();
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
639
|
+
const cacheBuster = useCacheBuster();
|
|
640
|
+
const provider = useProvider();
|
|
641
|
+
const [{
|
|
743
642
|
data: blockNumber
|
|
744
643
|
}] = useBlockNumber({
|
|
745
644
|
skip: true,
|
|
746
645
|
watch
|
|
747
646
|
});
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
didCancel = true;
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
try {
|
|
758
|
-
var _connector$chains;
|
|
759
|
-
|
|
760
|
-
var config_ = config !== null && config !== void 0 ? config : {
|
|
761
|
-
addressOrName,
|
|
762
|
-
formatUnits,
|
|
763
|
-
token
|
|
764
|
-
};
|
|
765
|
-
if (!config_.addressOrName) throw new Error('address is required');
|
|
766
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
767
|
-
error: undefined,
|
|
768
|
-
loading: true
|
|
769
|
-
}));
|
|
770
|
-
var balance = yield wagmiCore.balanceAction({
|
|
771
|
-
chains: [...((_connector$chains = connector === null || connector === void 0 ? void 0 : connector.chains) !== null && _connector$chains !== void 0 ? _connector$chains : []), ...wagmiCore.defaultChains, ...wagmiCore.defaultL2Chains],
|
|
772
|
-
config: config_,
|
|
773
|
-
provider
|
|
774
|
-
});
|
|
775
|
-
if (!didCancel) setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
776
|
-
balance,
|
|
777
|
-
loading: false
|
|
778
|
-
}));
|
|
779
|
-
return {
|
|
780
|
-
data: balance,
|
|
781
|
-
error: undefined
|
|
782
|
-
};
|
|
783
|
-
} catch (error_) {
|
|
784
|
-
var error = error_;
|
|
785
|
-
if (!didCancel) setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
786
|
-
error,
|
|
787
|
-
loading: false
|
|
788
|
-
}));
|
|
789
|
-
return {
|
|
790
|
-
data: undefined,
|
|
791
|
-
error
|
|
792
|
-
};
|
|
793
|
-
}
|
|
647
|
+
const [state, setState] = React__namespace.useState(initialState$a);
|
|
648
|
+
const cancelQuery = useCancel();
|
|
649
|
+
const getBalance = React__namespace.useCallback(async config => {
|
|
650
|
+
let didCancel = false;
|
|
651
|
+
cancelQuery(() => {
|
|
652
|
+
didCancel = true;
|
|
794
653
|
});
|
|
795
654
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
655
|
+
try {
|
|
656
|
+
var _connector$chains;
|
|
657
|
+
|
|
658
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
659
|
+
addressOrName,
|
|
660
|
+
formatUnits,
|
|
661
|
+
token
|
|
662
|
+
};
|
|
663
|
+
if (!config_.addressOrName) throw new Error('address is required');
|
|
664
|
+
setState(x => ({ ...x,
|
|
665
|
+
error: undefined,
|
|
666
|
+
loading: true
|
|
667
|
+
}));
|
|
668
|
+
const balance = await wagmiCore.balanceAction({
|
|
669
|
+
chains: [...((_connector$chains = connector === null || connector === void 0 ? void 0 : connector.chains) !== null && _connector$chains !== void 0 ? _connector$chains : []), ...wagmiCore.defaultChains, ...wagmiCore.defaultL2Chains],
|
|
670
|
+
config: config_,
|
|
671
|
+
provider
|
|
672
|
+
});
|
|
673
|
+
if (!didCancel) setState(x => ({ ...x,
|
|
674
|
+
balance,
|
|
675
|
+
loading: false
|
|
676
|
+
}));
|
|
677
|
+
return {
|
|
678
|
+
data: balance,
|
|
679
|
+
error: undefined
|
|
680
|
+
};
|
|
681
|
+
} catch (error_) {
|
|
682
|
+
const error = error_;
|
|
683
|
+
if (!didCancel) setState(x => ({ ...x,
|
|
684
|
+
error,
|
|
685
|
+
loading: false
|
|
686
|
+
}));
|
|
687
|
+
return {
|
|
688
|
+
data: undefined,
|
|
689
|
+
error
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
}, [addressOrName, cancelQuery, connector, formatUnits, provider, token]); // Fetch balance when deps or chain changes
|
|
800
693
|
|
|
801
694
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
802
695
|
|
|
@@ -832,77 +725,71 @@ var useBalance = function useBalance() {
|
|
|
832
725
|
}, getBalance];
|
|
833
726
|
};
|
|
834
727
|
|
|
835
|
-
|
|
728
|
+
const initialState$9 = {
|
|
836
729
|
loading: false
|
|
837
730
|
};
|
|
838
|
-
|
|
731
|
+
const useConnect = () => {
|
|
839
732
|
var _globalState$data;
|
|
840
733
|
|
|
841
|
-
|
|
734
|
+
const {
|
|
842
735
|
state: globalState,
|
|
843
736
|
setState: setGlobalState,
|
|
844
737
|
setLastUsedConnector
|
|
845
738
|
} = useContext();
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
});
|
|
739
|
+
const [state, setState] = React__namespace.useState(initialState$9);
|
|
740
|
+
const cancelQuery = useCancel();
|
|
741
|
+
const connect = React__namespace.useCallback(async connector => {
|
|
742
|
+
let didCancel = false;
|
|
743
|
+
cancelQuery(() => {
|
|
744
|
+
didCancel = true;
|
|
745
|
+
});
|
|
854
746
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
747
|
+
try {
|
|
748
|
+
const activeConnector = globalState === null || globalState === void 0 ? void 0 : globalState.connector;
|
|
749
|
+
if (connector === activeConnector) throw new wagmiCore.ConnectorAlreadyConnectedError();
|
|
750
|
+
setState(x => ({ ...x,
|
|
751
|
+
loading: true,
|
|
752
|
+
connector,
|
|
753
|
+
error: undefined
|
|
754
|
+
}));
|
|
755
|
+
const data = await connector.connect();
|
|
756
|
+
|
|
757
|
+
if (!didCancel) {
|
|
758
|
+
// Update connector globally only after successful connection
|
|
759
|
+
setGlobalState(x => ({ ...x,
|
|
860
760
|
connector,
|
|
861
|
-
|
|
761
|
+
data
|
|
862
762
|
}));
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
connector,
|
|
869
|
-
data
|
|
870
|
-
}));
|
|
871
|
-
setLastUsedConnector(connector.name);
|
|
872
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
873
|
-
loading: false
|
|
874
|
-
}));
|
|
875
|
-
}
|
|
763
|
+
setLastUsedConnector(connector.name);
|
|
764
|
+
setState(x => ({ ...x,
|
|
765
|
+
loading: false
|
|
766
|
+
}));
|
|
767
|
+
}
|
|
876
768
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
if (!didCancel) {
|
|
885
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
886
|
-
connector: undefined,
|
|
887
|
-
error,
|
|
888
|
-
loading: false
|
|
889
|
-
}));
|
|
890
|
-
}
|
|
769
|
+
return {
|
|
770
|
+
data,
|
|
771
|
+
error: undefined
|
|
772
|
+
};
|
|
773
|
+
} catch (error_) {
|
|
774
|
+
const error = error_;
|
|
891
775
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
776
|
+
if (!didCancel) {
|
|
777
|
+
setState(x => ({ ...x,
|
|
778
|
+
connector: undefined,
|
|
779
|
+
error,
|
|
780
|
+
loading: false
|
|
781
|
+
}));
|
|
896
782
|
}
|
|
897
|
-
});
|
|
898
783
|
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
784
|
+
return {
|
|
785
|
+
data: undefined,
|
|
786
|
+
error
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
}, [cancelQuery, globalState.connector, setGlobalState, setLastUsedConnector]); // Keep connector in sync with global connector
|
|
903
790
|
|
|
904
791
|
React__namespace.useEffect(() => {
|
|
905
|
-
setState(x =>
|
|
792
|
+
setState(x => ({ ...x,
|
|
906
793
|
connector: globalState.connector,
|
|
907
794
|
error: undefined
|
|
908
795
|
}));
|
|
@@ -919,79 +806,73 @@ var useConnect = () => {
|
|
|
919
806
|
}, connect];
|
|
920
807
|
};
|
|
921
808
|
|
|
922
|
-
|
|
809
|
+
const initialState$8 = {
|
|
923
810
|
loading: false
|
|
924
811
|
};
|
|
925
|
-
|
|
812
|
+
const useNetwork = () => {
|
|
926
813
|
var _data$chain, _data$chain2, _connector$chains;
|
|
927
814
|
|
|
928
|
-
|
|
815
|
+
const {
|
|
929
816
|
state: {
|
|
930
817
|
connector,
|
|
931
818
|
data
|
|
932
819
|
}
|
|
933
820
|
} = useContext();
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
};
|
|
821
|
+
const [state, setState] = React__namespace.useState(initialState$8);
|
|
822
|
+
const chainId = data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id;
|
|
823
|
+
const unsupported = data === null || data === void 0 ? void 0 : (_data$chain2 = data.chain) === null || _data$chain2 === void 0 ? void 0 : _data$chain2.unsupported;
|
|
824
|
+
const activeChains = (_connector$chains = connector === null || connector === void 0 ? void 0 : connector.chains) !== null && _connector$chains !== void 0 ? _connector$chains : [];
|
|
825
|
+
const activeChain = [...activeChains, ...wagmiCore.allChains].find(x => x.id === chainId);
|
|
826
|
+
const cancelQuery = useCancel();
|
|
827
|
+
const switchNetwork = React__namespace.useCallback(async chainId => {
|
|
828
|
+
let didCancel = false;
|
|
829
|
+
cancelQuery(() => {
|
|
830
|
+
didCancel = true;
|
|
831
|
+
});
|
|
832
|
+
if (!(connector !== null && connector !== void 0 && connector.switchChain)) return {
|
|
833
|
+
data: undefined,
|
|
834
|
+
error: new wagmiCore.SwitchChainError()
|
|
835
|
+
};
|
|
950
836
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
837
|
+
try {
|
|
838
|
+
setState(x => ({ ...x,
|
|
839
|
+
error: undefined,
|
|
840
|
+
loading: true
|
|
841
|
+
}));
|
|
842
|
+
const chain = await connector.switchChain(chainId);
|
|
957
843
|
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
844
|
+
if (!didCancel) {
|
|
845
|
+
setState(x => ({ ...x,
|
|
846
|
+
loading: false
|
|
847
|
+
}));
|
|
848
|
+
}
|
|
963
849
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (!didCancel) {
|
|
972
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
973
|
-
error,
|
|
974
|
-
loading: false
|
|
975
|
-
}));
|
|
976
|
-
}
|
|
850
|
+
return {
|
|
851
|
+
data: chain,
|
|
852
|
+
error: undefined
|
|
853
|
+
};
|
|
854
|
+
} catch (error_) {
|
|
855
|
+
const error = error_;
|
|
977
856
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
error
|
|
981
|
-
|
|
857
|
+
if (!didCancel) {
|
|
858
|
+
setState(x => ({ ...x,
|
|
859
|
+
error,
|
|
860
|
+
loading: false
|
|
861
|
+
}));
|
|
982
862
|
}
|
|
983
|
-
});
|
|
984
863
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
864
|
+
return {
|
|
865
|
+
data: undefined,
|
|
866
|
+
error
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
}, [cancelQuery, connector]);
|
|
989
870
|
return [{
|
|
990
871
|
data: {
|
|
991
|
-
chain: chainId ?
|
|
872
|
+
chain: chainId ? { ...activeChain,
|
|
992
873
|
id: chainId,
|
|
993
874
|
unsupported
|
|
994
|
-
}
|
|
875
|
+
} : undefined,
|
|
995
876
|
chains: activeChains
|
|
996
877
|
},
|
|
997
878
|
error: state.error,
|
|
@@ -999,38 +880,38 @@ var useNetwork = () => {
|
|
|
999
880
|
}, connector !== null && connector !== void 0 && connector.switchChain ? switchNetwork : undefined];
|
|
1000
881
|
};
|
|
1001
882
|
|
|
1002
|
-
|
|
883
|
+
const initialState$7 = {
|
|
1003
884
|
data: undefined,
|
|
1004
885
|
error: undefined,
|
|
1005
886
|
loading: false
|
|
1006
887
|
};
|
|
1007
|
-
|
|
1008
|
-
|
|
888
|
+
const useSigner = function () {
|
|
889
|
+
let {
|
|
1009
890
|
skip
|
|
1010
891
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1011
|
-
|
|
1012
|
-
|
|
892
|
+
const cacheBuster = useCacheBuster();
|
|
893
|
+
const {
|
|
1013
894
|
state: {
|
|
1014
895
|
connector
|
|
1015
896
|
}
|
|
1016
897
|
} = useContext();
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
898
|
+
const [state, setState] = React__namespace.useState(initialState$7);
|
|
899
|
+
const cancelQuery = useCancel();
|
|
900
|
+
const getSigner = React__namespace.useCallback(async () => {
|
|
901
|
+
let didCancel = false;
|
|
1021
902
|
cancelQuery(() => {
|
|
1022
903
|
didCancel = true;
|
|
1023
904
|
});
|
|
1024
905
|
|
|
1025
906
|
try {
|
|
1026
|
-
setState(x =>
|
|
907
|
+
setState(x => ({ ...x,
|
|
1027
908
|
error: undefined,
|
|
1028
909
|
loading: true
|
|
1029
910
|
}));
|
|
1030
|
-
|
|
911
|
+
const signer = await (connector === null || connector === void 0 ? void 0 : connector.getSigner());
|
|
1031
912
|
|
|
1032
913
|
if (!didCancel) {
|
|
1033
|
-
setState(x =>
|
|
914
|
+
setState(x => ({ ...x,
|
|
1034
915
|
data: signer,
|
|
1035
916
|
loading: false
|
|
1036
917
|
}));
|
|
@@ -1038,17 +919,17 @@ var useSigner = function useSigner() {
|
|
|
1038
919
|
|
|
1039
920
|
return signer;
|
|
1040
921
|
} catch (error_) {
|
|
1041
|
-
|
|
922
|
+
const error = error_;
|
|
1042
923
|
|
|
1043
924
|
if (!didCancel) {
|
|
1044
|
-
setState(x =>
|
|
925
|
+
setState(x => ({ ...x,
|
|
1045
926
|
data: undefined,
|
|
1046
927
|
error,
|
|
1047
928
|
loading: false
|
|
1048
929
|
}));
|
|
1049
930
|
}
|
|
1050
931
|
}
|
|
1051
|
-
}
|
|
932
|
+
}, [cancelQuery, connector]);
|
|
1052
933
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1053
934
|
|
|
1054
935
|
React__namespace.useEffect(() => {
|
|
@@ -1061,73 +942,67 @@ var useSigner = function useSigner() {
|
|
|
1061
942
|
return [state, getSigner];
|
|
1062
943
|
};
|
|
1063
944
|
|
|
1064
|
-
|
|
945
|
+
const initialState$6 = {
|
|
1065
946
|
loading: false
|
|
1066
947
|
};
|
|
1067
|
-
|
|
1068
|
-
|
|
948
|
+
const useSignMessage = function () {
|
|
949
|
+
let {
|
|
1069
950
|
message
|
|
1070
951
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1071
|
-
|
|
952
|
+
const {
|
|
1072
953
|
state: {
|
|
1073
954
|
connector
|
|
1074
955
|
}
|
|
1075
956
|
} = useContext();
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
});
|
|
957
|
+
const [state, setState] = React__namespace.useState(initialState$6);
|
|
958
|
+
const cancelQuery = useCancel();
|
|
959
|
+
const signMessage = React__namespace.useCallback(async config => {
|
|
960
|
+
let didCancel = false;
|
|
961
|
+
cancelQuery(() => {
|
|
962
|
+
didCancel = true;
|
|
963
|
+
});
|
|
1084
964
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
965
|
+
try {
|
|
966
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
967
|
+
message
|
|
968
|
+
};
|
|
969
|
+
if (!config_.message) throw new Error('message is required');
|
|
970
|
+
if (!connector) throw new wagmiCore.ConnectorNotFoundError();
|
|
971
|
+
setState(x => ({ ...x,
|
|
972
|
+
error: undefined,
|
|
973
|
+
loading: true
|
|
974
|
+
}));
|
|
975
|
+
const signer = await connector.getSigner();
|
|
976
|
+
const signature = await signer.signMessage(config_.message);
|
|
977
|
+
|
|
978
|
+
if (!didCancel) {
|
|
979
|
+
setState(x => ({ ...x,
|
|
980
|
+
signature,
|
|
981
|
+
loading: false
|
|
1094
982
|
}));
|
|
1095
|
-
|
|
1096
|
-
var signature = yield signer.signMessage(config_.message);
|
|
1097
|
-
|
|
1098
|
-
if (!didCancel) {
|
|
1099
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1100
|
-
signature,
|
|
1101
|
-
loading: false
|
|
1102
|
-
}));
|
|
1103
|
-
}
|
|
983
|
+
}
|
|
1104
984
|
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
if (!didCancel) {
|
|
1114
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1115
|
-
error,
|
|
1116
|
-
loading: false
|
|
1117
|
-
}));
|
|
1118
|
-
}
|
|
985
|
+
return {
|
|
986
|
+
data: signature,
|
|
987
|
+
error: undefined
|
|
988
|
+
};
|
|
989
|
+
} catch (error_) {
|
|
990
|
+
let error = error_;
|
|
991
|
+
if (error_.code === 4001) error = new wagmiCore.UserRejectedRequestError();
|
|
1119
992
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
error
|
|
1123
|
-
|
|
993
|
+
if (!didCancel) {
|
|
994
|
+
setState(x => ({ ...x,
|
|
995
|
+
error,
|
|
996
|
+
loading: false
|
|
997
|
+
}));
|
|
1124
998
|
}
|
|
1125
|
-
});
|
|
1126
999
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1000
|
+
return {
|
|
1001
|
+
data: undefined,
|
|
1002
|
+
error
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
}, [cancelQuery, connector, message]);
|
|
1131
1006
|
return [{
|
|
1132
1007
|
data: state.signature,
|
|
1133
1008
|
error: state.error,
|
|
@@ -1135,80 +1010,74 @@ var useSignMessage = function useSignMessage() {
|
|
|
1135
1010
|
}, signMessage];
|
|
1136
1011
|
};
|
|
1137
1012
|
|
|
1138
|
-
|
|
1013
|
+
const initialState$5 = {
|
|
1139
1014
|
loading: false
|
|
1140
1015
|
};
|
|
1141
|
-
|
|
1142
|
-
|
|
1016
|
+
const useSignTypedData = function () {
|
|
1017
|
+
let {
|
|
1143
1018
|
domain,
|
|
1144
1019
|
types,
|
|
1145
1020
|
value
|
|
1146
1021
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1147
|
-
|
|
1022
|
+
const {
|
|
1148
1023
|
state: {
|
|
1149
1024
|
connector
|
|
1150
1025
|
}
|
|
1151
1026
|
} = useContext();
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
});
|
|
1027
|
+
const [state, setState] = React__namespace.useState(initialState$5);
|
|
1028
|
+
const cancelQuery = useCancel();
|
|
1029
|
+
const signTypedData = React__namespace.useCallback(async config => {
|
|
1030
|
+
let didCancel = false;
|
|
1031
|
+
cancelQuery(() => {
|
|
1032
|
+
didCancel = true;
|
|
1033
|
+
});
|
|
1160
1034
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1035
|
+
try {
|
|
1036
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
1037
|
+
domain,
|
|
1038
|
+
types,
|
|
1039
|
+
value
|
|
1040
|
+
};
|
|
1041
|
+
if (!config_.domain) throw new Error('domain is required');
|
|
1042
|
+
if (!config_.types) throw new Error('type is required');
|
|
1043
|
+
if (!config_.value) throw new Error('value is required');
|
|
1044
|
+
if (!connector) throw new wagmiCore.ConnectorNotFoundError();
|
|
1045
|
+
setState(x => ({ ...x,
|
|
1046
|
+
error: undefined,
|
|
1047
|
+
loading: true
|
|
1048
|
+
}));
|
|
1049
|
+
const signer = await connector.getSigner(); // Method name may be changed in the future, see https://docs.ethers.io/v5/api/signer/#Signer-signTypedData
|
|
1176
1050
|
|
|
1177
|
-
|
|
1051
|
+
const signature = await signer._signTypedData(config_.domain, config_.types, config_.value);
|
|
1178
1052
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1053
|
+
if (!didCancel) {
|
|
1054
|
+
setState(x => ({ ...x,
|
|
1055
|
+
signature,
|
|
1056
|
+
loading: false
|
|
1057
|
+
}));
|
|
1058
|
+
}
|
|
1185
1059
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
if (!didCancel) {
|
|
1195
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1196
|
-
error,
|
|
1197
|
-
loading: false
|
|
1198
|
-
}));
|
|
1199
|
-
}
|
|
1060
|
+
return {
|
|
1061
|
+
data: signature,
|
|
1062
|
+
error: undefined
|
|
1063
|
+
};
|
|
1064
|
+
} catch (error_) {
|
|
1065
|
+
let error = error_;
|
|
1066
|
+
if (error_.code === 4001) error = new wagmiCore.UserRejectedRequestError();
|
|
1200
1067
|
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
error
|
|
1204
|
-
|
|
1068
|
+
if (!didCancel) {
|
|
1069
|
+
setState(x => ({ ...x,
|
|
1070
|
+
error,
|
|
1071
|
+
loading: false
|
|
1072
|
+
}));
|
|
1205
1073
|
}
|
|
1206
|
-
});
|
|
1207
1074
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1075
|
+
return {
|
|
1076
|
+
data: undefined,
|
|
1077
|
+
error
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
}, [cancelQuery, connector, domain, types, value]);
|
|
1212
1081
|
return [{
|
|
1213
1082
|
data: state.signature,
|
|
1214
1083
|
error: state.error,
|
|
@@ -1216,8 +1085,8 @@ var useSignTypedData = function useSignTypedData() {
|
|
|
1216
1085
|
}, signTypedData];
|
|
1217
1086
|
};
|
|
1218
1087
|
|
|
1219
|
-
|
|
1220
|
-
|
|
1088
|
+
const getContract = _ref => {
|
|
1089
|
+
let {
|
|
1221
1090
|
addressOrName,
|
|
1222
1091
|
contractInterface,
|
|
1223
1092
|
signerOrProvider
|
|
@@ -1225,8 +1094,8 @@ var getContract = _ref => {
|
|
|
1225
1094
|
return new ethers.Contract(addressOrName, contractInterface, signerOrProvider);
|
|
1226
1095
|
};
|
|
1227
1096
|
|
|
1228
|
-
|
|
1229
|
-
|
|
1097
|
+
const useContract = _ref2 => {
|
|
1098
|
+
let {
|
|
1230
1099
|
addressOrName,
|
|
1231
1100
|
contractInterface,
|
|
1232
1101
|
signerOrProvider
|
|
@@ -1240,21 +1109,22 @@ var useContract = _ref2 => {
|
|
|
1240
1109
|
}, [addressOrName, contractInterface, signerOrProvider]);
|
|
1241
1110
|
};
|
|
1242
1111
|
|
|
1243
|
-
|
|
1244
|
-
|
|
1112
|
+
const useContractEvent = function (contractConfig, eventName, listener) {
|
|
1113
|
+
let {
|
|
1245
1114
|
once
|
|
1246
1115
|
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
signerOrProvider: webSocketProvider !== null && webSocketProvider !== void 0 ? webSocketProvider : provider
|
|
1251
|
-
|
|
1252
|
-
|
|
1116
|
+
const provider = useProvider();
|
|
1117
|
+
const webSocketProvider = useWebSocketProvider();
|
|
1118
|
+
const contract = useContract({
|
|
1119
|
+
signerOrProvider: webSocketProvider !== null && webSocketProvider !== void 0 ? webSocketProvider : provider,
|
|
1120
|
+
...contractConfig
|
|
1121
|
+
});
|
|
1122
|
+
const listenerRef = React__namespace.useRef(listener);
|
|
1253
1123
|
listenerRef.current = listener;
|
|
1254
1124
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1255
1125
|
|
|
1256
1126
|
React__namespace.useEffect(() => {
|
|
1257
|
-
|
|
1127
|
+
const handler = function () {
|
|
1258
1128
|
for (var _len = arguments.length, event = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1259
1129
|
event[_key] = arguments[_key];
|
|
1260
1130
|
}
|
|
@@ -1262,7 +1132,7 @@ var useContractEvent = function useContractEvent(contractConfig, eventName, list
|
|
|
1262
1132
|
return listenerRef.current(event);
|
|
1263
1133
|
};
|
|
1264
1134
|
|
|
1265
|
-
|
|
1135
|
+
const contract_ = contract;
|
|
1266
1136
|
if (once) contract_.once(eventName, handler);else contract_.on(eventName, handler);
|
|
1267
1137
|
return () => {
|
|
1268
1138
|
contract_.off(eventName, handler);
|
|
@@ -1271,81 +1141,76 @@ var useContractEvent = function useContractEvent(contractConfig, eventName, list
|
|
|
1271
1141
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
1272
1142
|
};
|
|
1273
1143
|
|
|
1274
|
-
|
|
1144
|
+
const initialState$4 = {
|
|
1275
1145
|
loading: false
|
|
1276
1146
|
};
|
|
1277
|
-
|
|
1278
|
-
|
|
1147
|
+
const useContractRead = function (contractConfig, functionName) {
|
|
1148
|
+
let {
|
|
1279
1149
|
args,
|
|
1280
1150
|
overrides,
|
|
1281
1151
|
skip,
|
|
1282
1152
|
watch
|
|
1283
1153
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
signerOrProvider: provider
|
|
1288
|
-
|
|
1289
|
-
|
|
1154
|
+
const cacheBuster = useCacheBuster();
|
|
1155
|
+
const provider = useProvider();
|
|
1156
|
+
const contract = useContract({
|
|
1157
|
+
signerOrProvider: provider,
|
|
1158
|
+
...contractConfig
|
|
1159
|
+
});
|
|
1160
|
+
const [{
|
|
1290
1161
|
data: blockNumber
|
|
1291
1162
|
}] = useBlockNumber({
|
|
1292
1163
|
skip: true,
|
|
1293
1164
|
watch
|
|
1294
1165
|
});
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
});
|
|
1166
|
+
const [state, setState] = React__namespace.useState(initialState$4);
|
|
1167
|
+
const cancelQuery = useCancel();
|
|
1168
|
+
const read = React__namespace.useCallback(async config => {
|
|
1169
|
+
let didCancel = false;
|
|
1170
|
+
cancelQuery(() => {
|
|
1171
|
+
didCancel = true;
|
|
1172
|
+
});
|
|
1303
1173
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1174
|
+
try {
|
|
1175
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
1176
|
+
args,
|
|
1177
|
+
overrides
|
|
1178
|
+
};
|
|
1179
|
+
const params = [...(Array.isArray(config_.args) ? config_.args : config_.args ? [config_.args] : []), ...(config_.overrides ? [config_.overrides] : [])];
|
|
1180
|
+
setState(x => ({ ...x,
|
|
1181
|
+
error: undefined,
|
|
1182
|
+
loading: true,
|
|
1183
|
+
response: undefined
|
|
1184
|
+
}));
|
|
1185
|
+
const response = await contract[functionName](...params);
|
|
1316
1186
|
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1187
|
+
if (!didCancel) {
|
|
1188
|
+
setState(x => ({ ...x,
|
|
1189
|
+
loading: false,
|
|
1190
|
+
response
|
|
1191
|
+
}));
|
|
1192
|
+
}
|
|
1323
1193
|
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
if (!didCancel) {
|
|
1332
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1333
|
-
error,
|
|
1334
|
-
loading: false
|
|
1335
|
-
}));
|
|
1336
|
-
}
|
|
1194
|
+
return {
|
|
1195
|
+
data: response,
|
|
1196
|
+
error: undefined
|
|
1197
|
+
};
|
|
1198
|
+
} catch (error_) {
|
|
1199
|
+
const error = error_;
|
|
1337
1200
|
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
error
|
|
1341
|
-
|
|
1201
|
+
if (!didCancel) {
|
|
1202
|
+
setState(x => ({ ...x,
|
|
1203
|
+
error,
|
|
1204
|
+
loading: false
|
|
1205
|
+
}));
|
|
1342
1206
|
}
|
|
1343
|
-
});
|
|
1344
1207
|
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1208
|
+
return {
|
|
1209
|
+
data: undefined,
|
|
1210
|
+
error
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
}, [args, cancelQuery, contract, functionName, overrides]);
|
|
1349
1214
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1350
1215
|
|
|
1351
1216
|
React__namespace.useEffect(() => {
|
|
@@ -1372,78 +1237,72 @@ var useContractRead = function useContractRead(contractConfig, functionName) {
|
|
|
1372
1237
|
}, read];
|
|
1373
1238
|
};
|
|
1374
1239
|
|
|
1375
|
-
|
|
1240
|
+
const initialState$3 = {
|
|
1376
1241
|
loading: false
|
|
1377
1242
|
};
|
|
1378
|
-
|
|
1379
|
-
|
|
1243
|
+
const useContractWrite = function (contractConfig, functionName) {
|
|
1244
|
+
let {
|
|
1380
1245
|
args,
|
|
1381
1246
|
overrides
|
|
1382
1247
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1383
|
-
|
|
1248
|
+
const {
|
|
1384
1249
|
state: {
|
|
1385
1250
|
connector
|
|
1386
1251
|
}
|
|
1387
1252
|
} = useContext();
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
});
|
|
1253
|
+
const contract = useContract(contractConfig);
|
|
1254
|
+
const [state, setState] = React__namespace.useState(initialState$3);
|
|
1255
|
+
const cancelQuery = useCancel();
|
|
1256
|
+
const write = React__namespace.useCallback(async config => {
|
|
1257
|
+
let didCancel = false;
|
|
1258
|
+
cancelQuery(() => {
|
|
1259
|
+
didCancel = true;
|
|
1260
|
+
});
|
|
1397
1261
|
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1262
|
+
try {
|
|
1263
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
1264
|
+
args,
|
|
1265
|
+
overrides
|
|
1266
|
+
};
|
|
1267
|
+
if (!connector) throw new wagmiCore.ConnectorNotFoundError();
|
|
1268
|
+
const params = [...(Array.isArray(config_.args) ? config_.args : config_.args ? [config_.args] : []), ...(config_.overrides ? [config_.overrides] : [])];
|
|
1269
|
+
setState(x => ({ ...x,
|
|
1270
|
+
error: undefined,
|
|
1271
|
+
loading: true,
|
|
1272
|
+
response: undefined
|
|
1273
|
+
}));
|
|
1274
|
+
const signer = await connector.getSigner();
|
|
1275
|
+
const contract_ = contract.connect(signer);
|
|
1276
|
+
const response = await contract_[functionName](...params);
|
|
1277
|
+
|
|
1278
|
+
if (!didCancel) {
|
|
1279
|
+
setState(x => ({ ...x,
|
|
1280
|
+
loading: false,
|
|
1281
|
+
response
|
|
1409
1282
|
}));
|
|
1410
|
-
|
|
1411
|
-
var contract_ = contract.connect(signer);
|
|
1412
|
-
var response = yield contract_[functionName](...params);
|
|
1413
|
-
|
|
1414
|
-
if (!didCancel) {
|
|
1415
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1416
|
-
loading: false,
|
|
1417
|
-
response
|
|
1418
|
-
}));
|
|
1419
|
-
}
|
|
1283
|
+
}
|
|
1420
1284
|
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
if (!didCancel) {
|
|
1430
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1431
|
-
error,
|
|
1432
|
-
loading: false
|
|
1433
|
-
}));
|
|
1434
|
-
}
|
|
1285
|
+
return {
|
|
1286
|
+
data: response,
|
|
1287
|
+
error: undefined
|
|
1288
|
+
};
|
|
1289
|
+
} catch (error_) {
|
|
1290
|
+
let error = error_;
|
|
1291
|
+
if (error_.code === 4001) error = new wagmiCore.UserRejectedRequestError();
|
|
1435
1292
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
error
|
|
1439
|
-
|
|
1293
|
+
if (!didCancel) {
|
|
1294
|
+
setState(x => ({ ...x,
|
|
1295
|
+
error,
|
|
1296
|
+
loading: false
|
|
1297
|
+
}));
|
|
1440
1298
|
}
|
|
1441
|
-
});
|
|
1442
1299
|
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1300
|
+
return {
|
|
1301
|
+
data: undefined,
|
|
1302
|
+
error
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
}, [args, cancelQuery, connector, contract, functionName, overrides]);
|
|
1447
1306
|
return [{
|
|
1448
1307
|
data: state.response,
|
|
1449
1308
|
error: state.error,
|
|
@@ -1451,103 +1310,91 @@ var useContractWrite = function useContractWrite(contractConfig, functionName) {
|
|
|
1451
1310
|
}, write];
|
|
1452
1311
|
};
|
|
1453
1312
|
|
|
1454
|
-
|
|
1313
|
+
const initialState$2 = {
|
|
1455
1314
|
loading: false
|
|
1456
1315
|
};
|
|
1457
|
-
|
|
1458
|
-
|
|
1316
|
+
const useToken = function () {
|
|
1317
|
+
let {
|
|
1459
1318
|
address,
|
|
1460
1319
|
formatUnits = 'ether',
|
|
1461
1320
|
skip
|
|
1462
1321
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1463
|
-
|
|
1322
|
+
const {
|
|
1464
1323
|
state: {
|
|
1465
1324
|
connector
|
|
1466
1325
|
}
|
|
1467
1326
|
} = useContext();
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
});
|
|
1477
|
-
|
|
1478
|
-
try {
|
|
1479
|
-
var _config_$formatUnits;
|
|
1327
|
+
const provider = useProvider();
|
|
1328
|
+
const [state, setState] = React__namespace.useState(initialState$2);
|
|
1329
|
+
const cancelQuery = useCancel();
|
|
1330
|
+
const getToken = React__namespace.useCallback(async config => {
|
|
1331
|
+
let didCancel = false;
|
|
1332
|
+
cancelQuery(() => {
|
|
1333
|
+
didCancel = true;
|
|
1334
|
+
});
|
|
1480
1335
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
formatUnits
|
|
1484
|
-
};
|
|
1485
|
-
if (!config_.address) throw new Error('address is required');
|
|
1486
|
-
var contract = new ethers.ethers.Contract(config_.address, wagmiCore.erc20ABI, provider);
|
|
1487
|
-
var formatUnits_ = (_config_$formatUnits = config_.formatUnits) !== null && _config_$formatUnits !== void 0 ? _config_$formatUnits : 'ether';
|
|
1488
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1489
|
-
error: undefined,
|
|
1490
|
-
loading: true
|
|
1491
|
-
}));
|
|
1492
|
-
var [symbol, decimals, totalSupply] = yield Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
1493
|
-
var token = {
|
|
1494
|
-
address: config_.address,
|
|
1495
|
-
decimals,
|
|
1496
|
-
symbol,
|
|
1497
|
-
totalSupply: {
|
|
1498
|
-
formatted: ethers.utils.formatUnits(totalSupply, formatUnits_),
|
|
1499
|
-
value: totalSupply
|
|
1500
|
-
}
|
|
1501
|
-
};
|
|
1502
|
-
|
|
1503
|
-
if (!didCancel) {
|
|
1504
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1505
|
-
token,
|
|
1506
|
-
loading: false
|
|
1507
|
-
}));
|
|
1508
|
-
}
|
|
1336
|
+
try {
|
|
1337
|
+
var _config_$formatUnits;
|
|
1509
1338
|
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1339
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
1340
|
+
address,
|
|
1341
|
+
formatUnits
|
|
1342
|
+
};
|
|
1343
|
+
if (!config_.address) throw new Error('address is required');
|
|
1344
|
+
const contract = new ethers.ethers.Contract(config_.address, wagmiCore.erc20ABI, provider);
|
|
1345
|
+
const formatUnits_ = (_config_$formatUnits = config_.formatUnits) !== null && _config_$formatUnits !== void 0 ? _config_$formatUnits : 'ether';
|
|
1346
|
+
setState(x => ({ ...x,
|
|
1347
|
+
error: undefined,
|
|
1348
|
+
loading: true
|
|
1349
|
+
}));
|
|
1350
|
+
const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
1351
|
+
const token = {
|
|
1352
|
+
address: config_.address,
|
|
1353
|
+
decimals,
|
|
1354
|
+
symbol,
|
|
1355
|
+
totalSupply: {
|
|
1356
|
+
formatted: ethers.utils.formatUnits(totalSupply, formatUnits_),
|
|
1357
|
+
value: totalSupply
|
|
1522
1358
|
}
|
|
1359
|
+
};
|
|
1523
1360
|
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1361
|
+
if (!didCancel) {
|
|
1362
|
+
setState(x => ({ ...x,
|
|
1363
|
+
token,
|
|
1364
|
+
loading: false
|
|
1365
|
+
}));
|
|
1528
1366
|
}
|
|
1529
|
-
});
|
|
1530
1367
|
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
if (!(connector !== null && connector !== void 0 && connector.watchAsset)) return false;
|
|
1368
|
+
return {
|
|
1369
|
+
data: token,
|
|
1370
|
+
error: undefined
|
|
1371
|
+
};
|
|
1372
|
+
} catch (error_) {
|
|
1373
|
+
const error = error_;
|
|
1538
1374
|
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1375
|
+
if (!didCancel) {
|
|
1376
|
+
setState(x => ({ ...x,
|
|
1377
|
+
error,
|
|
1378
|
+
loading: false
|
|
1379
|
+
}));
|
|
1544
1380
|
}
|
|
1545
|
-
});
|
|
1546
1381
|
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1382
|
+
return {
|
|
1383
|
+
data: undefined,
|
|
1384
|
+
error
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
}, [address, cancelQuery, formatUnits, provider]);
|
|
1388
|
+
const watchToken = React__namespace.useCallback(async token => {
|
|
1389
|
+
if (!(connector !== null && connector !== void 0 && connector.watchAsset)) return false;
|
|
1390
|
+
|
|
1391
|
+
try {
|
|
1392
|
+
await connector.watchAsset(token);
|
|
1393
|
+
return true;
|
|
1394
|
+
} catch (error) {
|
|
1395
|
+
return error;
|
|
1396
|
+
}
|
|
1397
|
+
}, [connector]);
|
|
1551
1398
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1552
1399
|
|
|
1553
1400
|
React__namespace.useEffect(() => {
|
|
@@ -1561,80 +1408,74 @@ var useToken = function useToken() {
|
|
|
1561
1408
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
1562
1409
|
|
|
1563
1410
|
return [{
|
|
1564
|
-
data: state.token ?
|
|
1411
|
+
data: state.token ? { ...state.token,
|
|
1565
1412
|
address
|
|
1566
|
-
}
|
|
1413
|
+
} : undefined,
|
|
1567
1414
|
error: state.error,
|
|
1568
1415
|
loading: state.loading
|
|
1569
1416
|
}, watchToken, getToken];
|
|
1570
1417
|
};
|
|
1571
1418
|
|
|
1572
|
-
|
|
1419
|
+
const initialState$1 = {
|
|
1573
1420
|
loading: false
|
|
1574
1421
|
};
|
|
1575
|
-
|
|
1576
|
-
|
|
1422
|
+
const useTransaction = function () {
|
|
1423
|
+
let {
|
|
1577
1424
|
request
|
|
1578
1425
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1579
|
-
|
|
1426
|
+
const {
|
|
1580
1427
|
state: {
|
|
1581
1428
|
connector
|
|
1582
1429
|
}
|
|
1583
1430
|
} = useContext();
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
});
|
|
1431
|
+
const [state, setState] = React__namespace.useState(initialState$1);
|
|
1432
|
+
const cancelQuery = useCancel();
|
|
1433
|
+
const sendTransaction = React__namespace.useCallback(async config => {
|
|
1434
|
+
let didCancel = false;
|
|
1435
|
+
cancelQuery(() => {
|
|
1436
|
+
didCancel = true;
|
|
1437
|
+
});
|
|
1592
1438
|
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1439
|
+
try {
|
|
1440
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
1441
|
+
request
|
|
1442
|
+
};
|
|
1443
|
+
if (!config_.request) throw new Error('request is required');
|
|
1444
|
+
if (!connector) throw new wagmiCore.ConnectorNotFoundError();
|
|
1445
|
+
setState(x => ({ ...x,
|
|
1446
|
+
loading: true
|
|
1447
|
+
}));
|
|
1448
|
+
const signer = await connector.getSigner();
|
|
1449
|
+
const transaction = await signer.sendTransaction(config_.request);
|
|
1450
|
+
|
|
1451
|
+
if (!didCancel) {
|
|
1452
|
+
setState(x => ({ ...x,
|
|
1453
|
+
loading: false,
|
|
1454
|
+
transaction
|
|
1601
1455
|
}));
|
|
1602
|
-
|
|
1603
|
-
var transaction = yield signer.sendTransaction(config_.request);
|
|
1604
|
-
|
|
1605
|
-
if (!didCancel) {
|
|
1606
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1607
|
-
loading: false,
|
|
1608
|
-
transaction
|
|
1609
|
-
}));
|
|
1610
|
-
}
|
|
1456
|
+
}
|
|
1611
1457
|
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
if (!didCancel) {
|
|
1621
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1622
|
-
error,
|
|
1623
|
-
loading: false
|
|
1624
|
-
}));
|
|
1625
|
-
}
|
|
1458
|
+
return {
|
|
1459
|
+
data: transaction,
|
|
1460
|
+
error: undefined
|
|
1461
|
+
};
|
|
1462
|
+
} catch (error_) {
|
|
1463
|
+
let error = error_;
|
|
1464
|
+
if (error_.code === 4001) error = new wagmiCore.UserRejectedRequestError();
|
|
1626
1465
|
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
error
|
|
1630
|
-
|
|
1466
|
+
if (!didCancel) {
|
|
1467
|
+
setState(x => ({ ...x,
|
|
1468
|
+
error,
|
|
1469
|
+
loading: false
|
|
1470
|
+
}));
|
|
1631
1471
|
}
|
|
1632
|
-
});
|
|
1633
1472
|
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1473
|
+
return {
|
|
1474
|
+
data: undefined,
|
|
1475
|
+
error
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
}, [cancelQuery, connector, request]);
|
|
1638
1479
|
return [{
|
|
1639
1480
|
data: state.transaction,
|
|
1640
1481
|
error: state.error,
|
|
@@ -1642,75 +1483,69 @@ var useTransaction = function useTransaction() {
|
|
|
1642
1483
|
}, sendTransaction];
|
|
1643
1484
|
};
|
|
1644
1485
|
|
|
1645
|
-
|
|
1486
|
+
const initialState = {
|
|
1646
1487
|
loading: false
|
|
1647
1488
|
};
|
|
1648
|
-
|
|
1649
|
-
|
|
1489
|
+
const useWaitForTransaction = function () {
|
|
1490
|
+
let {
|
|
1650
1491
|
confirmations,
|
|
1651
1492
|
hash,
|
|
1652
1493
|
skip,
|
|
1653
1494
|
timeout,
|
|
1654
1495
|
wait: wait_
|
|
1655
1496
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
});
|
|
1497
|
+
const provider = useProvider();
|
|
1498
|
+
const [state, setState] = React__namespace.useState(initialState);
|
|
1499
|
+
const cancelQuery = useCancel();
|
|
1500
|
+
const wait = React__namespace.useCallback(async config => {
|
|
1501
|
+
let didCancel = false;
|
|
1502
|
+
cancelQuery(() => {
|
|
1503
|
+
didCancel = true;
|
|
1504
|
+
});
|
|
1665
1505
|
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
if (config_.wait) promise = config_.wait(config_.confirmations);else if (config_.hash) promise = provider.waitForTransaction(config_.hash, config_.confirmations, config_.timeout);else throw new Error('hash or wait is required');
|
|
1677
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1678
|
-
loading: true
|
|
1679
|
-
}));
|
|
1680
|
-
var receipt = yield promise;
|
|
1506
|
+
try {
|
|
1507
|
+
const config_ = config !== null && config !== void 0 ? config : {
|
|
1508
|
+
confirmations,
|
|
1509
|
+
hash,
|
|
1510
|
+
timeout,
|
|
1511
|
+
wait: wait_
|
|
1512
|
+
};
|
|
1513
|
+
if (!config_.hash && !config_.wait) throw new Error('hash or wait is required');
|
|
1514
|
+
let promise; // eslint-disable-next-line testing-library/await-async-utils
|
|
1681
1515
|
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
}
|
|
1516
|
+
if (config_.wait) promise = config_.wait(config_.confirmations);else if (config_.hash) promise = provider.waitForTransaction(config_.hash, config_.confirmations, config_.timeout);else throw new Error('hash or wait is required');
|
|
1517
|
+
setState(x => ({ ...x,
|
|
1518
|
+
loading: true
|
|
1519
|
+
}));
|
|
1520
|
+
const receipt = await promise;
|
|
1688
1521
|
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
if (!didCancel) {
|
|
1697
|
-
setState(x => _objectSpread2(_objectSpread2({}, x), {}, {
|
|
1698
|
-
error,
|
|
1699
|
-
loading: false
|
|
1700
|
-
}));
|
|
1701
|
-
}
|
|
1522
|
+
if (!didCancel) {
|
|
1523
|
+
setState(x => ({ ...x,
|
|
1524
|
+
loading: false,
|
|
1525
|
+
receipt
|
|
1526
|
+
}));
|
|
1527
|
+
}
|
|
1702
1528
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1529
|
+
return {
|
|
1530
|
+
data: receipt,
|
|
1531
|
+
error: undefined
|
|
1532
|
+
};
|
|
1533
|
+
} catch (error_) {
|
|
1534
|
+
const error = error_;
|
|
1535
|
+
|
|
1536
|
+
if (!didCancel) {
|
|
1537
|
+
setState(x => ({ ...x,
|
|
1538
|
+
error,
|
|
1539
|
+
loading: false
|
|
1540
|
+
}));
|
|
1707
1541
|
}
|
|
1708
|
-
});
|
|
1709
1542
|
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1543
|
+
return {
|
|
1544
|
+
data: undefined,
|
|
1545
|
+
error
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
}, [cancelQuery, confirmations, hash, provider, timeout, wait_]); // Fetch balance when deps or chain changes
|
|
1714
1549
|
|
|
1715
1550
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1716
1551
|
|
|
@@ -1737,11 +1572,11 @@ var useWaitForTransaction = function useWaitForTransaction() {
|
|
|
1737
1572
|
}, wait];
|
|
1738
1573
|
};
|
|
1739
1574
|
|
|
1740
|
-
|
|
1741
|
-
|
|
1575
|
+
const Context = /*#__PURE__*/React__namespace.createContext(null);
|
|
1576
|
+
const Provider = _ref => {
|
|
1742
1577
|
var _state$data2, _state$data2$chain, _state$data4, _state$data4$chain, _state$data6, _state$data6$chain;
|
|
1743
1578
|
|
|
1744
|
-
|
|
1579
|
+
let {
|
|
1745
1580
|
autoConnect = false,
|
|
1746
1581
|
children,
|
|
1747
1582
|
connectors: connectors_ = [new wagmiCore.InjectedConnector()],
|
|
@@ -1749,12 +1584,12 @@ var Provider = _ref => {
|
|
|
1749
1584
|
provider: provider_ = providers.getDefaultProvider(),
|
|
1750
1585
|
webSocketProvider: webSocketProvider_
|
|
1751
1586
|
} = _ref;
|
|
1752
|
-
|
|
1753
|
-
|
|
1587
|
+
const [lastUsedConnector, setLastUsedConnector] = useLocalStorage(connectorStorageKey);
|
|
1588
|
+
const [state, setState] = React__namespace.useState({
|
|
1754
1589
|
cacheBuster: 1,
|
|
1755
1590
|
connecting: autoConnect
|
|
1756
1591
|
});
|
|
1757
|
-
|
|
1592
|
+
const connectors = React__namespace.useMemo(() => {
|
|
1758
1593
|
var _state$data, _state$data$chain;
|
|
1759
1594
|
|
|
1760
1595
|
if (typeof connectors_ !== 'function') return connectors_;
|
|
@@ -1762,7 +1597,7 @@ var Provider = _ref => {
|
|
|
1762
1597
|
chainId: (_state$data = state.data) === null || _state$data === void 0 ? void 0 : (_state$data$chain = _state$data.chain) === null || _state$data$chain === void 0 ? void 0 : _state$data$chain.id
|
|
1763
1598
|
});
|
|
1764
1599
|
}, [connectors_, (_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : (_state$data2$chain = _state$data2.chain) === null || _state$data2$chain === void 0 ? void 0 : _state$data2$chain.id]);
|
|
1765
|
-
|
|
1600
|
+
const provider = React__namespace.useMemo(() => {
|
|
1766
1601
|
var _state$data3, _state$data3$chain;
|
|
1767
1602
|
|
|
1768
1603
|
if (typeof provider_ !== 'function') return provider_;
|
|
@@ -1771,7 +1606,7 @@ var Provider = _ref => {
|
|
|
1771
1606
|
connector: state.connector
|
|
1772
1607
|
});
|
|
1773
1608
|
}, [provider_, (_state$data4 = state.data) === null || _state$data4 === void 0 ? void 0 : (_state$data4$chain = _state$data4.chain) === null || _state$data4$chain === void 0 ? void 0 : _state$data4$chain.id, state.connector]);
|
|
1774
|
-
|
|
1609
|
+
const webSocketProvider = React__namespace.useMemo(() => {
|
|
1775
1610
|
var _state$data5, _state$data5$chain;
|
|
1776
1611
|
|
|
1777
1612
|
if (!webSocketProvider_) return undefined;
|
|
@@ -1787,32 +1622,25 @@ var Provider = _ref => {
|
|
|
1787
1622
|
React__namespace.useEffect(() => {
|
|
1788
1623
|
if (!autoConnect) return;
|
|
1789
1624
|
|
|
1790
|
-
|
|
1791
|
-
setState(x =>
|
|
1625
|
+
(async () => {
|
|
1626
|
+
setState(x => ({ ...x,
|
|
1792
1627
|
connecting: true
|
|
1793
1628
|
}));
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
if (!connector.ready || !connector.isAuthorized)
|
|
1798
|
-
|
|
1799
|
-
if (!isAuthorized)
|
|
1800
|
-
|
|
1801
|
-
setState(x =>
|
|
1629
|
+
const sorted = lastUsedConnector ? [...connectors].sort(x => x.name === lastUsedConnector ? -1 : 1) : connectors;
|
|
1630
|
+
|
|
1631
|
+
for (const connector of sorted) {
|
|
1632
|
+
if (!connector.ready || !connector.isAuthorized) continue;
|
|
1633
|
+
const isAuthorized = await connector.isAuthorized();
|
|
1634
|
+
if (!isAuthorized) continue;
|
|
1635
|
+
const data = await connector.connect();
|
|
1636
|
+
setState(x => ({ ...x,
|
|
1802
1637
|
connector,
|
|
1803
1638
|
data
|
|
1804
1639
|
}));
|
|
1805
|
-
|
|
1806
|
-
};
|
|
1807
|
-
|
|
1808
|
-
for (var connector of sorted) {
|
|
1809
|
-
var _ret = yield* _loop(connector);
|
|
1810
|
-
|
|
1811
|
-
if (_ret === "continue") continue;
|
|
1812
|
-
if (_ret === "break") break;
|
|
1640
|
+
break;
|
|
1813
1641
|
}
|
|
1814
1642
|
|
|
1815
|
-
setState(x =>
|
|
1643
|
+
setState(x => ({ ...x,
|
|
1816
1644
|
connecting: false
|
|
1817
1645
|
}));
|
|
1818
1646
|
})();
|
|
@@ -1830,16 +1658,18 @@ var Provider = _ref => {
|
|
|
1830
1658
|
React__namespace.useEffect(() => {
|
|
1831
1659
|
if (!state.connector) return;
|
|
1832
1660
|
|
|
1833
|
-
|
|
1661
|
+
const onChange = data => setState(x => ({ ...x,
|
|
1834
1662
|
cacheBuster: x.cacheBuster + 1,
|
|
1835
|
-
data:
|
|
1663
|
+
data: { ...x.data,
|
|
1664
|
+
...data
|
|
1665
|
+
}
|
|
1836
1666
|
}));
|
|
1837
1667
|
|
|
1838
|
-
|
|
1668
|
+
const onDisconnect = () => setState({
|
|
1839
1669
|
cacheBuster: 1
|
|
1840
1670
|
});
|
|
1841
1671
|
|
|
1842
|
-
|
|
1672
|
+
const onError = error => setState(x => ({ ...x,
|
|
1843
1673
|
error
|
|
1844
1674
|
}));
|
|
1845
1675
|
|
|
@@ -1853,7 +1683,7 @@ var Provider = _ref => {
|
|
|
1853
1683
|
state.connector.off('error', onError);
|
|
1854
1684
|
};
|
|
1855
1685
|
}, [state.connector]);
|
|
1856
|
-
|
|
1686
|
+
const value = {
|
|
1857
1687
|
state: {
|
|
1858
1688
|
cacheBuster: state.cacheBuster,
|
|
1859
1689
|
connecting: state.connecting,
|
|
@@ -1870,8 +1700,8 @@ var Provider = _ref => {
|
|
|
1870
1700
|
value
|
|
1871
1701
|
}, children);
|
|
1872
1702
|
};
|
|
1873
|
-
|
|
1874
|
-
|
|
1703
|
+
const useContext = () => {
|
|
1704
|
+
const context = React__namespace.useContext(Context);
|
|
1875
1705
|
if (!context) throw Error('Must be used within Provider');
|
|
1876
1706
|
return context;
|
|
1877
1707
|
};
|