@rango-dev/wallets-core 0.1.16-next.7 → 0.1.16-next.8
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/helpers.d.ts +20 -20
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/index.js.map +7 -0
- package/dist/provider.d.ts +5 -5
- package/dist/provider.d.ts.map +1 -1
- package/dist/types.d.ts +103 -103
- package/dist/types.d.ts.map +1 -1
- package/dist/wallet.d.ts +48 -52
- package/dist/wallet.d.ts.map +1 -1
- package/package.json +5 -7
- package/dist/wallets-core.cjs.development.js +0 -1102
- package/dist/wallets-core.cjs.development.js.map +0 -1
- package/dist/wallets-core.cjs.production.min.js +0 -2
- package/dist/wallets-core.cjs.production.min.js.map +0 -1
- package/dist/wallets-core.esm.js +0 -1082
- package/dist/wallets-core.esm.js.map +0 -1
package/dist/wallets-core.esm.js
DELETED
|
@@ -1,1082 +0,0 @@
|
|
|
1
|
-
import WalletConnectProvider from '@walletconnect/ethereum-provider';
|
|
2
|
-
import { WalletTypes, evmChainsToRpcMap, convertEvmBlockchainMetaToEvmChainInfo, getBlockChainNameFromId, Network } from '@rango-dev/wallets-shared';
|
|
3
|
-
import { isEvmBlockchain } from 'rango-types';
|
|
4
|
-
import React, { useReducer, useEffect, useContext, createContext, useRef } from 'react';
|
|
5
|
-
|
|
6
|
-
function _regeneratorRuntime() {
|
|
7
|
-
_regeneratorRuntime = function () {
|
|
8
|
-
return exports;
|
|
9
|
-
};
|
|
10
|
-
var exports = {},
|
|
11
|
-
Op = Object.prototype,
|
|
12
|
-
hasOwn = Op.hasOwnProperty,
|
|
13
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
14
|
-
obj[key] = desc.value;
|
|
15
|
-
},
|
|
16
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
17
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
18
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
19
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
20
|
-
function define(obj, key, value) {
|
|
21
|
-
return Object.defineProperty(obj, key, {
|
|
22
|
-
value: value,
|
|
23
|
-
enumerable: !0,
|
|
24
|
-
configurable: !0,
|
|
25
|
-
writable: !0
|
|
26
|
-
}), obj[key];
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
define({}, "");
|
|
30
|
-
} catch (err) {
|
|
31
|
-
define = function (obj, key, value) {
|
|
32
|
-
return obj[key] = value;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
36
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
37
|
-
generator = Object.create(protoGenerator.prototype),
|
|
38
|
-
context = new Context(tryLocsList || []);
|
|
39
|
-
return defineProperty(generator, "_invoke", {
|
|
40
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
41
|
-
}), generator;
|
|
42
|
-
}
|
|
43
|
-
function tryCatch(fn, obj, arg) {
|
|
44
|
-
try {
|
|
45
|
-
return {
|
|
46
|
-
type: "normal",
|
|
47
|
-
arg: fn.call(obj, arg)
|
|
48
|
-
};
|
|
49
|
-
} catch (err) {
|
|
50
|
-
return {
|
|
51
|
-
type: "throw",
|
|
52
|
-
arg: err
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.wrap = wrap;
|
|
57
|
-
var ContinueSentinel = {};
|
|
58
|
-
function Generator() {}
|
|
59
|
-
function GeneratorFunction() {}
|
|
60
|
-
function GeneratorFunctionPrototype() {}
|
|
61
|
-
var IteratorPrototype = {};
|
|
62
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
63
|
-
return this;
|
|
64
|
-
});
|
|
65
|
-
var getProto = Object.getPrototypeOf,
|
|
66
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
67
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
68
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
69
|
-
function defineIteratorMethods(prototype) {
|
|
70
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
71
|
-
define(prototype, method, function (arg) {
|
|
72
|
-
return this._invoke(method, arg);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
77
|
-
function invoke(method, arg, resolve, reject) {
|
|
78
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
79
|
-
if ("throw" !== record.type) {
|
|
80
|
-
var result = record.arg,
|
|
81
|
-
value = result.value;
|
|
82
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
83
|
-
invoke("next", value, resolve, reject);
|
|
84
|
-
}, function (err) {
|
|
85
|
-
invoke("throw", err, resolve, reject);
|
|
86
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
87
|
-
result.value = unwrapped, resolve(result);
|
|
88
|
-
}, function (error) {
|
|
89
|
-
return invoke("throw", error, resolve, reject);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
reject(record.arg);
|
|
93
|
-
}
|
|
94
|
-
var previousPromise;
|
|
95
|
-
defineProperty(this, "_invoke", {
|
|
96
|
-
value: function (method, arg) {
|
|
97
|
-
function callInvokeWithMethodAndArg() {
|
|
98
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
99
|
-
invoke(method, arg, resolve, reject);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
107
|
-
var state = "suspendedStart";
|
|
108
|
-
return function (method, arg) {
|
|
109
|
-
if ("executing" === state) throw new Error("Generator is already running");
|
|
110
|
-
if ("completed" === state) {
|
|
111
|
-
if ("throw" === method) throw arg;
|
|
112
|
-
return doneResult();
|
|
113
|
-
}
|
|
114
|
-
for (context.method = method, context.arg = arg;;) {
|
|
115
|
-
var delegate = context.delegate;
|
|
116
|
-
if (delegate) {
|
|
117
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
118
|
-
if (delegateResult) {
|
|
119
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
120
|
-
return delegateResult;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
124
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
125
|
-
context.dispatchException(context.arg);
|
|
126
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
127
|
-
state = "executing";
|
|
128
|
-
var record = tryCatch(innerFn, self, context);
|
|
129
|
-
if ("normal" === record.type) {
|
|
130
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
131
|
-
return {
|
|
132
|
-
value: record.arg,
|
|
133
|
-
done: context.done
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
141
|
-
var methodName = context.method,
|
|
142
|
-
method = delegate.iterator[methodName];
|
|
143
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
144
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
145
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
146
|
-
var info = record.arg;
|
|
147
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
148
|
-
}
|
|
149
|
-
function pushTryEntry(locs) {
|
|
150
|
-
var entry = {
|
|
151
|
-
tryLoc: locs[0]
|
|
152
|
-
};
|
|
153
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
154
|
-
}
|
|
155
|
-
function resetTryEntry(entry) {
|
|
156
|
-
var record = entry.completion || {};
|
|
157
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
158
|
-
}
|
|
159
|
-
function Context(tryLocsList) {
|
|
160
|
-
this.tryEntries = [{
|
|
161
|
-
tryLoc: "root"
|
|
162
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
163
|
-
}
|
|
164
|
-
function values(iterable) {
|
|
165
|
-
if (iterable) {
|
|
166
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
167
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
168
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
169
|
-
if (!isNaN(iterable.length)) {
|
|
170
|
-
var i = -1,
|
|
171
|
-
next = function next() {
|
|
172
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
173
|
-
return next.value = undefined, next.done = !0, next;
|
|
174
|
-
};
|
|
175
|
-
return next.next = next;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
next: doneResult
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function doneResult() {
|
|
183
|
-
return {
|
|
184
|
-
value: undefined,
|
|
185
|
-
done: !0
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
189
|
-
value: GeneratorFunctionPrototype,
|
|
190
|
-
configurable: !0
|
|
191
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
192
|
-
value: GeneratorFunction,
|
|
193
|
-
configurable: !0
|
|
194
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
195
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
196
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
197
|
-
}, exports.mark = function (genFun) {
|
|
198
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
199
|
-
}, exports.awrap = function (arg) {
|
|
200
|
-
return {
|
|
201
|
-
__await: arg
|
|
202
|
-
};
|
|
203
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
204
|
-
return this;
|
|
205
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
206
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
207
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
208
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
209
|
-
return result.done ? result.value : iter.next();
|
|
210
|
-
});
|
|
211
|
-
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
212
|
-
return this;
|
|
213
|
-
}), define(Gp, "toString", function () {
|
|
214
|
-
return "[object Generator]";
|
|
215
|
-
}), exports.keys = function (val) {
|
|
216
|
-
var object = Object(val),
|
|
217
|
-
keys = [];
|
|
218
|
-
for (var key in object) keys.push(key);
|
|
219
|
-
return keys.reverse(), function next() {
|
|
220
|
-
for (; keys.length;) {
|
|
221
|
-
var key = keys.pop();
|
|
222
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
223
|
-
}
|
|
224
|
-
return next.done = !0, next;
|
|
225
|
-
};
|
|
226
|
-
}, exports.values = values, Context.prototype = {
|
|
227
|
-
constructor: Context,
|
|
228
|
-
reset: function (skipTempReset) {
|
|
229
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
230
|
-
},
|
|
231
|
-
stop: function () {
|
|
232
|
-
this.done = !0;
|
|
233
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
234
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
235
|
-
return this.rval;
|
|
236
|
-
},
|
|
237
|
-
dispatchException: function (exception) {
|
|
238
|
-
if (this.done) throw exception;
|
|
239
|
-
var context = this;
|
|
240
|
-
function handle(loc, caught) {
|
|
241
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
242
|
-
}
|
|
243
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
244
|
-
var entry = this.tryEntries[i],
|
|
245
|
-
record = entry.completion;
|
|
246
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
247
|
-
if (entry.tryLoc <= this.prev) {
|
|
248
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
249
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
250
|
-
if (hasCatch && hasFinally) {
|
|
251
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
252
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
253
|
-
} else if (hasCatch) {
|
|
254
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
255
|
-
} else {
|
|
256
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
257
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
abrupt: function (type, arg) {
|
|
263
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
264
|
-
var entry = this.tryEntries[i];
|
|
265
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
266
|
-
var finallyEntry = entry;
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
271
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
272
|
-
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
273
|
-
},
|
|
274
|
-
complete: function (record, afterLoc) {
|
|
275
|
-
if ("throw" === record.type) throw record.arg;
|
|
276
|
-
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
277
|
-
},
|
|
278
|
-
finish: function (finallyLoc) {
|
|
279
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
280
|
-
var entry = this.tryEntries[i];
|
|
281
|
-
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
catch: function (tryLoc) {
|
|
285
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
286
|
-
var entry = this.tryEntries[i];
|
|
287
|
-
if (entry.tryLoc === tryLoc) {
|
|
288
|
-
var record = entry.completion;
|
|
289
|
-
if ("throw" === record.type) {
|
|
290
|
-
var thrown = record.arg;
|
|
291
|
-
resetTryEntry(entry);
|
|
292
|
-
}
|
|
293
|
-
return thrown;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
throw new Error("illegal catch attempt");
|
|
297
|
-
},
|
|
298
|
-
delegateYield: function (iterable, resultName, nextLoc) {
|
|
299
|
-
return this.delegate = {
|
|
300
|
-
iterator: values(iterable),
|
|
301
|
-
resultName: resultName,
|
|
302
|
-
nextLoc: nextLoc
|
|
303
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
304
|
-
}
|
|
305
|
-
}, exports;
|
|
306
|
-
}
|
|
307
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
308
|
-
try {
|
|
309
|
-
var info = gen[key](arg);
|
|
310
|
-
var value = info.value;
|
|
311
|
-
} catch (error) {
|
|
312
|
-
reject(error);
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
if (info.done) {
|
|
316
|
-
resolve(value);
|
|
317
|
-
} else {
|
|
318
|
-
Promise.resolve(value).then(_next, _throw);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
function _asyncToGenerator(fn) {
|
|
322
|
-
return function () {
|
|
323
|
-
var self = this,
|
|
324
|
-
args = arguments;
|
|
325
|
-
return new Promise(function (resolve, reject) {
|
|
326
|
-
var gen = fn.apply(self, args);
|
|
327
|
-
function _next(value) {
|
|
328
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
329
|
-
}
|
|
330
|
-
function _throw(err) {
|
|
331
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
332
|
-
}
|
|
333
|
-
_next(undefined);
|
|
334
|
-
});
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
function _extends() {
|
|
338
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
339
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
340
|
-
var source = arguments[i];
|
|
341
|
-
for (var key in source) {
|
|
342
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
343
|
-
target[key] = source[key];
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return target;
|
|
348
|
-
};
|
|
349
|
-
return _extends.apply(this, arguments);
|
|
350
|
-
}
|
|
351
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
352
|
-
if (source == null) return {};
|
|
353
|
-
var target = {};
|
|
354
|
-
var sourceKeys = Object.keys(source);
|
|
355
|
-
var key, i;
|
|
356
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
357
|
-
key = sourceKeys[i];
|
|
358
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
359
|
-
target[key] = source[key];
|
|
360
|
-
}
|
|
361
|
-
return target;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
var _excluded = ["config"];
|
|
365
|
-
function choose(wallets, type) {
|
|
366
|
-
return wallets.find(function (wallet) {
|
|
367
|
-
return wallet.type === type;
|
|
368
|
-
}) || null;
|
|
369
|
-
}
|
|
370
|
-
var defaultWalletState = {
|
|
371
|
-
connected: false,
|
|
372
|
-
connecting: false,
|
|
373
|
-
reachable: false,
|
|
374
|
-
installed: false,
|
|
375
|
-
accounts: null,
|
|
376
|
-
network: null
|
|
377
|
-
};
|
|
378
|
-
function state_reducer(state, action) {
|
|
379
|
-
if (action.type === 'new_state') {
|
|
380
|
-
var _extends4, _extends5;
|
|
381
|
-
// TODO fix problem and remove ts-ignore
|
|
382
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
383
|
-
// @ts-ignore
|
|
384
|
-
var target_wallet = state[action.wallet];
|
|
385
|
-
if (!target_wallet) {
|
|
386
|
-
var _extends2, _extends3;
|
|
387
|
-
return _extends({}, state, (_extends3 = {}, _extends3[action.wallet] = _extends({}, defaultWalletState, (_extends2 = {}, _extends2[action.name] = action.value, _extends2)), _extends3));
|
|
388
|
-
}
|
|
389
|
-
return _extends({}, state, (_extends5 = {}, _extends5[action.wallet] = _extends({}, target_wallet, (_extends4 = {}, _extends4[action.name] = action.value, _extends4)), _extends5));
|
|
390
|
-
}
|
|
391
|
-
return state;
|
|
392
|
-
}
|
|
393
|
-
function formatAddressWithNetwork(address, network) {
|
|
394
|
-
return (network || '') + ":" + address;
|
|
395
|
-
}
|
|
396
|
-
function accountAddressesWithNetwork(addresses, network) {
|
|
397
|
-
if (!addresses) return [];
|
|
398
|
-
return addresses.map(function (address) {
|
|
399
|
-
return formatAddressWithNetwork(address, network);
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
function readAccountAddress(addressWithNetwork) {
|
|
403
|
-
var _addressWithNetwork$s = addressWithNetwork.split(':'),
|
|
404
|
-
network = _addressWithNetwork$s[0],
|
|
405
|
-
address = _addressWithNetwork$s[1];
|
|
406
|
-
return {
|
|
407
|
-
network: network,
|
|
408
|
-
address: address
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function connectedWallets(providersState) {
|
|
412
|
-
return Object.entries(providersState).filter(function (_ref) {
|
|
413
|
-
var wallet_state = _ref[1];
|
|
414
|
-
return wallet_state == null ? void 0 : wallet_state.connected;
|
|
415
|
-
}).map(function (_ref2) {
|
|
416
|
-
var type = _ref2[0];
|
|
417
|
-
return type;
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
function availableWallets(providersState) {
|
|
421
|
-
return Object.entries(providersState).map(function (_ref3) {
|
|
422
|
-
var type = _ref3[0];
|
|
423
|
-
return type;
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
function checkWalletProviders(list) {
|
|
427
|
-
var wallets = new Map();
|
|
428
|
-
list.forEach(function (provider) {
|
|
429
|
-
var config = provider.config,
|
|
430
|
-
actions = _objectWithoutPropertiesLoose(provider, _excluded);
|
|
431
|
-
wallets.set(config.type, {
|
|
432
|
-
actions: actions,
|
|
433
|
-
config: config
|
|
434
|
-
});
|
|
435
|
-
});
|
|
436
|
-
return wallets;
|
|
437
|
-
}
|
|
438
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
439
|
-
function isAsync(fn) {
|
|
440
|
-
var _fn$constructor;
|
|
441
|
-
return (fn == null ? void 0 : (_fn$constructor = fn.constructor) == null ? void 0 : _fn$constructor.name) === 'AsyncFunction';
|
|
442
|
-
}
|
|
443
|
-
function needsCheckInstallation(options) {
|
|
444
|
-
var _options$config$check = options.config.checkInstallation,
|
|
445
|
-
checkInstallation = _options$config$check === void 0 ? true : _options$config$check;
|
|
446
|
-
return checkInstallation;
|
|
447
|
-
}
|
|
448
|
-
/*
|
|
449
|
-
WalletConnect instance is not compatible with ethers.providers.Web3Provider,
|
|
450
|
-
Here we are returning a comptable instance, instead of the original one.
|
|
451
|
-
*/
|
|
452
|
-
function isWalletDerivedFromWalletConnect(wallet_type) {
|
|
453
|
-
return wallet_type === WalletTypes.WALLET_CONNECT;
|
|
454
|
-
}
|
|
455
|
-
function getComptaibleProvider(supportedChains, provider, type) {
|
|
456
|
-
if (isWalletDerivedFromWalletConnect(type)) {
|
|
457
|
-
var evmBlockchains = supportedChains.filter(isEvmBlockchain);
|
|
458
|
-
var rpcUrls = evmChainsToRpcMap(convertEvmBlockchainMetaToEvmChainInfo(evmBlockchains));
|
|
459
|
-
return new WalletConnectProvider({
|
|
460
|
-
qrcode: false,
|
|
461
|
-
rpc: rpcUrls,
|
|
462
|
-
connector: provider,
|
|
463
|
-
chainId: provider.chainId
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
return provider;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
var Events;
|
|
470
|
-
(function (Events) {
|
|
471
|
-
Events["CONNECTED"] = "connected";
|
|
472
|
-
Events["CONNECTING"] = "connecting";
|
|
473
|
-
Events["REACHABLE"] = "reachable";
|
|
474
|
-
Events["INSTALLED"] = "installed";
|
|
475
|
-
Events["ACCOUNTS"] = "accounts";
|
|
476
|
-
Events["NETWORK"] = "network";
|
|
477
|
-
})(Events || (Events = {}));
|
|
478
|
-
|
|
479
|
-
var Wallet = /*#__PURE__*/function () {
|
|
480
|
-
function Wallet(options, actions) {
|
|
481
|
-
this.actions = actions;
|
|
482
|
-
this.options = options;
|
|
483
|
-
this.provider = null;
|
|
484
|
-
this.meta = [];
|
|
485
|
-
this.state = {
|
|
486
|
-
connected: false,
|
|
487
|
-
connecting: false,
|
|
488
|
-
// TODO: Remove
|
|
489
|
-
reachable: false,
|
|
490
|
-
installed: false,
|
|
491
|
-
accounts: null,
|
|
492
|
-
network: null
|
|
493
|
-
};
|
|
494
|
-
if (!needsCheckInstallation(options)) {
|
|
495
|
-
this.setInstalledAs(true);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
var _proto = Wallet.prototype;
|
|
499
|
-
_proto.eagerConnection = /*#__PURE__*/function () {
|
|
500
|
-
var _eagerConnection = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
501
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
502
|
-
while (1) switch (_context.prev = _context.next) {
|
|
503
|
-
case 0:
|
|
504
|
-
if (!(this.state.connected && !!this.provider)) {
|
|
505
|
-
_context.next = 2;
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
return _context.abrupt("return", {
|
|
509
|
-
accounts: this.state.accounts,
|
|
510
|
-
network: this.state.network,
|
|
511
|
-
provider: this.provider
|
|
512
|
-
});
|
|
513
|
-
case 2:
|
|
514
|
-
return _context.abrupt("return", null);
|
|
515
|
-
case 3:
|
|
516
|
-
case "end":
|
|
517
|
-
return _context.stop();
|
|
518
|
-
}
|
|
519
|
-
}, _callee, this);
|
|
520
|
-
}));
|
|
521
|
-
function eagerConnection() {
|
|
522
|
-
return _eagerConnection.apply(this, arguments);
|
|
523
|
-
}
|
|
524
|
-
return eagerConnection;
|
|
525
|
-
}();
|
|
526
|
-
_proto.connect = /*#__PURE__*/function () {
|
|
527
|
-
var _connect = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(network) {
|
|
528
|
-
var _this = this;
|
|
529
|
-
var eagerConnection, currentNetwork, requestedNetwork, networkChanged, instance, connectResult, nextAccounts, nextNetwork, accounts, chainId, _network;
|
|
530
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
531
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
532
|
-
case 0:
|
|
533
|
-
if (!this.state.connecting) {
|
|
534
|
-
_context2.next = 2;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
throw new Error('Connecting...');
|
|
538
|
-
case 2:
|
|
539
|
-
_context2.next = 4;
|
|
540
|
-
return this.eagerConnection();
|
|
541
|
-
case 4:
|
|
542
|
-
eagerConnection = _context2.sent;
|
|
543
|
-
currentNetwork = this.state.network; // If a network hasn't been provided and also we have `lastNetwork`
|
|
544
|
-
// We will use lastNetwork to make sure we will not
|
|
545
|
-
// Ask the user to switch his network wrongly.
|
|
546
|
-
requestedNetwork = network || currentNetwork || this.options.config.defaultNetwork;
|
|
547
|
-
if (!eagerConnection) {
|
|
548
|
-
_context2.next = 15;
|
|
549
|
-
break;
|
|
550
|
-
}
|
|
551
|
-
networkChanged = currentNetwork !== requestedNetwork && !!requestedNetwork; // Reuse current connection if nothing has changed and we already have the connection in memory.
|
|
552
|
-
if (!(currentNetwork === requestedNetwork)) {
|
|
553
|
-
_context2.next = 11;
|
|
554
|
-
break;
|
|
555
|
-
}
|
|
556
|
-
return _context2.abrupt("return", eagerConnection);
|
|
557
|
-
case 11:
|
|
558
|
-
if (!(networkChanged && !!this.actions.switchNetwork)) {
|
|
559
|
-
_context2.next = 15;
|
|
560
|
-
break;
|
|
561
|
-
}
|
|
562
|
-
_context2.next = 14;
|
|
563
|
-
return this.actions.switchNetwork({
|
|
564
|
-
instance: this.provider,
|
|
565
|
-
meta: this.meta,
|
|
566
|
-
// TODO: Fix type error
|
|
567
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
568
|
-
// @ts-ignore
|
|
569
|
-
network: requestedNetwork,
|
|
570
|
-
newInstance: this.tryGetInstance.bind(this)
|
|
571
|
-
});
|
|
572
|
-
case 14:
|
|
573
|
-
return _context2.abrupt("return", {
|
|
574
|
-
// Only network has been changed, so we reuse accounts from what we have already.
|
|
575
|
-
accounts: eagerConnection.accounts,
|
|
576
|
-
network: requestedNetwork,
|
|
577
|
-
provider: this.provider
|
|
578
|
-
});
|
|
579
|
-
case 15:
|
|
580
|
-
_context2.next = 17;
|
|
581
|
-
return this.tryGetInstance({
|
|
582
|
-
network: network
|
|
583
|
-
});
|
|
584
|
-
case 17:
|
|
585
|
-
instance = _context2.sent;
|
|
586
|
-
// Instance exists, trying to connect
|
|
587
|
-
this.updateState({
|
|
588
|
-
connecting: true
|
|
589
|
-
});
|
|
590
|
-
this.setInstalledAs(true);
|
|
591
|
-
_context2.prev = 20;
|
|
592
|
-
_context2.next = 23;
|
|
593
|
-
return this.actions.connect({
|
|
594
|
-
instance: instance,
|
|
595
|
-
network: requestedNetwork || undefined,
|
|
596
|
-
meta: this.meta || []
|
|
597
|
-
});
|
|
598
|
-
case 23:
|
|
599
|
-
connectResult = _context2.sent;
|
|
600
|
-
_context2.next = 30;
|
|
601
|
-
break;
|
|
602
|
-
case 26:
|
|
603
|
-
_context2.prev = 26;
|
|
604
|
-
_context2.t0 = _context2["catch"](20);
|
|
605
|
-
this.resetState();
|
|
606
|
-
throw _context2.t0;
|
|
607
|
-
case 30:
|
|
608
|
-
this.updateState({
|
|
609
|
-
connected: true,
|
|
610
|
-
reachable: true,
|
|
611
|
-
connecting: false
|
|
612
|
-
});
|
|
613
|
-
// TODO: Handle accounts.length > 0
|
|
614
|
-
// Inserting accounts into our state.
|
|
615
|
-
nextAccounts = [];
|
|
616
|
-
nextNetwork = null;
|
|
617
|
-
if (Array.isArray(connectResult)) {
|
|
618
|
-
accounts = connectResult.flatMap(function (blockchain) {
|
|
619
|
-
var chainId = blockchain.chainId || Network.Unknown;
|
|
620
|
-
// Try to map chainId with a Network, if not found, we use chainId directly.
|
|
621
|
-
var network = getBlockChainNameFromId(chainId, _this.meta) || Network.Unknown;
|
|
622
|
-
// TODO: second parameter should be `string` when we decided to open source the package.
|
|
623
|
-
return accountAddressesWithNetwork(blockchain.accounts, network);
|
|
624
|
-
}); // Typescript can not detect we are filtering out null values:(
|
|
625
|
-
nextAccounts = accounts.filter(Boolean);
|
|
626
|
-
nextNetwork = requestedNetwork || this.options.config.defaultNetwork;
|
|
627
|
-
} else {
|
|
628
|
-
chainId = connectResult.chainId || Network.Unknown;
|
|
629
|
-
_network = getBlockChainNameFromId(chainId, this.meta) || Network.Unknown; // We fallback to current active network if `chainId` not provided.
|
|
630
|
-
nextAccounts = accountAddressesWithNetwork(connectResult.accounts, _network);
|
|
631
|
-
nextNetwork = _network;
|
|
632
|
-
}
|
|
633
|
-
if (nextAccounts.length > 0) {
|
|
634
|
-
this.updateState({
|
|
635
|
-
accounts: nextAccounts,
|
|
636
|
-
network: nextNetwork
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
return _context2.abrupt("return", {
|
|
640
|
-
accounts: this.state.accounts,
|
|
641
|
-
network: this.state.network,
|
|
642
|
-
provider: this.provider
|
|
643
|
-
});
|
|
644
|
-
case 36:
|
|
645
|
-
case "end":
|
|
646
|
-
return _context2.stop();
|
|
647
|
-
}
|
|
648
|
-
}, _callee2, this, [[20, 26]]);
|
|
649
|
-
}));
|
|
650
|
-
function connect(_x) {
|
|
651
|
-
return _connect.apply(this, arguments);
|
|
652
|
-
}
|
|
653
|
-
return connect;
|
|
654
|
-
}();
|
|
655
|
-
_proto.disconnect = /*#__PURE__*/function () {
|
|
656
|
-
var _disconnect = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
657
|
-
var _this2 = this;
|
|
658
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
659
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
660
|
-
case 0:
|
|
661
|
-
this.resetState();
|
|
662
|
-
if (this.actions.disconnect) {
|
|
663
|
-
this.actions.disconnect({
|
|
664
|
-
instance: this.provider,
|
|
665
|
-
// On wallet connect, we need to destory the instance and get a whole new instance when we are going to connect
|
|
666
|
-
destroyInstance: function destroyInstance() {
|
|
667
|
-
_this2.setProvider(null);
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
case 2:
|
|
672
|
-
case "end":
|
|
673
|
-
return _context3.stop();
|
|
674
|
-
}
|
|
675
|
-
}, _callee3, this);
|
|
676
|
-
}));
|
|
677
|
-
function disconnect() {
|
|
678
|
-
return _disconnect.apply(this, arguments);
|
|
679
|
-
}
|
|
680
|
-
return disconnect;
|
|
681
|
-
}();
|
|
682
|
-
_proto.getSigners = function getSigners(provider) {
|
|
683
|
-
return this.actions.getSigners(provider);
|
|
684
|
-
};
|
|
685
|
-
_proto.getWalletInfo = function getWalletInfo(allBlockChains) {
|
|
686
|
-
return this.actions.getWalletInfo(allBlockChains);
|
|
687
|
-
};
|
|
688
|
-
_proto.canSwitchNetworkTo = function canSwitchNetworkTo(network, provider) {
|
|
689
|
-
var switchTo = this.actions.canSwitchNetworkTo;
|
|
690
|
-
if (!switchTo) return false;
|
|
691
|
-
return switchTo({
|
|
692
|
-
network: network,
|
|
693
|
-
meta: this.meta,
|
|
694
|
-
provider: provider
|
|
695
|
-
});
|
|
696
|
-
};
|
|
697
|
-
_proto.onInit = function onInit() {
|
|
698
|
-
if (!this.options.config.isAsyncInstance) {
|
|
699
|
-
var instance = this.actions.getInstance();
|
|
700
|
-
if (!!instance && !this.state.installed) {
|
|
701
|
-
this.setInstalledAs(true);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
};
|
|
705
|
-
_proto.setProvider = function setProvider(value) {
|
|
706
|
-
var _this3 = this;
|
|
707
|
-
this.provider = value;
|
|
708
|
-
if (!!value && !!this.actions.subscribe) {
|
|
709
|
-
this.actions.subscribe({
|
|
710
|
-
instance: value,
|
|
711
|
-
state: this.state,
|
|
712
|
-
meta: this.meta,
|
|
713
|
-
connect: this.connect.bind(this),
|
|
714
|
-
disconnect: this.disconnect.bind(this),
|
|
715
|
-
updateAccounts: function updateAccounts(accounts, chainId) {
|
|
716
|
-
var network = _this3.state.network;
|
|
717
|
-
if (chainId) {
|
|
718
|
-
network = getBlockChainNameFromId(chainId, _this3.meta) || Network.Unknown;
|
|
719
|
-
}
|
|
720
|
-
var nextAccounts = accountAddressesWithNetwork(accounts, network);
|
|
721
|
-
if (nextAccounts.length > 0) {
|
|
722
|
-
_this3.updateState({
|
|
723
|
-
accounts: nextAccounts
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
},
|
|
727
|
-
updateChainId: function updateChainId(chainId) {
|
|
728
|
-
var network = chainId ? getBlockChainNameFromId(chainId, _this3.meta) : Network.Unknown;
|
|
729
|
-
_this3.updateState({
|
|
730
|
-
network: network
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
_proto.setMeta = function setMeta(value) {
|
|
737
|
-
this.meta = value;
|
|
738
|
-
};
|
|
739
|
-
_proto.setHandler = function setHandler(handler) {
|
|
740
|
-
this.options.handler = handler;
|
|
741
|
-
};
|
|
742
|
-
_proto.getState = function getState() {
|
|
743
|
-
return this.state;
|
|
744
|
-
};
|
|
745
|
-
_proto.updateState = function updateState(states) {
|
|
746
|
-
var _this4 = this;
|
|
747
|
-
// We will notify handler after updating all the states.
|
|
748
|
-
// Because when we call `handler` it will has latest states.
|
|
749
|
-
var updates = [];
|
|
750
|
-
if (typeof states.connected !== 'undefined') {
|
|
751
|
-
this.state.connected = states.connected;
|
|
752
|
-
updates.push([Events.CONNECTED, states.connected]);
|
|
753
|
-
}
|
|
754
|
-
if (typeof states.connecting !== 'undefined') {
|
|
755
|
-
this.state.connecting = states.connecting;
|
|
756
|
-
updates.push([Events.CONNECTING, states.connecting]);
|
|
757
|
-
}
|
|
758
|
-
if (typeof states.reachable !== 'undefined') {
|
|
759
|
-
this.state.reachable = states.reachable;
|
|
760
|
-
updates.push([Events.REACHABLE, states.reachable]);
|
|
761
|
-
}
|
|
762
|
-
if (typeof states.installed !== 'undefined') {
|
|
763
|
-
this.state.installed = states.installed;
|
|
764
|
-
updates.push([Events.INSTALLED, states.installed]);
|
|
765
|
-
}
|
|
766
|
-
if (typeof states.accounts !== 'undefined') {
|
|
767
|
-
this.state.accounts = states.accounts;
|
|
768
|
-
updates.push([Events.ACCOUNTS, states.accounts]);
|
|
769
|
-
}
|
|
770
|
-
if (typeof states.network !== 'undefined') {
|
|
771
|
-
this.state.network = states.network;
|
|
772
|
-
updates.push([Events.NETWORK, states.network]);
|
|
773
|
-
}
|
|
774
|
-
var state = this.getState();
|
|
775
|
-
updates.forEach(function (_ref) {
|
|
776
|
-
var name = _ref[0],
|
|
777
|
-
value = _ref[1];
|
|
778
|
-
_this4.options.handler(_this4.options.config.type, name, value, state, _this4.meta);
|
|
779
|
-
});
|
|
780
|
-
};
|
|
781
|
-
_proto.resetState = function resetState() {
|
|
782
|
-
this.updateState({
|
|
783
|
-
connected: false,
|
|
784
|
-
connecting: false,
|
|
785
|
-
reachable: false,
|
|
786
|
-
accounts: null,
|
|
787
|
-
network: null
|
|
788
|
-
});
|
|
789
|
-
};
|
|
790
|
-
_proto.setInstalledAs = function setInstalledAs(value) {
|
|
791
|
-
if (!needsCheckInstallation(this.options) && value === false) return;
|
|
792
|
-
this.updateState({
|
|
793
|
-
installed: value
|
|
794
|
-
});
|
|
795
|
-
};
|
|
796
|
-
_proto.tryGetInstance = /*#__PURE__*/function () {
|
|
797
|
-
var _tryGetInstance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref2) {
|
|
798
|
-
var _this5 = this;
|
|
799
|
-
var network, force, instance, instanceOptions, error_message;
|
|
800
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
801
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
802
|
-
case 0:
|
|
803
|
-
network = _ref2.network, force = _ref2.force;
|
|
804
|
-
instance = null; // For switching network on Trust Wallet (WalletConnect),
|
|
805
|
-
// We only kill the session (and not restting the whole state)
|
|
806
|
-
// So we are relying on this.provider for achieving this functionality.
|
|
807
|
-
this.setProvider(null);
|
|
808
|
-
if (!this.options.config.isAsyncInstance) {
|
|
809
|
-
_context4.next = 11;
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
// Trying to connect
|
|
813
|
-
instanceOptions = {
|
|
814
|
-
currentProvider: this.provider,
|
|
815
|
-
meta: this.meta,
|
|
816
|
-
force: force || false,
|
|
817
|
-
updateChainId: function updateChainId(chainId) {
|
|
818
|
-
var network = chainId ? getBlockChainNameFromId(chainId, _this5.meta) : Network.Unknown;
|
|
819
|
-
_this5.updateState({
|
|
820
|
-
network: network
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
};
|
|
824
|
-
if (network) {
|
|
825
|
-
instanceOptions.network = network;
|
|
826
|
-
}
|
|
827
|
-
_context4.next = 8;
|
|
828
|
-
return this.actions.getInstance(instanceOptions);
|
|
829
|
-
case 8:
|
|
830
|
-
instance = _context4.sent;
|
|
831
|
-
_context4.next = 12;
|
|
832
|
-
break;
|
|
833
|
-
case 11:
|
|
834
|
-
instance = this.actions.getInstance();
|
|
835
|
-
case 12:
|
|
836
|
-
if (instance) {
|
|
837
|
-
_context4.next = 17;
|
|
838
|
-
break;
|
|
839
|
-
}
|
|
840
|
-
this.setInstalledAs(false);
|
|
841
|
-
this.resetState();
|
|
842
|
-
error_message = "It seems your selected wallet (" + this.options.config.type + ") isn't installed.";
|
|
843
|
-
throw new Error(error_message);
|
|
844
|
-
case 17:
|
|
845
|
-
this.setProvider(instance);
|
|
846
|
-
return _context4.abrupt("return", instance);
|
|
847
|
-
case 19:
|
|
848
|
-
case "end":
|
|
849
|
-
return _context4.stop();
|
|
850
|
-
}
|
|
851
|
-
}, _callee4, this);
|
|
852
|
-
}));
|
|
853
|
-
function tryGetInstance(_x2) {
|
|
854
|
-
return _tryGetInstance.apply(this, arguments);
|
|
855
|
-
}
|
|
856
|
-
return tryGetInstance;
|
|
857
|
-
}();
|
|
858
|
-
return Wallet;
|
|
859
|
-
}();
|
|
860
|
-
|
|
861
|
-
// TODO fix lint problem
|
|
862
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
863
|
-
// @ts-ignore
|
|
864
|
-
var WalletContext = /*#__PURE__*/createContext({});
|
|
865
|
-
/*
|
|
866
|
-
Our event handler includes an internal state updater, and a notifier
|
|
867
|
-
for the outside listener.
|
|
868
|
-
On creating first wallet refrence, and on chaning `props.onUpdateState`
|
|
869
|
-
we are using this function.
|
|
870
|
-
*/
|
|
871
|
-
function makeEventHandler(dispatcher, onUpdateState) {
|
|
872
|
-
var handler = function handler(type, name, value, coreState, supportedChains) {
|
|
873
|
-
var action = {
|
|
874
|
-
type: 'new_state',
|
|
875
|
-
wallet: type,
|
|
876
|
-
name: name,
|
|
877
|
-
value: value
|
|
878
|
-
};
|
|
879
|
-
// Update state
|
|
880
|
-
dispatcher(action);
|
|
881
|
-
// Giving the event to the outside listener
|
|
882
|
-
if (onUpdateState) {
|
|
883
|
-
onUpdateState(type, name, value, coreState, supportedChains);
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
return handler;
|
|
887
|
-
}
|
|
888
|
-
function useInitializers(onChangeState) {
|
|
889
|
-
var availableWallets = useRef({});
|
|
890
|
-
function updater(wallet) {
|
|
891
|
-
var type = wallet.config.type;
|
|
892
|
-
// We only update, if there is no instance available.
|
|
893
|
-
if (typeof availableWallets.current[type] === 'undefined') {
|
|
894
|
-
availableWallets.current[type] = new Wallet({
|
|
895
|
-
config: wallet.config,
|
|
896
|
-
handler: onChangeState
|
|
897
|
-
}, wallet.actions);
|
|
898
|
-
}
|
|
899
|
-
return availableWallets.current[type];
|
|
900
|
-
}
|
|
901
|
-
return updater;
|
|
902
|
-
}
|
|
903
|
-
function Provider(props) {
|
|
904
|
-
var _useReducer = useReducer(state_reducer, {}),
|
|
905
|
-
providersState = _useReducer[0],
|
|
906
|
-
dispatch = _useReducer[1];
|
|
907
|
-
var addWalletRef = useInitializers(makeEventHandler(dispatch, props.onUpdateState));
|
|
908
|
-
// const providersRef = useRef<{ [type in WalletType]?: any }>({});
|
|
909
|
-
var listOfProviders = props.providers;
|
|
910
|
-
var wallets = checkWalletProviders(listOfProviders);
|
|
911
|
-
var api = {
|
|
912
|
-
// TODO: Fix type error
|
|
913
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
914
|
-
// @ts-ignore
|
|
915
|
-
connect: function connect(type, network) {
|
|
916
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
917
|
-
var wallet, ref, result;
|
|
918
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
919
|
-
while (1) switch (_context.prev = _context.next) {
|
|
920
|
-
case 0:
|
|
921
|
-
wallet = wallets.get(type);
|
|
922
|
-
if (wallet) {
|
|
923
|
-
_context.next = 3;
|
|
924
|
-
break;
|
|
925
|
-
}
|
|
926
|
-
throw new Error("You should add " + type + " to provider first.");
|
|
927
|
-
case 3:
|
|
928
|
-
ref = addWalletRef(wallet);
|
|
929
|
-
_context.next = 6;
|
|
930
|
-
return ref.connect(network);
|
|
931
|
-
case 6:
|
|
932
|
-
result = _context.sent;
|
|
933
|
-
return _context.abrupt("return", result);
|
|
934
|
-
case 8:
|
|
935
|
-
case "end":
|
|
936
|
-
return _context.stop();
|
|
937
|
-
}
|
|
938
|
-
}, _callee);
|
|
939
|
-
}))();
|
|
940
|
-
},
|
|
941
|
-
disconnect: function disconnect(type) {
|
|
942
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
943
|
-
var wallet, ref;
|
|
944
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
945
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
946
|
-
case 0:
|
|
947
|
-
wallet = wallets.get(type);
|
|
948
|
-
if (wallet) {
|
|
949
|
-
_context2.next = 3;
|
|
950
|
-
break;
|
|
951
|
-
}
|
|
952
|
-
throw new Error("You should add " + type + " to provider first.");
|
|
953
|
-
case 3:
|
|
954
|
-
ref = addWalletRef(wallet);
|
|
955
|
-
_context2.next = 6;
|
|
956
|
-
return ref.disconnect();
|
|
957
|
-
case 6:
|
|
958
|
-
case "end":
|
|
959
|
-
return _context2.stop();
|
|
960
|
-
}
|
|
961
|
-
}, _callee2);
|
|
962
|
-
}))();
|
|
963
|
-
},
|
|
964
|
-
disconnectAll: function disconnectAll() {
|
|
965
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
966
|
-
var disconnect_promises;
|
|
967
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
968
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
969
|
-
case 0:
|
|
970
|
-
disconnect_promises = []; // When a wallet is initializing, a record will be added to `providersState`
|
|
971
|
-
// So we use them to know what wallet has been initialized then we need to
|
|
972
|
-
// filter connected wallets only.
|
|
973
|
-
connectedWallets(providersState).forEach(function (type) {
|
|
974
|
-
var wallet = wallets.get(type);
|
|
975
|
-
if (wallet) {
|
|
976
|
-
var ref = addWalletRef(wallet);
|
|
977
|
-
disconnect_promises.push(ref.disconnect());
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
_context3.next = 4;
|
|
981
|
-
return Promise.allSettled(disconnect_promises);
|
|
982
|
-
case 4:
|
|
983
|
-
return _context3.abrupt("return", _context3.sent);
|
|
984
|
-
case 5:
|
|
985
|
-
case "end":
|
|
986
|
-
return _context3.stop();
|
|
987
|
-
}
|
|
988
|
-
}, _callee3);
|
|
989
|
-
}))();
|
|
990
|
-
},
|
|
991
|
-
state: function state(type) {
|
|
992
|
-
return providersState[type] || defaultWalletState;
|
|
993
|
-
},
|
|
994
|
-
canSwitchNetworkTo: function canSwitchNetworkTo(type, network) {
|
|
995
|
-
var wallet = wallets.get(type);
|
|
996
|
-
if (!wallet) {
|
|
997
|
-
return false;
|
|
998
|
-
}
|
|
999
|
-
var ref = addWalletRef(wallet);
|
|
1000
|
-
return ref.canSwitchNetworkTo ? ref.canSwitchNetworkTo(network, ref.provider) : false;
|
|
1001
|
-
},
|
|
1002
|
-
providers: function providers() {
|
|
1003
|
-
var providers = {};
|
|
1004
|
-
availableWallets(providersState).forEach(function (type) {
|
|
1005
|
-
var wallet = wallets.get(type);
|
|
1006
|
-
if (wallet) {
|
|
1007
|
-
var ref = addWalletRef(wallet);
|
|
1008
|
-
providers[type] = ref.provider;
|
|
1009
|
-
}
|
|
1010
|
-
});
|
|
1011
|
-
return providers;
|
|
1012
|
-
},
|
|
1013
|
-
getWalletInfo: function getWalletInfo(type) {
|
|
1014
|
-
var wallet = wallets.get(type);
|
|
1015
|
-
if (!wallet) {
|
|
1016
|
-
throw new Error("You should add " + type + " to provider first.");
|
|
1017
|
-
}
|
|
1018
|
-
// Get wallet info could be used in render methods to show wallets data
|
|
1019
|
-
// So, addWalletRef method shouldn't be called in this method
|
|
1020
|
-
return wallet.actions.getWalletInfo(props.allBlockChains || []);
|
|
1021
|
-
},
|
|
1022
|
-
getSigners: function getSigners(type) {
|
|
1023
|
-
var wallet = wallets.get(type);
|
|
1024
|
-
if (!wallet) {
|
|
1025
|
-
throw new Error("You should add " + type + " to provider first.");
|
|
1026
|
-
}
|
|
1027
|
-
var ref = addWalletRef(wallet);
|
|
1028
|
-
var supportedChains = ref.getWalletInfo(props.allBlockChains || []).supportedChains;
|
|
1029
|
-
var provider = getComptaibleProvider(supportedChains, ref.provider, type);
|
|
1030
|
-
var result = ref.getSigners(provider);
|
|
1031
|
-
return result;
|
|
1032
|
-
}
|
|
1033
|
-
};
|
|
1034
|
-
useEffect(function () {
|
|
1035
|
-
wallets.forEach(function (wallet) {
|
|
1036
|
-
var ref = addWalletRef(wallet);
|
|
1037
|
-
var runOnInit = function runOnInit() {
|
|
1038
|
-
if (ref.onInit) {
|
|
1039
|
-
ref.onInit();
|
|
1040
|
-
}
|
|
1041
|
-
};
|
|
1042
|
-
var initWhenPageIsReady = function initWhenPageIsReady(event) {
|
|
1043
|
-
if (event.target && event.target.readyState === 'complete') {
|
|
1044
|
-
runOnInit();
|
|
1045
|
-
document.removeEventListener('readystatechange', initWhenPageIsReady);
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
// Try to run, maybe it's ready.
|
|
1049
|
-
runOnInit();
|
|
1050
|
-
// Try again when the page has been completely loaded.
|
|
1051
|
-
// Some of wallets, take some time to be fully injected and loaded.
|
|
1052
|
-
document.addEventListener('readystatechange', initWhenPageIsReady);
|
|
1053
|
-
});
|
|
1054
|
-
}, []);
|
|
1055
|
-
useEffect(function () {
|
|
1056
|
-
var allBlockChains = props.allBlockChains;
|
|
1057
|
-
if (allBlockChains) {
|
|
1058
|
-
wallets.forEach(function (wallet) {
|
|
1059
|
-
var ref = addWalletRef(wallet);
|
|
1060
|
-
var supportedChains = ref.getWalletInfo(props.allBlockChains || []).supportedChains;
|
|
1061
|
-
ref.setMeta(supportedChains);
|
|
1062
|
-
});
|
|
1063
|
-
}
|
|
1064
|
-
}, [props.allBlockChains]);
|
|
1065
|
-
useEffect(function () {
|
|
1066
|
-
wallets.forEach(function (wallet) {
|
|
1067
|
-
var ref = addWalletRef(wallet);
|
|
1068
|
-
ref.setHandler(makeEventHandler(dispatch, props.onUpdateState));
|
|
1069
|
-
});
|
|
1070
|
-
}, [props.onUpdateState]);
|
|
1071
|
-
return React.createElement(WalletContext.Provider, {
|
|
1072
|
-
value: api
|
|
1073
|
-
}, props.children);
|
|
1074
|
-
}
|
|
1075
|
-
function useWallets() {
|
|
1076
|
-
var context = useContext(WalletContext);
|
|
1077
|
-
if (!context) throw Error('useWallet can only be used within the Provider component');
|
|
1078
|
-
return context;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
export { Events, Provider, accountAddressesWithNetwork, availableWallets, checkWalletProviders, choose, connectedWallets, defaultWalletState, formatAddressWithNetwork, getComptaibleProvider, isAsync, isWalletDerivedFromWalletConnect, needsCheckInstallation, readAccountAddress, state_reducer, useWallets };
|
|
1082
|
-
//# sourceMappingURL=wallets-core.esm.js.map
|