@rango-dev/queue-manager-rango-preset 0.1.10-next.101

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.
Files changed (60) hide show
  1. package/dist/actions/checkStatus.d.ts +12 -0
  2. package/dist/actions/checkStatus.d.ts.map +1 -0
  3. package/dist/actions/createTransaction.d.ts +11 -0
  4. package/dist/actions/createTransaction.d.ts.map +1 -0
  5. package/dist/actions/executeTransaction.d.ts +13 -0
  6. package/dist/actions/executeTransaction.d.ts.map +1 -0
  7. package/dist/actions/scheduleNextStep.d.ts +13 -0
  8. package/dist/actions/scheduleNextStep.d.ts.map +1 -0
  9. package/dist/actions/start.d.ts +4 -0
  10. package/dist/actions/start.d.ts.map +1 -0
  11. package/dist/constants.d.ts +8 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/helpers.d.ts +197 -0
  14. package/dist/helpers.d.ts.map +1 -0
  15. package/dist/hooks.d.ts +19 -0
  16. package/dist/hooks.d.ts.map +1 -0
  17. package/dist/index.d.ts +7 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +8 -0
  20. package/dist/migration.d.ts +15 -0
  21. package/dist/migration.d.ts.map +1 -0
  22. package/dist/queue-manager-rango-preset.cjs.development.js +2799 -0
  23. package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -0
  24. package/dist/queue-manager-rango-preset.cjs.production.min.js +2 -0
  25. package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -0
  26. package/dist/queue-manager-rango-preset.esm.js +2781 -0
  27. package/dist/queue-manager-rango-preset.esm.js.map +1 -0
  28. package/dist/queueDef.d.ts +10 -0
  29. package/dist/queueDef.d.ts.map +1 -0
  30. package/dist/services/httpService.d.ts +3 -0
  31. package/dist/services/httpService.d.ts.map +1 -0
  32. package/dist/services/index.d.ts +2 -0
  33. package/dist/services/index.d.ts.map +1 -0
  34. package/dist/shared-errors.d.ts +25 -0
  35. package/dist/shared-errors.d.ts.map +1 -0
  36. package/dist/shared-sentry.d.ts +4 -0
  37. package/dist/shared-sentry.d.ts.map +1 -0
  38. package/dist/shared.d.ts +148 -0
  39. package/dist/shared.d.ts.map +1 -0
  40. package/dist/types.d.ts +48 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/package.json +62 -0
  43. package/readme.md +8 -0
  44. package/src/actions/checkStatus.ts +269 -0
  45. package/src/actions/createTransaction.ts +122 -0
  46. package/src/actions/executeTransaction.ts +121 -0
  47. package/src/actions/scheduleNextStep.ts +61 -0
  48. package/src/actions/start.ts +10 -0
  49. package/src/constants.ts +22 -0
  50. package/src/helpers.ts +1774 -0
  51. package/src/hooks.ts +76 -0
  52. package/src/index.ts +27 -0
  53. package/src/migration.ts +124 -0
  54. package/src/queueDef.ts +39 -0
  55. package/src/services/httpService.ts +7 -0
  56. package/src/services/index.ts +1 -0
  57. package/src/shared-errors.ts +160 -0
  58. package/src/shared-sentry.ts +24 -0
  59. package/src/shared.ts +342 -0
  60. package/src/types.ts +76 -0
@@ -0,0 +1,2799 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var rangoTypes = require('rango-types');
6
+ var walletsShared = require('@rango-dev/wallets-shared');
7
+ var walletsCore = require('@rango-dev/wallets-core');
8
+ var rangoSdk = require('rango-sdk');
9
+ var queueManagerCore = require('@rango-dev/queue-manager-core');
10
+ var Sentry = require('@sentry/browser');
11
+ var queueManagerReact = require('@rango-dev/queue-manager-react');
12
+ var react = require('react');
13
+ var uuid = require('uuid');
14
+
15
+ function _regeneratorRuntime() {
16
+ _regeneratorRuntime = function () {
17
+ return exports;
18
+ };
19
+ var exports = {},
20
+ Op = Object.prototype,
21
+ hasOwn = Op.hasOwnProperty,
22
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
23
+ obj[key] = desc.value;
24
+ },
25
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
26
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
27
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
28
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
29
+ function define(obj, key, value) {
30
+ return Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: !0,
33
+ configurable: !0,
34
+ writable: !0
35
+ }), obj[key];
36
+ }
37
+ try {
38
+ define({}, "");
39
+ } catch (err) {
40
+ define = function (obj, key, value) {
41
+ return obj[key] = value;
42
+ };
43
+ }
44
+ function wrap(innerFn, outerFn, self, tryLocsList) {
45
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
46
+ generator = Object.create(protoGenerator.prototype),
47
+ context = new Context(tryLocsList || []);
48
+ return defineProperty(generator, "_invoke", {
49
+ value: makeInvokeMethod(innerFn, self, context)
50
+ }), generator;
51
+ }
52
+ function tryCatch(fn, obj, arg) {
53
+ try {
54
+ return {
55
+ type: "normal",
56
+ arg: fn.call(obj, arg)
57
+ };
58
+ } catch (err) {
59
+ return {
60
+ type: "throw",
61
+ arg: err
62
+ };
63
+ }
64
+ }
65
+ exports.wrap = wrap;
66
+ var ContinueSentinel = {};
67
+ function Generator() {}
68
+ function GeneratorFunction() {}
69
+ function GeneratorFunctionPrototype() {}
70
+ var IteratorPrototype = {};
71
+ define(IteratorPrototype, iteratorSymbol, function () {
72
+ return this;
73
+ });
74
+ var getProto = Object.getPrototypeOf,
75
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
76
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
77
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
78
+ function defineIteratorMethods(prototype) {
79
+ ["next", "throw", "return"].forEach(function (method) {
80
+ define(prototype, method, function (arg) {
81
+ return this._invoke(method, arg);
82
+ });
83
+ });
84
+ }
85
+ function AsyncIterator(generator, PromiseImpl) {
86
+ function invoke(method, arg, resolve, reject) {
87
+ var record = tryCatch(generator[method], generator, arg);
88
+ if ("throw" !== record.type) {
89
+ var result = record.arg,
90
+ value = result.value;
91
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
92
+ invoke("next", value, resolve, reject);
93
+ }, function (err) {
94
+ invoke("throw", err, resolve, reject);
95
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
96
+ result.value = unwrapped, resolve(result);
97
+ }, function (error) {
98
+ return invoke("throw", error, resolve, reject);
99
+ });
100
+ }
101
+ reject(record.arg);
102
+ }
103
+ var previousPromise;
104
+ defineProperty(this, "_invoke", {
105
+ value: function (method, arg) {
106
+ function callInvokeWithMethodAndArg() {
107
+ return new PromiseImpl(function (resolve, reject) {
108
+ invoke(method, arg, resolve, reject);
109
+ });
110
+ }
111
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
112
+ }
113
+ });
114
+ }
115
+ function makeInvokeMethod(innerFn, self, context) {
116
+ var state = "suspendedStart";
117
+ return function (method, arg) {
118
+ if ("executing" === state) throw new Error("Generator is already running");
119
+ if ("completed" === state) {
120
+ if ("throw" === method) throw arg;
121
+ return doneResult();
122
+ }
123
+ for (context.method = method, context.arg = arg;;) {
124
+ var delegate = context.delegate;
125
+ if (delegate) {
126
+ var delegateResult = maybeInvokeDelegate(delegate, context);
127
+ if (delegateResult) {
128
+ if (delegateResult === ContinueSentinel) continue;
129
+ return delegateResult;
130
+ }
131
+ }
132
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
133
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
134
+ context.dispatchException(context.arg);
135
+ } else "return" === context.method && context.abrupt("return", context.arg);
136
+ state = "executing";
137
+ var record = tryCatch(innerFn, self, context);
138
+ if ("normal" === record.type) {
139
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
140
+ return {
141
+ value: record.arg,
142
+ done: context.done
143
+ };
144
+ }
145
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
146
+ }
147
+ };
148
+ }
149
+ function maybeInvokeDelegate(delegate, context) {
150
+ var methodName = context.method,
151
+ method = delegate.iterator[methodName];
152
+ 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;
153
+ var record = tryCatch(method, delegate.iterator, context.arg);
154
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
155
+ var info = record.arg;
156
+ 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);
157
+ }
158
+ function pushTryEntry(locs) {
159
+ var entry = {
160
+ tryLoc: locs[0]
161
+ };
162
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
163
+ }
164
+ function resetTryEntry(entry) {
165
+ var record = entry.completion || {};
166
+ record.type = "normal", delete record.arg, entry.completion = record;
167
+ }
168
+ function Context(tryLocsList) {
169
+ this.tryEntries = [{
170
+ tryLoc: "root"
171
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
172
+ }
173
+ function values(iterable) {
174
+ if (iterable) {
175
+ var iteratorMethod = iterable[iteratorSymbol];
176
+ if (iteratorMethod) return iteratorMethod.call(iterable);
177
+ if ("function" == typeof iterable.next) return iterable;
178
+ if (!isNaN(iterable.length)) {
179
+ var i = -1,
180
+ next = function next() {
181
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
182
+ return next.value = undefined, next.done = !0, next;
183
+ };
184
+ return next.next = next;
185
+ }
186
+ }
187
+ return {
188
+ next: doneResult
189
+ };
190
+ }
191
+ function doneResult() {
192
+ return {
193
+ value: undefined,
194
+ done: !0
195
+ };
196
+ }
197
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
198
+ value: GeneratorFunctionPrototype,
199
+ configurable: !0
200
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
201
+ value: GeneratorFunction,
202
+ configurable: !0
203
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
204
+ var ctor = "function" == typeof genFun && genFun.constructor;
205
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
206
+ }, exports.mark = function (genFun) {
207
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
208
+ }, exports.awrap = function (arg) {
209
+ return {
210
+ __await: arg
211
+ };
212
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
213
+ return this;
214
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
215
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
216
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
217
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
218
+ return result.done ? result.value : iter.next();
219
+ });
220
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
221
+ return this;
222
+ }), define(Gp, "toString", function () {
223
+ return "[object Generator]";
224
+ }), exports.keys = function (val) {
225
+ var object = Object(val),
226
+ keys = [];
227
+ for (var key in object) keys.push(key);
228
+ return keys.reverse(), function next() {
229
+ for (; keys.length;) {
230
+ var key = keys.pop();
231
+ if (key in object) return next.value = key, next.done = !1, next;
232
+ }
233
+ return next.done = !0, next;
234
+ };
235
+ }, exports.values = values, Context.prototype = {
236
+ constructor: Context,
237
+ reset: function (skipTempReset) {
238
+ 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);
239
+ },
240
+ stop: function () {
241
+ this.done = !0;
242
+ var rootRecord = this.tryEntries[0].completion;
243
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
244
+ return this.rval;
245
+ },
246
+ dispatchException: function (exception) {
247
+ if (this.done) throw exception;
248
+ var context = this;
249
+ function handle(loc, caught) {
250
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
251
+ }
252
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
253
+ var entry = this.tryEntries[i],
254
+ record = entry.completion;
255
+ if ("root" === entry.tryLoc) return handle("end");
256
+ if (entry.tryLoc <= this.prev) {
257
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
258
+ hasFinally = hasOwn.call(entry, "finallyLoc");
259
+ if (hasCatch && hasFinally) {
260
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
261
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
262
+ } else if (hasCatch) {
263
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
264
+ } else {
265
+ if (!hasFinally) throw new Error("try statement without catch or finally");
266
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
267
+ }
268
+ }
269
+ }
270
+ },
271
+ abrupt: function (type, arg) {
272
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
273
+ var entry = this.tryEntries[i];
274
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
275
+ var finallyEntry = entry;
276
+ break;
277
+ }
278
+ }
279
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
280
+ var record = finallyEntry ? finallyEntry.completion : {};
281
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
282
+ },
283
+ complete: function (record, afterLoc) {
284
+ if ("throw" === record.type) throw record.arg;
285
+ 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;
286
+ },
287
+ finish: function (finallyLoc) {
288
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
289
+ var entry = this.tryEntries[i];
290
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
291
+ }
292
+ },
293
+ catch: function (tryLoc) {
294
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
295
+ var entry = this.tryEntries[i];
296
+ if (entry.tryLoc === tryLoc) {
297
+ var record = entry.completion;
298
+ if ("throw" === record.type) {
299
+ var thrown = record.arg;
300
+ resetTryEntry(entry);
301
+ }
302
+ return thrown;
303
+ }
304
+ }
305
+ throw new Error("illegal catch attempt");
306
+ },
307
+ delegateYield: function (iterable, resultName, nextLoc) {
308
+ return this.delegate = {
309
+ iterator: values(iterable),
310
+ resultName: resultName,
311
+ nextLoc: nextLoc
312
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
313
+ }
314
+ }, exports;
315
+ }
316
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
317
+ try {
318
+ var info = gen[key](arg);
319
+ var value = info.value;
320
+ } catch (error) {
321
+ reject(error);
322
+ return;
323
+ }
324
+ if (info.done) {
325
+ resolve(value);
326
+ } else {
327
+ Promise.resolve(value).then(_next, _throw);
328
+ }
329
+ }
330
+ function _asyncToGenerator(fn) {
331
+ return function () {
332
+ var self = this,
333
+ args = arguments;
334
+ return new Promise(function (resolve, reject) {
335
+ var gen = fn.apply(self, args);
336
+ function _next(value) {
337
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
338
+ }
339
+ function _throw(err) {
340
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
341
+ }
342
+ _next(undefined);
343
+ });
344
+ };
345
+ }
346
+ function _extends() {
347
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
348
+ for (var i = 1; i < arguments.length; i++) {
349
+ var source = arguments[i];
350
+ for (var key in source) {
351
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
352
+ target[key] = source[key];
353
+ }
354
+ }
355
+ }
356
+ return target;
357
+ };
358
+ return _extends.apply(this, arguments);
359
+ }
360
+ function _inheritsLoose(subClass, superClass) {
361
+ subClass.prototype = Object.create(superClass.prototype);
362
+ subClass.prototype.constructor = subClass;
363
+ _setPrototypeOf(subClass, superClass);
364
+ }
365
+ function _getPrototypeOf(o) {
366
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
367
+ return o.__proto__ || Object.getPrototypeOf(o);
368
+ };
369
+ return _getPrototypeOf(o);
370
+ }
371
+ function _setPrototypeOf(o, p) {
372
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
373
+ o.__proto__ = p;
374
+ return o;
375
+ };
376
+ return _setPrototypeOf(o, p);
377
+ }
378
+ function _isNativeReflectConstruct() {
379
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
380
+ if (Reflect.construct.sham) return false;
381
+ if (typeof Proxy === "function") return true;
382
+ try {
383
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
384
+ return true;
385
+ } catch (e) {
386
+ return false;
387
+ }
388
+ }
389
+ function _construct(Parent, args, Class) {
390
+ if (_isNativeReflectConstruct()) {
391
+ _construct = Reflect.construct.bind();
392
+ } else {
393
+ _construct = function _construct(Parent, args, Class) {
394
+ var a = [null];
395
+ a.push.apply(a, args);
396
+ var Constructor = Function.bind.apply(Parent, a);
397
+ var instance = new Constructor();
398
+ if (Class) _setPrototypeOf(instance, Class.prototype);
399
+ return instance;
400
+ };
401
+ }
402
+ return _construct.apply(null, arguments);
403
+ }
404
+ function _isNativeFunction(fn) {
405
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
406
+ }
407
+ function _wrapNativeSuper(Class) {
408
+ var _cache = typeof Map === "function" ? new Map() : undefined;
409
+ _wrapNativeSuper = function _wrapNativeSuper(Class) {
410
+ if (Class === null || !_isNativeFunction(Class)) return Class;
411
+ if (typeof Class !== "function") {
412
+ throw new TypeError("Super expression must either be null or a function");
413
+ }
414
+ if (typeof _cache !== "undefined") {
415
+ if (_cache.has(Class)) return _cache.get(Class);
416
+ _cache.set(Class, Wrapper);
417
+ }
418
+ function Wrapper() {
419
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
420
+ }
421
+ Wrapper.prototype = Object.create(Class.prototype, {
422
+ constructor: {
423
+ value: Wrapper,
424
+ enumerable: false,
425
+ writable: true,
426
+ configurable: true
427
+ }
428
+ });
429
+ return _setPrototypeOf(Wrapper, Class);
430
+ };
431
+ return _wrapNativeSuper(Class);
432
+ }
433
+ function _assertThisInitialized(self) {
434
+ if (self === void 0) {
435
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
436
+ }
437
+ return self;
438
+ }
439
+
440
+ var ERROR_ASSERTION_FAILED = 'Assertion failed (Unexpected behaviour)';
441
+ var ERROR_CREATE_TRANSACTION = 'Create transaction failed in Rango Server';
442
+ var ERROR_INPUT_WALLET_NOT_FOUND = 'Input wallet not found';
443
+ var PrettyError = /*#__PURE__*/function (_Error) {
444
+ _inheritsLoose(PrettyError, _Error);
445
+ function PrettyError(code, m, root, detail) {
446
+ var _this;
447
+ _this = _Error.call(this, m) || this;
448
+ _this._isPrettyError = true;
449
+ Object.setPrototypeOf(_assertThisInitialized(_this), PrettyError.prototype);
450
+ PrettyError.prototype._isPrettyError = true;
451
+ _this.code = code;
452
+ _this.detail = detail;
453
+ _this.root = root;
454
+ return _this;
455
+ }
456
+ PrettyError.isPrettyError = function isPrettyError(obj) {
457
+ return obj instanceof PrettyError || Object.prototype.hasOwnProperty('_isPrettyError');
458
+ };
459
+ var _proto = PrettyError.prototype;
460
+ _proto.getErrorDetail = function getErrorDetail() {
461
+ var rawMessage = typeof this.root === 'object' && this.root && this.root.error ? this.root.error : JSON.stringify(this.root);
462
+ var rootStr = typeof this.root === 'string' ? this.root : this.root instanceof Error ? this.root.message : rawMessage;
463
+ return {
464
+ extraMessage: this.message,
465
+ extraMessageDetail: this.detail || rootStr,
466
+ extraMessageErrorCode: this.code || null
467
+ };
468
+ };
469
+ PrettyError.AssertionFailed = function AssertionFailed(m) {
470
+ return new PrettyError('CLIENT_UNEXPECTED_BEHAVIOUR', ERROR_ASSERTION_FAILED, m);
471
+ };
472
+ PrettyError.BadStatusCode = function BadStatusCode(message, statusCode) {
473
+ return new PrettyError('TX_FAIL', message, null, "status code = " + statusCode);
474
+ };
475
+ PrettyError.CreateTransaction = function CreateTransaction(detail) {
476
+ return new PrettyError('FETCH_TX_FAILED', ERROR_CREATE_TRANSACTION, null, detail);
477
+ };
478
+ PrettyError.WalletMissing = function WalletMissing() {
479
+ return new PrettyError('CLIENT_UNEXPECTED_BEHAVIOUR', ERROR_INPUT_WALLET_NOT_FOUND, null, 'Server requested for a blockchain or address not selected by user');
480
+ };
481
+ PrettyError.BlockchainMissing = function BlockchainMissing() {
482
+ return new PrettyError('CLIENT_UNEXPECTED_BEHAVIOUR', ERROR_INPUT_WALLET_NOT_FOUND, null, 'Server requested for a blockchain or address not selected by user');
483
+ };
484
+ return PrettyError;
485
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
486
+ function mapAppErrorCodesToAPIErrorCode(errorCode) {
487
+ var defaultErrorCode = 'CLIENT_UNEXPECTED_BEHAVIOUR';
488
+ try {
489
+ if (!errorCode) return defaultErrorCode;
490
+ if (rangoTypes.isAPIErrorCode(errorCode)) return errorCode;
491
+ if (rangoTypes.isSignerErrorCode(errorCode)) {
492
+ var _t;
493
+ var t = (_t = {}, _t[rangoTypes.SignerErrorCode.REJECTED_BY_USER] = 'USER_REJECT', _t[rangoTypes.SignerErrorCode.SIGN_TX_ERROR] = 'CALL_WALLET_FAILED', _t[rangoTypes.SignerErrorCode.SEND_TX_ERROR] = 'SEND_TX_FAILED', _t[rangoTypes.SignerErrorCode.NOT_IMPLEMENTED] = defaultErrorCode, _t[rangoTypes.SignerErrorCode.OPERATION_UNSUPPORTED] = defaultErrorCode, _t[rangoTypes.SignerErrorCode.UNEXPECTED_BEHAVIOUR] = defaultErrorCode, _t);
494
+ return t[errorCode];
495
+ }
496
+ return defaultErrorCode;
497
+ } catch (err) {
498
+ return defaultErrorCode;
499
+ }
500
+ }
501
+ var prettifyErrorMessage = function prettifyErrorMessage(obj) {
502
+ if (!obj) return {
503
+ extraMessage: '',
504
+ extraMessageErrorCode: null
505
+ };
506
+ if (PrettyError.isPrettyError(obj)) return obj.getErrorDetail();
507
+ if (rangoTypes.SignerError.isSignerError(obj)) {
508
+ var t = obj.getErrorDetail();
509
+ return {
510
+ extraMessage: t.message,
511
+ extraMessageDetail: t.detail,
512
+ extraMessageErrorCode: t.code
513
+ };
514
+ }
515
+ if (obj instanceof Error) return {
516
+ extraMessage: obj.toString(),
517
+ extraMessageErrorCode: null
518
+ };
519
+ if (typeof obj !== 'string') return {
520
+ extraMessage: JSON.stringify(obj),
521
+ extraMessageErrorCode: null
522
+ };
523
+ return {
524
+ extraMessage: obj,
525
+ extraMessageErrorCode: null
526
+ };
527
+ };
528
+
529
+ (function (PendingSwapNetworkStatus) {
530
+ PendingSwapNetworkStatus["WaitingForConnectingWallet"] = "waitingForConnectingWallet";
531
+ PendingSwapNetworkStatus["WaitingForQueue"] = "waitingForQueue";
532
+ PendingSwapNetworkStatus["WaitingForNetworkChange"] = "waitingForNetworkChange";
533
+ PendingSwapNetworkStatus["NetworkChanged"] = "networkChanged";
534
+ })(exports.PendingSwapNetworkStatus || (exports.PendingSwapNetworkStatus = {}));
535
+ (function (MessageSeverity) {
536
+ MessageSeverity["error"] = "error";
537
+ MessageSeverity["warning"] = "warning";
538
+ MessageSeverity["info"] = "info";
539
+ MessageSeverity["success"] = "success";
540
+ })(exports.MessageSeverity || (exports.MessageSeverity = {}));
541
+ var getCurrentBlockchainOfOrNull = function getCurrentBlockchainOfOrNull(swap, step) {
542
+ try {
543
+ return getCurrentBlockchainOf(swap, step);
544
+ } catch (e) {
545
+ return null;
546
+ }
547
+ };
548
+ var getCurrentBlockchainOf = function getCurrentBlockchainOf(swap, step) {
549
+ var _step$evmTransaction, _step$evmApprovalTran, _step$starknetTransac, _step$starknetApprova, _step$tronTransaction, _step$tronApprovalTra, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac;
550
+ var b1 = ((_step$evmTransaction = step.evmTransaction) == null ? void 0 : _step$evmTransaction.blockChain) || ((_step$evmApprovalTran = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran.blockChain) || ((_step$starknetTransac = step.starknetTransaction) == null ? void 0 : _step$starknetTransac.blockChain) || ((_step$starknetApprova = step.starknetApprovalTransaction) == null ? void 0 : _step$starknetApprova.blockChain) || ((_step$tronTransaction = step.tronTransaction) == null ? void 0 : _step$tronTransaction.blockChain) || ((_step$tronApprovalTra = step.tronApprovalTransaction) == null ? void 0 : _step$tronApprovalTra.blockChain) || ((_step$cosmosTransacti = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti.blockChain) || ((_step$solanaTransacti = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti.blockChain);
551
+ if (!!b1) return b1;
552
+ var transferAddress = (_step$transferTransac = step.transferTransaction) == null ? void 0 : _step$transferTransac.fromWalletAddress;
553
+ if (!transferAddress) throw PrettyError.BlockchainMissing();
554
+ var blockchain = Object.keys(swap.wallets).find(function (b) {
555
+ var _swap$wallets$b;
556
+ return ((_swap$wallets$b = swap.wallets[b]) == null ? void 0 : _swap$wallets$b.address) === transferAddress;
557
+ }) || null;
558
+ if (blockchain == null) throw PrettyError.BlockchainMissing();
559
+ // TODO: check why it returns string
560
+ return blockchain;
561
+ };
562
+ var getEvmApproveUrl = function getEvmApproveUrl(tx, network, evmBasedBlockchains) {
563
+ var evmBlochain = evmBasedBlockchains.find(function (blockchain) {
564
+ return blockchain.name === network;
565
+ });
566
+ if (!evmBlochain) {
567
+ throw Error("unsupported network: " + network + " for getting approve url.");
568
+ }
569
+ if (evmBlochain.info.transactionUrl) return evmBlochain.info.transactionUrl.replace('{txHash}', tx.toLowerCase());
570
+ throw Error("Explorer url for " + network + " is not implemented");
571
+ };
572
+ var getStarknetApproveUrl = function getStarknetApproveUrl(tx) {
573
+ return 'https://starkscan.co/tx/{txHash}'.replace('{txHash}', tx.toLowerCase());
574
+ };
575
+ var getTronApproveUrl = function getTronApproveUrl(tx) {
576
+ return 'https://tronscan.org/#/transaction/{txHash}'.replace('{txHash}', tx.toLowerCase());
577
+ };
578
+ function getNextStep(swap, currentStep) {
579
+ return swap.steps.find(function (step) {
580
+ return step.status !== 'failed' && step.status !== 'success' && step.id !== currentStep.id;
581
+ }) || null;
582
+ }
583
+ /**
584
+ * Returns the wallet address, based on the current step of `PendingSwap`.
585
+ */
586
+ var getCurrentAddressOf = function getCurrentAddressOf(swap, step) {
587
+ var _step$evmTransaction2, _step$evmApprovalTran2, _step$tronTransaction2, _step$tronApprovalTra2, _step$starknetTransac2, _step$starknetApprova2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac2, _step$transferTransac3;
588
+ var result = swap.wallets[((_step$evmTransaction2 = step.evmTransaction) == null ? void 0 : _step$evmTransaction2.blockChain) || ''] || swap.wallets[((_step$evmApprovalTran2 = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran2.blockChain) || ''] || swap.wallets[((_step$tronTransaction2 = step.tronTransaction) == null ? void 0 : _step$tronTransaction2.blockChain) || ''] || swap.wallets[((_step$tronApprovalTra2 = step.tronApprovalTransaction) == null ? void 0 : _step$tronApprovalTra2.blockChain) || ''] || swap.wallets[((_step$starknetTransac2 = step.starknetTransaction) == null ? void 0 : _step$starknetTransac2.blockChain) || ''] || swap.wallets[((_step$starknetApprova2 = step.starknetApprovalTransaction) == null ? void 0 : _step$starknetApprova2.blockChain) || ''] || swap.wallets[((_step$cosmosTransacti2 = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti2.blockChain) || ''] || swap.wallets[((_step$solanaTransacti2 = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti2.blockChain) || ''] || ((_step$transferTransac2 = step.transferTransaction) != null && _step$transferTransac2.fromWalletAddress ? {
589
+ address: (_step$transferTransac3 = step.transferTransaction) == null ? void 0 : _step$transferTransac3.fromWalletAddress
590
+ } : null) || null;
591
+ if (result == null) throw PrettyError.WalletMissing();
592
+ return result.address;
593
+ };
594
+ function getRelatedWallet(swap, currentStep) {
595
+ var walletAddress = getCurrentAddressOf(swap, currentStep);
596
+ var walletKV = Object.keys(swap.wallets).map(function (k) {
597
+ return {
598
+ k: k,
599
+ v: swap.wallets[k]
600
+ };
601
+ }).find(function (_ref) {
602
+ var v = _ref.v;
603
+ return v.address === walletAddress;
604
+ }) || null;
605
+ var blockchain = (walletKV == null ? void 0 : walletKV.k) || null;
606
+ var wallet = (walletKV == null ? void 0 : walletKV.v) || null;
607
+ var walletType = wallet == null ? void 0 : wallet.walletType;
608
+ if (walletType === walletsShared.WalletType.UNKNOWN || wallet === null) throw PrettyError.AssertionFailed("Wallet for source " + blockchain + " not passed: walletType: " + walletType);
609
+ return wallet;
610
+ }
611
+ function getRelatedWalletOrNull(swap, currentStep) {
612
+ try {
613
+ return getRelatedWallet(swap, currentStep);
614
+ } catch (e) {
615
+ return null;
616
+ }
617
+ }
618
+
619
+ var SwapActionTypes;
620
+ (function (SwapActionTypes) {
621
+ SwapActionTypes["START"] = "START";
622
+ SwapActionTypes["SCHEDULE_NEXT_STEP"] = "SCHEDULE_NEXT_STEP";
623
+ SwapActionTypes["CREATE_TRANSACTION"] = "CREATE_TRANSACTION";
624
+ SwapActionTypes["EXECUTE_TRANSACTION"] = "EXECUTE_TRANSACTION";
625
+ SwapActionTypes["CHECK_TRANSACTION_STATUS"] = "CHECK_TRANSACTION_STATUS";
626
+ })(SwapActionTypes || (SwapActionTypes = {}));
627
+ var BlockReason;
628
+ (function (BlockReason) {
629
+ BlockReason["WAIT_FOR_CONNECT_WALLET"] = "waiting_for_connecting_wallet";
630
+ BlockReason["WAIT_FOR_NETWORK_CHANGE"] = "waiting_for_network_change";
631
+ BlockReason["DEPENDS_ON_OTHER_QUEUES"] = "depends_on_other_queues";
632
+ })(BlockReason || (BlockReason = {}));
633
+
634
+ var RANGO_DAPP_API_KEY = process.env.REACT_APP_API_KEY;
635
+ var RANGO_DAPP_API_BASE_URL = process.env.REACT_APP_API_BASE_URL;
636
+ var ERROR_MESSAGE_WAIT_FOR_WALLET = 'Waiting for connecting wallet';
637
+ var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address) {
638
+ return "Please change your " + (type || 'wallet') + " account to " + (address || 'proper address');
639
+ };
640
+ var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) {
641
+ return "Please connect to " + (type || 'your wallet') + " by using bellow button or top right button on page.";
642
+ };
643
+ var ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK = function ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(network) {
644
+ return "Please change your network to " + network + ".";
645
+ };
646
+
647
+ function logRPCError(error, swap, currentStep, walletType) {
648
+ try {
649
+ Sentry.captureException(error, {
650
+ tags: {
651
+ requestId: swap.requestId,
652
+ rpc: true,
653
+ swapper: (currentStep == null ? void 0 : currentStep.swapperId) || '',
654
+ walletType: walletType || ''
655
+ },
656
+ level: 'warning'
657
+ });
658
+ } catch (e) {
659
+ console.log({
660
+ e: e
661
+ });
662
+ }
663
+ }
664
+
665
+ var httpService = /*#__PURE__*/new rangoSdk.RangoClient(RANGO_DAPP_API_KEY || '', RANGO_DAPP_API_BASE_URL);
666
+
667
+ var swapClaimedBy = null;
668
+ /**
669
+ *
670
+ * We simply use module-level variable to keep track of which queue has claimed the execution of parallel runnings.
671
+ *
672
+ */
673
+ function claimQueue() {
674
+ return {
675
+ claimedBy: function claimedBy() {
676
+ var _swapClaimedBy;
677
+ return (_swapClaimedBy = swapClaimedBy) == null ? void 0 : _swapClaimedBy.id;
678
+ },
679
+ setClaimer: function setClaimer(queue_id) {
680
+ swapClaimedBy = {
681
+ id: queue_id
682
+ };
683
+ },
684
+ reset: function reset() {
685
+ swapClaimedBy = null;
686
+ }
687
+ };
688
+ }
689
+ /**
690
+ * Sample inputs are:
691
+ * - "metamask-ETH"
692
+ * - "metamask-BSC-BSC:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
693
+ * - "token-pocket-BSC-BSC:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
694
+ * Returns "wallet and network" separately, even if the wallet is dashed inside.
695
+ *
696
+ */
697
+ function splitWalletNetwork(input) {
698
+ var removedAddressInput = (input == null ? void 0 : input.split(':')[0]) || '';
699
+ var splittedInput = removedAddressInput.split('-');
700
+ var network = splittedInput[splittedInput.length - 1];
701
+ var walletNetwork = splittedInput.slice(0, -1);
702
+ if (walletNetwork[walletNetwork.length - 1] === network) {
703
+ walletNetwork.pop();
704
+ }
705
+ var wallet = walletNetwork.join('-');
706
+ return [wallet, network];
707
+ }
708
+ /**
709
+ *
710
+ * Returns `steps`, if it's a `running` swap.
711
+ * Each `PendingSwap` has a `steps` inside it, `steps` shows how many tasks should be created and run to finish the swap.
712
+ *
713
+ */
714
+ var getCurrentStep = function getCurrentStep(swap) {
715
+ return swap.steps.find(function (step) {
716
+ return step.status !== 'failed' && step.status !== 'success';
717
+ }) || null;
718
+ };
719
+ /**
720
+ * When we are doing a swap, there are some common fields that will be updated together.
721
+ * This function helps us to update a swap status and also it will update some more fields like `extraMessageSeverity` based on the input.
722
+ */
723
+ function updateSwapStatus(_ref) {
724
+ var getStorage = _ref.getStorage,
725
+ setStorage = _ref.setStorage,
726
+ nextStatus = _ref.nextStatus,
727
+ nextStepStatus = _ref.nextStepStatus,
728
+ message = _ref.message,
729
+ details = _ref.details,
730
+ _ref$errorCode = _ref.errorCode,
731
+ errorCode = _ref$errorCode === void 0 ? null : _ref$errorCode,
732
+ hasAlreadyProceededToSign = _ref.hasAlreadyProceededToSign;
733
+ var swap = getStorage().swapDetails;
734
+ var currentStep = getCurrentStep(swap);
735
+ if (!!nextStepStatus && !!currentStep) currentStep.status = nextStepStatus;
736
+ if (!!nextStatus) swap.status = nextStatus;
737
+ swap.hasAlreadyProceededToSign = hasAlreadyProceededToSign;
738
+ if (!!nextStatus && ['failed', 'success'].includes(nextStatus)) swap.finishTime = new Date().getTime().toString();
739
+ if (!!message || !!details) {
740
+ swap.extraMessage = message || '';
741
+ swap.extraMessageDetail = details || '';
742
+ }
743
+ if (!!nextStepStatus && ['failed'].includes(nextStepStatus)) {
744
+ var _getRelatedWalletOrNu;
745
+ //if user cancel the swap, we should pass relevant reason to the server.
746
+ var errorReason = details && details.includes('Warning') ? 'Swap canceled by user.' : details;
747
+ var walletType = (_getRelatedWalletOrNu = getRelatedWalletOrNull(swap, currentStep)) == null ? void 0 : _getRelatedWalletOrNu.walletType;
748
+ swap.extraMessageSeverity = exports.MessageSeverity.error;
749
+ httpService.reportFailure({
750
+ requestId: swap.requestId,
751
+ step: (currentStep == null ? void 0 : currentStep.id) || 1,
752
+ eventType: mapAppErrorCodesToAPIErrorCode(errorCode),
753
+ reason: errorReason || '',
754
+ data: walletType ? {
755
+ wallet: walletType
756
+ } : undefined
757
+ }).then()["catch"]();
758
+ } else if (!!nextStepStatus && ['running'].includes(nextStepStatus)) swap.extraMessageSeverity = exports.MessageSeverity.info;else if (!!nextStepStatus && ['success', 'approved'].includes(nextStepStatus)) swap.extraMessageSeverity = exports.MessageSeverity.success;else if (nextStepStatus && ['waitingForApproval'].includes(nextStepStatus)) swap.extraMessageSeverity = exports.MessageSeverity.warning;
759
+ if (nextStepStatus === 'running' && currentStep) currentStep.startTransactionTime = new Date().getTime();
760
+ setStorage(_extends({}, getStorage(), {
761
+ swapDetails: swap
762
+ }));
763
+ return {
764
+ swap: swap,
765
+ step: currentStep
766
+ };
767
+ }
768
+ function setStepTransactionIds(_ref2, txId, notifier, eventType, approveUrl) {
769
+ var getStorage = _ref2.getStorage,
770
+ setStorage = _ref2.setStorage;
771
+ var swap = getStorage().swapDetails;
772
+ swap.hasAlreadyProceededToSign = null;
773
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
774
+ var currentStep = getCurrentStep(swap);
775
+ currentStep.executedTransactionId = txId;
776
+ currentStep.executedTransactionTime = new Date().getTime().toString();
777
+ if (!!approveUrl) currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
778
+ url: approveUrl,
779
+ description: "approve"
780
+ }]);
781
+ if (eventType === 'check_tx_status') {
782
+ swap.extraMessage = 'Checking transaction status ...';
783
+ swap.extraMessageDetail = '';
784
+ swap.extraMessageSeverity = exports.MessageSeverity.info;
785
+ } else if (eventType === 'check_approve_tx_status') {
786
+ swap.extraMessage = 'Checking approve transaction status ...';
787
+ swap.extraMessageDetail = '';
788
+ swap.extraMessageSeverity = exports.MessageSeverity.info;
789
+ }
790
+ setStorage(_extends({}, getStorage(), {
791
+ swapDetails: swap
792
+ }));
793
+ if (!!eventType) notifier({
794
+ eventType: eventType,
795
+ swap: swap,
796
+ step: currentStep
797
+ });
798
+ }
799
+ function getSwapNotitfication(eventType, updateResult) {
800
+ if (updateResult.swap.hasAlreadyProceededToSign) {
801
+ return _extends({
802
+ eventType: 'transaction_expired'
803
+ }, updateResult);
804
+ } else return _extends({
805
+ eventType: eventType
806
+ }, updateResult);
807
+ }
808
+ /**
809
+ * If a swap needs a wallet to be connected,
810
+ * By calling this function some related fields will be updated to show a correct message and state for notfiying the user.
811
+ */
812
+ function markRunningSwapAsWaitingForConnectingWallet(_ref3, reason, reasonDetail) {
813
+ var getStorage = _ref3.getStorage,
814
+ setStorage = _ref3.setStorage;
815
+ var swap = getStorage().swapDetails;
816
+ var currentStep = getCurrentStep(swap);
817
+ if (!currentStep) return;
818
+ var currentTime = new Date();
819
+ swap.lastNotificationTime = currentTime.getTime().toString();
820
+ var isAlreadyMarked = currentStep.networkStatus === exports.PendingSwapNetworkStatus.WaitingForConnectingWallet && swap.networkStatusExtraMessage === reason && swap.networkStatusExtraMessageDetail === reasonDetail;
821
+ if (isAlreadyMarked) {
822
+ return;
823
+ }
824
+ currentStep.networkStatus = exports.PendingSwapNetworkStatus.WaitingForConnectingWallet;
825
+ swap.networkStatusExtraMessage = reason;
826
+ swap.networkStatusExtraMessageDetail = reasonDetail;
827
+ setStorage(_extends({}, getStorage(), {
828
+ swapDetails: swap
829
+ }));
830
+ }
831
+ /**
832
+ * If a swap needs a certain network to proceed,
833
+ * By calling this function some related fields will be updated to show a correct message and state for notfiying the user.
834
+ */
835
+ function markRunningSwapAsSwitchingNetwork(_ref4) {
836
+ var getStorage = _ref4.getStorage,
837
+ setStorage = _ref4.setStorage;
838
+ var swap = getStorage().swapDetails;
839
+ var currentStep = getCurrentStep(swap);
840
+ if (!currentStep) return;
841
+ // Generate message
842
+ var _getRequiredWallet = getRequiredWallet(swap),
843
+ type = _getRequiredWallet.type;
844
+ var fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
845
+ var reason = "Change " + type + " wallet network to " + fromBlockchain;
846
+ var metamaskMessage = '';
847
+ if (type === walletsShared.WalletType.META_MASK) metamaskMessage = "(Networks -> Select '" + fromBlockchain + "' network.)";
848
+ var reasonDetail = "Please change your " + type + " wallet network to " + fromBlockchain + ". " + metamaskMessage;
849
+ var currentTime = new Date();
850
+ swap.lastNotificationTime = currentTime.getTime().toString();
851
+ currentStep.networkStatus = exports.PendingSwapNetworkStatus.WaitingForNetworkChange;
852
+ swap.networkStatusExtraMessage = reason;
853
+ swap.networkStatusExtraMessageDetail = reasonDetail;
854
+ setStorage(_extends({}, getStorage(), {
855
+ swapDetails: swap
856
+ }));
857
+ return {
858
+ swap: swap,
859
+ step: currentStep
860
+ };
861
+ }
862
+ /**
863
+ * We are marking the queue as it depends on other queues to be run (on Parallel mode)
864
+ * By calling this function some related fields will be updated to show a correct message and state for notfiying the user.
865
+ */
866
+ function markRunningSwapAsDependsOnOtherQueues(_ref5) {
867
+ var getStorage = _ref5.getStorage,
868
+ setStorage = _ref5.setStorage,
869
+ notifier = _ref5.notifier;
870
+ var swap = getStorage().swapDetails;
871
+ var currentStep = getCurrentStep(swap);
872
+ if (!currentStep) return;
873
+ swap.networkStatusExtraMessage = '';
874
+ swap.networkStatusExtraMessageDetail = '';
875
+ currentStep.networkStatus = exports.PendingSwapNetworkStatus.WaitingForQueue;
876
+ notifier({
877
+ eventType: 'waiting_for_queue',
878
+ swap: swap,
879
+ step: currentStep
880
+ });
881
+ setStorage(_extends({}, getStorage(), {
882
+ swapDetails: swap
883
+ }));
884
+ return {
885
+ swap: swap,
886
+ step: currentStep
887
+ };
888
+ }
889
+ function delay(ms) {
890
+ return new Promise(function (res) {
891
+ return setTimeout(res, ms);
892
+ });
893
+ }
894
+ var isEvmTransaction = function isEvmTransaction(tx) {
895
+ return tx.type === rangoSdk.TransactionType.EVM;
896
+ };
897
+ var isCosmosTransaction = function isCosmosTransaction(tx) {
898
+ return tx.type === rangoSdk.TransactionType.COSMOS;
899
+ };
900
+ var isSolanaTransaction = function isSolanaTransaction(tx) {
901
+ return tx.type === rangoSdk.TransactionType.SOLANA;
902
+ };
903
+ var isTrasnferTransaction = function isTrasnferTransaction(tx) {
904
+ return tx.type === rangoSdk.TransactionType.TRANSFER;
905
+ };
906
+ var isStarknetTransaction = function isStarknetTransaction(tx) {
907
+ return tx.type === rangoSdk.TransactionType.STARKNET;
908
+ };
909
+ var isTronTransaction = function isTronTransaction(tx) {
910
+ return tx.type === rangoSdk.TransactionType.TRON;
911
+ };
912
+ /**
913
+ *
914
+ * To execute a swap, we are keeping the user prefrences on what wallet they are going to use for a sepecific blockchain
915
+ * By passing the swap and the network we are looking for, it returns the wallet name that user selected.
916
+ *
917
+ */
918
+ var getSwapWalletType = function getSwapWalletType(swap, network) {
919
+ var _swap$wallets$network;
920
+ return (_swap$wallets$network = swap.wallets[network]) == null ? void 0 : _swap$wallets$network.walletType;
921
+ };
922
+ /**
923
+ *
924
+ * We are keeping the connected wallet in a specific structure (`Wallet`),
925
+ * By using this function we normally want to check a specific wallet is connected and exists or not.
926
+ *
927
+ */
928
+ function isWalletNull(wallet) {
929
+ return wallet === null || (wallet == null ? void 0 : wallet.blockchains) === null || (wallet == null ? void 0 : wallet.blockchains.length) === 0;
930
+ }
931
+ /**
932
+ * On our implementation for `wallets` package, We keep the instance in 2 ways
933
+ * If it's a single chain wallet, it returns the instance directly,
934
+ * If it's a multichain wallet, it returns a `Map` of instances.
935
+ * This function will get the `ETHEREUM` instance in both types.
936
+ */
937
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
938
+ function getEvmProvider(providers, type) {
939
+ if (type && providers[type]) {
940
+ // we need this because provider can return an instance or a map of instances, so what you are doing here is try to detect that.
941
+ if (providers[type].size) return providers[type].get(walletsShared.Network.ETHEREUM);
942
+ return providers[type];
943
+ }
944
+ return null;
945
+ }
946
+ /**
947
+ * In a `PendingSwap`, each step needs a wallet to proceed,
948
+ * By using this function we can access what wallet exactly we need to run current step.
949
+ */
950
+ function getRequiredWallet(swap) {
951
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
952
+ var step = getCurrentStep(swap);
953
+ var bcName = getCurrentBlockchainOfOrNull(swap, step);
954
+ if (!bcName) {
955
+ return {
956
+ type: null,
957
+ network: null,
958
+ address: null
959
+ };
960
+ }
961
+ var walletType = getSwapWalletType(swap, bcName);
962
+ var sourceWallet = swap.wallets[bcName];
963
+ return {
964
+ type: walletType || null,
965
+ network: bcName,
966
+ address: sourceWallet ? sourceWallet.address : null
967
+ };
968
+ }
969
+ /**
970
+ * On EVM compatible wallets, There is one instance with different chains (like Polygon)
971
+ * To get the chain from instance we will use this function.
972
+ */
973
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
974
+ function getChainId(_x) {
975
+ return _getChainId.apply(this, arguments);
976
+ }
977
+ /**
978
+ * For running a swap safely, we need to make sure about the state of wallet
979
+ * which means the netowrk/chain of wallet should be exactly on what a transaction needs.
980
+ */
981
+ function _getChainId() {
982
+ _getChainId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(provider) {
983
+ var chainId;
984
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
985
+ while (1) switch (_context.prev = _context.next) {
986
+ case 0:
987
+ _context.next = 2;
988
+ return provider.request({
989
+ method: 'eth_chainId'
990
+ });
991
+ case 2:
992
+ _context.t0 = _context.sent;
993
+ if (_context.t0) {
994
+ _context.next = 5;
995
+ break;
996
+ }
997
+ _context.t0 = provider == null ? void 0 : provider.chainId;
998
+ case 5:
999
+ chainId = _context.t0;
1000
+ return _context.abrupt("return", chainId);
1001
+ case 7:
1002
+ case "end":
1003
+ return _context.stop();
1004
+ }
1005
+ }, _callee);
1006
+ }));
1007
+ return _getChainId.apply(this, arguments);
1008
+ }
1009
+ function isNetworkMatchedForTransaction(_x2, _x3, _x4, _x5, _x6) {
1010
+ return _isNetworkMatchedForTransaction.apply(this, arguments);
1011
+ }
1012
+ function _isNetworkMatchedForTransaction() {
1013
+ _isNetworkMatchedForTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(swap, step, wallet, meta, providers) {
1014
+ var fromBlockChain, sourceWallet, provider, chainId, blockChain;
1015
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1016
+ while (1) switch (_context2.prev = _context2.next) {
1017
+ case 0:
1018
+ if (!isWalletNull(wallet)) {
1019
+ _context2.next = 3;
1020
+ break;
1021
+ }
1022
+ console.warn('wallet object is null');
1023
+ return _context2.abrupt("return", false);
1024
+ case 3:
1025
+ fromBlockChain = getCurrentBlockchainOfOrNull(swap, step);
1026
+ if (fromBlockChain) {
1027
+ _context2.next = 6;
1028
+ break;
1029
+ }
1030
+ return _context2.abrupt("return", false);
1031
+ case 6:
1032
+ if (!meta.evmBasedChains.find(function (evmBlochain) {
1033
+ return evmBlochain.name === fromBlockChain;
1034
+ })) {
1035
+ _context2.next = 30;
1036
+ break;
1037
+ }
1038
+ _context2.prev = 7;
1039
+ sourceWallet = swap.wallets[fromBlockChain];
1040
+ if (!sourceWallet) {
1041
+ _context2.next = 24;
1042
+ break;
1043
+ }
1044
+ if (![walletsShared.WalletType.META_MASK, walletsShared.WalletType.BINANCE_CHAIN, walletsShared.WalletType.XDEFI, walletsShared.WalletType.WALLET_CONNECT, walletsShared.WalletType.TRUST_WALLET, walletsShared.WalletType.COIN98, walletsShared.WalletType.EXODUS, walletsShared.WalletType.OKX, walletsShared.WalletType.COINBASE, walletsShared.WalletType.TOKEN_POCKET, walletsShared.WalletType.MATH, walletsShared.WalletType.SAFEPAL, walletsShared.WalletType.COSMOSTATION, walletsShared.WalletType.CLOVER, walletsShared.WalletType.BRAVE, walletsShared.WalletType.FRONTIER, walletsShared.WalletType.KUCOIN].includes(sourceWallet.walletType)) {
1045
+ _context2.next = 23;
1046
+ break;
1047
+ }
1048
+ provider = getEvmProvider(providers, sourceWallet.walletType);
1049
+ _context2.next = 14;
1050
+ return getChainId(provider);
1051
+ case 14:
1052
+ chainId = _context2.sent;
1053
+ if (!chainId) {
1054
+ _context2.next = 21;
1055
+ break;
1056
+ }
1057
+ blockChain = walletsShared.getBlockChainNameFromId(chainId, Object.entries(meta.blockchains).map(function (_ref6) {
1058
+ var blockchainMeta = _ref6[1];
1059
+ return blockchainMeta;
1060
+ }));
1061
+ if (!(blockChain && blockChain.toLowerCase() === fromBlockChain.toLowerCase())) {
1062
+ _context2.next = 19;
1063
+ break;
1064
+ }
1065
+ return _context2.abrupt("return", true);
1066
+ case 19:
1067
+ if (!(blockChain && blockChain.toLowerCase() !== fromBlockChain.toLowerCase())) {
1068
+ _context2.next = 21;
1069
+ break;
1070
+ }
1071
+ return _context2.abrupt("return", false);
1072
+ case 21:
1073
+ _context2.next = 24;
1074
+ break;
1075
+ case 23:
1076
+ return _context2.abrupt("return", true);
1077
+ case 24:
1078
+ _context2.next = 29;
1079
+ break;
1080
+ case 26:
1081
+ _context2.prev = 26;
1082
+ _context2.t0 = _context2["catch"](7);
1083
+ console.log(_context2.t0);
1084
+ case 29:
1085
+ return _context2.abrupt("return", false);
1086
+ case 30:
1087
+ return _context2.abrupt("return", true);
1088
+ case 31:
1089
+ case "end":
1090
+ return _context2.stop();
1091
+ }
1092
+ }, _callee2, null, [[7, 26]]);
1093
+ }));
1094
+ return _isNetworkMatchedForTransaction.apply(this, arguments);
1095
+ }
1096
+ var isTxAlreadyCreated = function isTxAlreadyCreated(swap, step) {
1097
+ var _step$evmTransaction, _step$evmApprovalTran, _step$tronTransaction, _step$tronApprovalTra, _step$starknetTransac, _step$starknetApprova, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac;
1098
+ var result = swap.wallets[((_step$evmTransaction = step.evmTransaction) == null ? void 0 : _step$evmTransaction.blockChain) || ''] || swap.wallets[((_step$evmApprovalTran = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran.blockChain) || ''] || swap.wallets[((_step$tronTransaction = step.tronTransaction) == null ? void 0 : _step$tronTransaction.blockChain) || ''] || swap.wallets[((_step$tronApprovalTra = step.tronApprovalTransaction) == null ? void 0 : _step$tronApprovalTra.blockChain) || ''] || swap.wallets[((_step$starknetTransac = step.starknetTransaction) == null ? void 0 : _step$starknetTransac.blockChain) || ''] || swap.wallets[((_step$starknetApprova = step.starknetApprovalTransaction) == null ? void 0 : _step$starknetApprova.blockChain) || ''] || swap.wallets[((_step$cosmosTransacti = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti.blockChain) || ''] || swap.wallets[((_step$solanaTransacti = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti.blockChain) || ''] || ((_step$transferTransac = step.transferTransaction) == null ? void 0 : _step$transferTransac.fromWalletAddress) || null;
1099
+ return result !== null;
1100
+ };
1101
+ function resetNetworkStatus(actions) {
1102
+ var getStorage = actions.getStorage,
1103
+ setStorage = actions.setStorage;
1104
+ var swap = getStorage().swapDetails;
1105
+ var currentStep = getCurrentStep(swap);
1106
+ if (currentStep != null && currentStep.networkStatus) {
1107
+ currentStep.networkStatus = null;
1108
+ setStorage(_extends({}, getStorage(), {
1109
+ swapDetails: swap
1110
+ }));
1111
+ }
1112
+ }
1113
+ function updateNetworkStatus(actions, data) {
1114
+ if (data === void 0) {
1115
+ data = {
1116
+ message: '',
1117
+ details: '',
1118
+ status: null
1119
+ };
1120
+ }
1121
+ var _data = data,
1122
+ message = _data.message,
1123
+ details = _data.details,
1124
+ status = _data.status;
1125
+ var getStorage = actions.getStorage,
1126
+ setStorage = actions.setStorage;
1127
+ var swap = getStorage().swapDetails;
1128
+ var currentStep = getCurrentStep(swap);
1129
+ if (currentStep != null && currentStep.networkStatus) {
1130
+ swap.networkStatusExtraMessage = message;
1131
+ swap.networkStatusExtraMessageDetail = details;
1132
+ currentStep.networkStatus = status;
1133
+ setStorage(_extends({}, getStorage(), {
1134
+ swapDetails: swap
1135
+ }));
1136
+ }
1137
+ }
1138
+ /**
1139
+ * Event handler for blocked tasks.
1140
+ * If a transcation execution is manually blocked (like for parallel or waiting for wallet),
1141
+ * This function will be called by queue manager using `queue definition`.
1142
+ *
1143
+ * It checks if the required wallet is connected, unblock the queue to be run.
1144
+ */
1145
+ function onBlockForConnectWallet(event, meta) {
1146
+ var context = meta.context,
1147
+ queue = meta.queue;
1148
+ var swap = queue.getStorage().swapDetails;
1149
+ var _isRequiredWalletConn = isRequiredWalletConnected(swap, context.state),
1150
+ ok = _isRequiredWalletConn.ok,
1151
+ reason = _isRequiredWalletConn.reason;
1152
+ if (!ok) {
1153
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1154
+ var currentStep = getCurrentStep(swap);
1155
+ context.notifier({
1156
+ eventType: reason === 'account_miss_match' ? 'waiting_for_change_wallet_account' : 'waiting_for_connecting_wallet',
1157
+ swap: swap,
1158
+ step: currentStep
1159
+ });
1160
+ markRunningSwapAsWaitingForConnectingWallet({
1161
+ getStorage: queue.getStorage.bind(queue),
1162
+ setStorage: queue.setStorage.bind(queue)
1163
+ }, ERROR_MESSAGE_WAIT_FOR_WALLET, event.reason.description);
1164
+ return;
1165
+ }
1166
+ queue.unblock();
1167
+ }
1168
+ /**
1169
+ * Event handler for blocked tasks.
1170
+ * If a transcation execution is manually blocked (like for parallel or waiting for walle),
1171
+ * This function will be called by queue manager using `queue definition`.
1172
+ *
1173
+ * It checks if the required network is connected, unblock the queue to be run.
1174
+ * Note: it automatically try to switch the network if its `provider` supports.
1175
+ */
1176
+ function onBlockForChangeNetwork(_event, meta) {
1177
+ var context = meta.context,
1178
+ queue = meta.queue;
1179
+ var swap = queue.getStorage().swapDetails;
1180
+ var currentStep = getCurrentStep(swap);
1181
+ if (!currentStep || swap.status !== 'running') return;
1182
+ var result = markRunningSwapAsSwitchingNetwork({
1183
+ getStorage: queue.getStorage.bind(queue),
1184
+ setStorage: queue.setStorage.bind(queue)
1185
+ });
1186
+ if (result) {
1187
+ context.notifier({
1188
+ eventType: 'waiting_for_network_change',
1189
+ swap: result.swap,
1190
+ step: result.step
1191
+ });
1192
+ }
1193
+ // Try to auto switch
1194
+ var _getRequiredWallet2 = getRequiredWallet(swap),
1195
+ type = _getRequiredWallet2.type,
1196
+ network = _getRequiredWallet2.network;
1197
+ if (!!type && !!network) {
1198
+ var _result = context.switchNetwork(type, network);
1199
+ if (_result) {
1200
+ _result.then(function () {
1201
+ queue.unblock();
1202
+ });
1203
+ }
1204
+ }
1205
+ }
1206
+ /**
1207
+ * Event handler for blocked tasks. (Parallel mode)
1208
+ * If a transcation execution flow is manually blocked (like for parallel or waiting for walle),
1209
+ * This function will be called by queue manager using `queue definition`.
1210
+ *
1211
+ * It checks the blocked tasks, if there is no active `claimed` queue, try to give it to the best candidate.
1212
+ */
1213
+ function onDependsOnOtherQueues(_event, meta) {
1214
+ var getBlockedTasks = meta.getBlockedTasks,
1215
+ forceExecute = meta.forceExecute,
1216
+ queue = meta.queue,
1217
+ manager = meta.manager,
1218
+ context = meta.context;
1219
+ var _claimQueue = claimQueue(),
1220
+ setClaimer = _claimQueue.setClaimer,
1221
+ claimedBy = _claimQueue.claimedBy,
1222
+ reset = _claimQueue.reset;
1223
+ // We only needs those blocked tasks that have DEPENDS_ON_OTHER_QUEUES reason.
1224
+ var blockedTasks = getBlockedTasks().filter(function (task) {
1225
+ return task.reason.reason === BlockReason.DEPENDS_ON_OTHER_QUEUES;
1226
+ });
1227
+ if (blockedTasks.length === 0) {
1228
+ return;
1229
+ }
1230
+ var claimerId = claimedBy();
1231
+ var isClaimedByAnyQueue = !!claimerId;
1232
+ // Check if any queue `claimed` before, if yes, we don't should do anything.
1233
+ if (isClaimedByAnyQueue) {
1234
+ // We need to keep the latest swap messages
1235
+ markRunningSwapAsDependsOnOtherQueues({
1236
+ getStorage: queue.getStorage.bind(queue),
1237
+ setStorage: queue.setStorage.bind(queue),
1238
+ notifier: context.notifier
1239
+ });
1240
+ return;
1241
+ }
1242
+ // Prioritize current queue to be run first.
1243
+ var task = blockedTasks.find(function (task) {
1244
+ return task.queue_id === meta.queue_id;
1245
+ });
1246
+ // If current task isn't available anymore, fallback to first blocked task.
1247
+ if (!task) {
1248
+ var firstBlockedTask = blockedTasks[0];
1249
+ task = firstBlockedTask;
1250
+ }
1251
+ setClaimer(task.queue_id);
1252
+ var claimedStorage = task.storage.get();
1253
+ var _getRequiredWallet3 = getRequiredWallet(claimedStorage.swapDetails),
1254
+ type = _getRequiredWallet3.type,
1255
+ network = _getRequiredWallet3.network,
1256
+ address = _getRequiredWallet3.address;
1257
+ // Run
1258
+ forceExecute(task.queue_id, {
1259
+ claimedBy: claimedBy(),
1260
+ resetClaimedBy: function resetClaimedBy() {
1261
+ reset();
1262
+ // TODO: Use key generator
1263
+ retryOn(type + "-" + network + "-" + address, context.notifier, manager);
1264
+ }
1265
+ });
1266
+ }
1267
+ function isRequiredWalletConnected(swap, getState) {
1268
+ var _getRequiredWallet4 = getRequiredWallet(swap),
1269
+ type = _getRequiredWallet4.type,
1270
+ address = _getRequiredWallet4.address;
1271
+ if (!type || !address) {
1272
+ return {
1273
+ ok: false,
1274
+ reason: 'not_connected'
1275
+ };
1276
+ }
1277
+ var walletState = getState(type);
1278
+ var accounts = walletState.accounts,
1279
+ connected = walletState.connected;
1280
+ var connectedAccounts = accounts || [];
1281
+ if (!connected) return {
1282
+ ok: false,
1283
+ reason: 'not_connected'
1284
+ };
1285
+ var matched = connectedAccounts.some(function (account) {
1286
+ var _readAccountAddress = walletsCore.readAccountAddress(account),
1287
+ accountAddress = _readAccountAddress.address;
1288
+ return address === accountAddress;
1289
+ });
1290
+ return {
1291
+ ok: matched,
1292
+ reason: 'account_miss_match'
1293
+ };
1294
+ }
1295
+ function singTransaction(actions) {
1296
+ var getStorage = actions.getStorage,
1297
+ setStorage = actions.setStorage,
1298
+ failed = actions.failed,
1299
+ next = actions.next,
1300
+ schedule = actions.schedule,
1301
+ context = actions.context;
1302
+ var meta = context.meta,
1303
+ getSigners = context.getSigners,
1304
+ notifier = context.notifier;
1305
+ var swap = getStorage().swapDetails;
1306
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1307
+ var currentStep = getCurrentStep(swap);
1308
+ var evmTransaction = currentStep.evmTransaction,
1309
+ evmApprovalTransaction = currentStep.evmApprovalTransaction,
1310
+ cosmosTransaction = currentStep.cosmosTransaction,
1311
+ solanaTransaction = currentStep.solanaTransaction,
1312
+ transferTransaction = currentStep.transferTransaction,
1313
+ tronTransaction = currentStep.tronTransaction,
1314
+ tronApprovalTransaction = currentStep.tronApprovalTransaction,
1315
+ starknetTransaction = currentStep.starknetTransaction,
1316
+ starknetApprovalTransaction = currentStep.starknetApprovalTransaction;
1317
+ var sourceWallet = getRelatedWallet(swap, currentStep);
1318
+ var walletAddress = getCurrentAddressOf(swap, currentStep);
1319
+ var walletSigners = getSigners(sourceWallet.walletType);
1320
+ var onFinish = function onFinish() {
1321
+ // TODO resetClaimedBy is undefined here
1322
+ if (actions.context.resetClaimedBy) {
1323
+ actions.context.resetClaimedBy();
1324
+ }
1325
+ };
1326
+ if (!!evmApprovalTransaction) {
1327
+ var spenderContract = evmApprovalTransaction == null ? void 0 : evmApprovalTransaction.to;
1328
+ if (!spenderContract) throw PrettyError.AssertionFailed('contract address is null for checking approval');
1329
+ // Update swap status
1330
+ var message = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
1331
+ var updateResult = updateSwapStatus({
1332
+ getStorage: getStorage,
1333
+ setStorage: setStorage,
1334
+ nextStepStatus: 'waitingForApproval',
1335
+ message: message,
1336
+ details: 'Waiting for approve transaction to be mined and confirmed successfully'
1337
+ });
1338
+ notifier(_extends({
1339
+ eventType: 'confirm_approve_contract'
1340
+ }, updateResult));
1341
+ // Execute transaction
1342
+ walletSigners.getSigner(rangoSdk.TransactionType.EVM).signAndSendTx(evmApprovalTransaction, walletAddress, null).then(function (hash) {
1343
+ console.debug('transaction of approval minted successfully', hash);
1344
+ var approveUrl = getEvmApproveUrl(hash, getCurrentBlockchainOf(swap, currentStep), meta.evmBasedChains);
1345
+ setStepTransactionIds(actions, hash, notifier, 'check_approve_tx_status', approveUrl);
1346
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1347
+ next();
1348
+ onFinish();
1349
+ }, function (error) {
1350
+ var _error$root, _error$root2, _error$root3;
1351
+ if (swap.status === 'failed') return;
1352
+ console.debug('error in approving', error);
1353
+ var _prettifyErrorMessage = prettifyErrorMessage(error),
1354
+ extraMessage = _prettifyErrorMessage.extraMessage,
1355
+ extraMessageDetail = _prettifyErrorMessage.extraMessageDetail,
1356
+ extraMessageErrorCode = _prettifyErrorMessage.extraMessageErrorCode;
1357
+ if (error && error != null && error.root && error != null && (_error$root = error.root) != null && _error$root.message && error != null && (_error$root2 = error.root) != null && _error$root2.code && error != null && (_error$root3 = error.root) != null && _error$root3.reason) {
1358
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1359
+ }
1360
+ var updateResult = updateSwapStatus({
1361
+ getStorage: getStorage,
1362
+ setStorage: setStorage,
1363
+ nextStatus: 'failed',
1364
+ nextStepStatus: 'failed',
1365
+ message: extraMessage,
1366
+ details: extraMessageDetail,
1367
+ errorCode: extraMessageErrorCode
1368
+ });
1369
+ notifier(_extends({
1370
+ eventType: 'contract_rejected'
1371
+ }, updateResult));
1372
+ failed();
1373
+ onFinish();
1374
+ });
1375
+ return;
1376
+ } else if (!!tronApprovalTransaction) {
1377
+ // Update swap status
1378
+ var _message = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
1379
+ var _updateResult = updateSwapStatus({
1380
+ getStorage: getStorage,
1381
+ setStorage: setStorage,
1382
+ nextStepStatus: 'waitingForApproval',
1383
+ message: _message,
1384
+ details: 'Waiting for approve transaction to be mined and confirmed successfully'
1385
+ });
1386
+ notifier(_extends({
1387
+ eventType: 'confirm_approve_contract'
1388
+ }, _updateResult));
1389
+ // Execute transaction
1390
+ walletSigners.getSigner(rangoSdk.TransactionType.TRON).signAndSendTx(tronApprovalTransaction, walletAddress, null).then(function (hash) {
1391
+ console.debug('transaction of approval minted successfully', hash);
1392
+ var approveUrl = getTronApproveUrl(hash);
1393
+ setStepTransactionIds(actions, hash, notifier, 'check_approve_tx_status', approveUrl);
1394
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1395
+ next();
1396
+ onFinish();
1397
+ }, function (error) {
1398
+ var _error$root4, _error$root5, _error$root6;
1399
+ if (swap.status === 'failed') return;
1400
+ console.debug('error in approving', error);
1401
+ var _prettifyErrorMessage2 = prettifyErrorMessage(error),
1402
+ extraMessage = _prettifyErrorMessage2.extraMessage,
1403
+ extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail,
1404
+ extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
1405
+ if (error && error != null && error.root && error != null && (_error$root4 = error.root) != null && _error$root4.message && error != null && (_error$root5 = error.root) != null && _error$root5.code && error != null && (_error$root6 = error.root) != null && _error$root6.reason) {
1406
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1407
+ }
1408
+ var updateResult = updateSwapStatus({
1409
+ getStorage: getStorage,
1410
+ setStorage: setStorage,
1411
+ nextStatus: 'failed',
1412
+ nextStepStatus: 'failed',
1413
+ message: extraMessage,
1414
+ details: extraMessageDetail,
1415
+ errorCode: extraMessageErrorCode
1416
+ });
1417
+ notifier(_extends({
1418
+ eventType: 'contract_rejected'
1419
+ }, updateResult));
1420
+ failed();
1421
+ onFinish();
1422
+ });
1423
+ return;
1424
+ } else if (!!starknetApprovalTransaction) {
1425
+ // Update swap status
1426
+ var _message2 = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
1427
+ var _updateResult2 = updateSwapStatus({
1428
+ getStorage: getStorage,
1429
+ setStorage: setStorage,
1430
+ nextStepStatus: 'waitingForApproval',
1431
+ message: _message2,
1432
+ details: 'Waiting for approve transaction to be mined and confirmed successfully'
1433
+ });
1434
+ notifier(_extends({
1435
+ eventType: 'confirm_approve_contract'
1436
+ }, _updateResult2));
1437
+ // Execute transaction
1438
+ walletSigners.getSigner(rangoSdk.TransactionType.STARKNET).signAndSendTx(starknetApprovalTransaction, walletAddress, null).then(function (hash) {
1439
+ console.debug('transaction of approval minted successfully', hash);
1440
+ var approveUrl = getStarknetApproveUrl(hash);
1441
+ setStepTransactionIds(actions, hash, notifier, 'check_approve_tx_status', approveUrl);
1442
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1443
+ next();
1444
+ onFinish();
1445
+ }, function (error) {
1446
+ var _error$root7, _error$root8, _error$root9;
1447
+ if (swap.status === 'failed') return;
1448
+ console.debug('error in approving', error);
1449
+ var _prettifyErrorMessage3 = prettifyErrorMessage(error),
1450
+ extraMessage = _prettifyErrorMessage3.extraMessage,
1451
+ extraMessageDetail = _prettifyErrorMessage3.extraMessageDetail,
1452
+ extraMessageErrorCode = _prettifyErrorMessage3.extraMessageErrorCode;
1453
+ if (error && error != null && error.root && error != null && (_error$root7 = error.root) != null && _error$root7.message && error != null && (_error$root8 = error.root) != null && _error$root8.code && error != null && (_error$root9 = error.root) != null && _error$root9.reason) {
1454
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1455
+ }
1456
+ var updateResult = updateSwapStatus({
1457
+ getStorage: getStorage,
1458
+ setStorage: setStorage,
1459
+ nextStatus: 'failed',
1460
+ nextStepStatus: 'failed',
1461
+ message: extraMessage,
1462
+ details: extraMessageDetail,
1463
+ errorCode: extraMessageErrorCode
1464
+ });
1465
+ notifier(_extends({
1466
+ eventType: 'contract_rejected'
1467
+ }, updateResult));
1468
+ failed();
1469
+ onFinish();
1470
+ });
1471
+ return;
1472
+ }
1473
+ var hasAlreadyProceededToSign = typeof swap.hasAlreadyProceededToSign === 'boolean';
1474
+ var nextStepStatusBasedOnHasAlreadyProceededToSign = hasAlreadyProceededToSign ? 'failed' : 'running';
1475
+ var errorCodeBasedOnHasAlreadyProceededToSign = hasAlreadyProceededToSign ? 'TX_EXPIRED' : null;
1476
+ var executeMessage = hasAlreadyProceededToSign ? 'Transaction is expired. Please try again' : 'executing transaction';
1477
+ var executeDetails = "" + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'Check your mobile phone' : '');
1478
+ if (!!transferTransaction) {
1479
+ var _updateResult3 = updateSwapStatus({
1480
+ getStorage: getStorage,
1481
+ setStorage: setStorage,
1482
+ nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1483
+ nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1484
+ message: executeMessage,
1485
+ details: executeDetails,
1486
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1487
+ errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1488
+ });
1489
+ var notification = getSwapNotitfication('confirm_transfer', _updateResult3);
1490
+ notifier(notification);
1491
+ if (notification.eventType === 'transaction_expired') {
1492
+ failed();
1493
+ onFinish();
1494
+ } else {
1495
+ walletSigners.getSigner(rangoSdk.TransactionType.TRANSFER).signAndSendTx(transferTransaction, walletAddress, null).then(function (txId) {
1496
+ setStepTransactionIds(actions, txId, notifier, 'check_tx_status');
1497
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1498
+ next();
1499
+ onFinish();
1500
+ }, function (error) {
1501
+ if (swap.status === 'failed') return;
1502
+ var _prettifyErrorMessage4 = prettifyErrorMessage(error),
1503
+ extraMessage = _prettifyErrorMessage4.extraMessage,
1504
+ extraMessageDetail = _prettifyErrorMessage4.extraMessageDetail,
1505
+ extraMessageErrorCode = _prettifyErrorMessage4.extraMessageErrorCode;
1506
+ var updateResult = updateSwapStatus({
1507
+ getStorage: getStorage,
1508
+ setStorage: setStorage,
1509
+ nextStatus: 'failed',
1510
+ nextStepStatus: 'failed',
1511
+ message: extraMessage,
1512
+ details: extraMessageDetail,
1513
+ errorCode: extraMessageErrorCode
1514
+ });
1515
+ notifier(_extends({
1516
+ eventType: 'transfer_rejected'
1517
+ }, updateResult));
1518
+ failed();
1519
+ onFinish();
1520
+ });
1521
+ }
1522
+ } else if (!!evmTransaction) {
1523
+ var _updateResult4 = updateSwapStatus({
1524
+ getStorage: getStorage,
1525
+ setStorage: setStorage,
1526
+ nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1527
+ nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1528
+ message: executeMessage,
1529
+ details: executeDetails,
1530
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1531
+ errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1532
+ });
1533
+ var _notification = getSwapNotitfication('calling_smart_contract', _updateResult4);
1534
+ notifier(_notification);
1535
+ if (_notification.eventType === 'transaction_expired') {
1536
+ failed();
1537
+ onFinish();
1538
+ } else {
1539
+ walletSigners.getSigner(rangoSdk.TransactionType.EVM).signAndSendTx(evmTransaction, walletAddress, null).then(function (id) {
1540
+ setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1541
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1542
+ next();
1543
+ onFinish();
1544
+ }, function (error) {
1545
+ var _error$root10, _error$root11, _error$root12;
1546
+ if (swap.status === 'failed') return;
1547
+ var _prettifyErrorMessage5 = prettifyErrorMessage(error),
1548
+ extraMessage = _prettifyErrorMessage5.extraMessage,
1549
+ extraMessageDetail = _prettifyErrorMessage5.extraMessageDetail,
1550
+ extraMessageErrorCode = _prettifyErrorMessage5.extraMessageErrorCode;
1551
+ if (error && error != null && error.root && error != null && (_error$root10 = error.root) != null && _error$root10.message && error != null && (_error$root11 = error.root) != null && _error$root11.code && error != null && (_error$root12 = error.root) != null && _error$root12.reason) {
1552
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1553
+ }
1554
+ var updateResult = updateSwapStatus({
1555
+ getStorage: getStorage,
1556
+ setStorage: setStorage,
1557
+ nextStatus: 'failed',
1558
+ nextStepStatus: 'failed',
1559
+ message: extraMessage,
1560
+ details: extraMessageDetail,
1561
+ errorCode: extraMessageErrorCode
1562
+ });
1563
+ notifier(_extends({
1564
+ eventType: 'smart_contract_call_failed'
1565
+ }, updateResult));
1566
+ failed();
1567
+ onFinish();
1568
+ });
1569
+ }
1570
+ } else if (!!cosmosTransaction) {
1571
+ var _updateResult5 = updateSwapStatus({
1572
+ getStorage: getStorage,
1573
+ setStorage: setStorage,
1574
+ nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1575
+ nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1576
+ message: executeMessage,
1577
+ details: executeDetails,
1578
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1579
+ errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1580
+ });
1581
+ var _notification2 = getSwapNotitfication('calling_smart_contract', _updateResult5);
1582
+ notifier(_notification2);
1583
+ if (_notification2.eventType === 'transaction_expired') {
1584
+ failed();
1585
+ onFinish();
1586
+ } else {
1587
+ // If keplr wallet is executing contracts on terra, throw error. keplr doesn't support transfer or execute contracts. only IBC messages are supported
1588
+ if (((currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'TerraSwap' || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'ThorChain' && (currentStep == null ? void 0 : currentStep.fromBlockchain) === walletsShared.Network.TERRA || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'Terra Bridge' && currentStep.fromBlockchain === walletsShared.Network.TERRA) &&
1589
+ // here we must allow ibc on terrastatus
1590
+ sourceWallet.walletType === walletsShared.WalletType.KEPLR) {
1591
+ var _prettifyErrorMessage6 = prettifyErrorMessage('Keplr only supports IBC Transactions on Terra. ' + 'Using Terra Bridge, TerraSwap and THORChain is not possible with Keplr. Please use TerraStation or Leap wallet'),
1592
+ extraMessage = _prettifyErrorMessage6.extraMessage,
1593
+ extraMessageDetail = _prettifyErrorMessage6.extraMessageDetail,
1594
+ extraMessageErrorCode = _prettifyErrorMessage6.extraMessageErrorCode;
1595
+ var _updateResult6 = updateSwapStatus({
1596
+ getStorage: getStorage,
1597
+ setStorage: setStorage,
1598
+ nextStatus: 'failed',
1599
+ nextStepStatus: 'failed',
1600
+ message: extraMessage,
1601
+ details: extraMessageDetail,
1602
+ errorCode: extraMessageErrorCode
1603
+ });
1604
+ notifier(_extends({
1605
+ eventType: 'smart_contract_call_failed'
1606
+ }, _updateResult6));
1607
+ failed();
1608
+ onFinish();
1609
+ return;
1610
+ }
1611
+ walletSigners.getSigner(rangoSdk.TransactionType.COSMOS).signAndSendTx(cosmosTransaction, walletAddress, null).then(
1612
+ // todo
1613
+ function (id) {
1614
+ setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1615
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1616
+ next();
1617
+ onFinish();
1618
+ }, function (error) {
1619
+ if (swap.status === 'failed') return;
1620
+ var _prettifyErrorMessage7 = prettifyErrorMessage(error),
1621
+ extraMessage = _prettifyErrorMessage7.extraMessage,
1622
+ extraMessageDetail = _prettifyErrorMessage7.extraMessageDetail,
1623
+ extraMessageErrorCode = _prettifyErrorMessage7.extraMessageErrorCode;
1624
+ var updateResult = updateSwapStatus({
1625
+ getStorage: getStorage,
1626
+ setStorage: setStorage,
1627
+ nextStatus: 'failed',
1628
+ nextStepStatus: 'failed',
1629
+ message: extraMessage,
1630
+ details: extraMessageDetail,
1631
+ errorCode: extraMessageErrorCode
1632
+ });
1633
+ notifier(_extends({
1634
+ eventType: 'smart_contract_call_failed'
1635
+ }, updateResult));
1636
+ failed();
1637
+ onFinish();
1638
+ });
1639
+ }
1640
+ } else if (!!solanaTransaction) {
1641
+ var _updateResult7 = updateSwapStatus({
1642
+ getStorage: getStorage,
1643
+ setStorage: setStorage,
1644
+ nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1645
+ nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1646
+ message: executeMessage,
1647
+ details: executeDetails,
1648
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1649
+ errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1650
+ });
1651
+ var _notification3 = getSwapNotitfication('calling_smart_contract', _updateResult7);
1652
+ notifier(_notification3);
1653
+ if (_notification3.eventType === 'transaction_expired') {
1654
+ failed();
1655
+ onFinish();
1656
+ } else {
1657
+ var tx = solanaTransaction;
1658
+ walletSigners.getSigner(rangoSdk.TransactionType.SOLANA).signAndSendTx(tx, walletAddress, null).then(function (txId) {
1659
+ setStepTransactionIds(actions, txId, notifier, 'check_tx_status');
1660
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1661
+ next();
1662
+ onFinish();
1663
+ }, function (error) {
1664
+ if (swap.status === 'failed') return;
1665
+ var _prettifyErrorMessage8 = prettifyErrorMessage(error),
1666
+ extraMessage = _prettifyErrorMessage8.extraMessage,
1667
+ extraMessageDetail = _prettifyErrorMessage8.extraMessageDetail,
1668
+ extraMessageErrorCode = _prettifyErrorMessage8.extraMessageErrorCode;
1669
+ var updateResult = updateSwapStatus({
1670
+ getStorage: getStorage,
1671
+ setStorage: setStorage,
1672
+ nextStatus: 'failed',
1673
+ nextStepStatus: 'failed',
1674
+ message: extraMessage,
1675
+ details: extraMessageDetail,
1676
+ errorCode: extraMessageErrorCode
1677
+ });
1678
+ notifier(_extends({
1679
+ eventType: 'smart_contract_call_failed'
1680
+ }, updateResult));
1681
+ failed();
1682
+ onFinish();
1683
+ });
1684
+ }
1685
+ } else if (!!tronTransaction) {
1686
+ var _updateResult8 = updateSwapStatus({
1687
+ getStorage: getStorage,
1688
+ setStorage: setStorage,
1689
+ nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1690
+ nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1691
+ message: executeMessage,
1692
+ details: executeDetails,
1693
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1694
+ errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1695
+ });
1696
+ var _notification4 = getSwapNotitfication('calling_smart_contract', _updateResult8);
1697
+ notifier(_notification4);
1698
+ if (_notification4.eventType === 'transaction_expired') {
1699
+ failed();
1700
+ onFinish();
1701
+ } else {
1702
+ walletSigners.getSigner(rangoSdk.TransactionType.TRON).signAndSendTx(tronTransaction, walletAddress, null).then(function (id) {
1703
+ setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1704
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1705
+ next();
1706
+ onFinish();
1707
+ }, function (error) {
1708
+ var _error$root13, _error$root14, _error$root15;
1709
+ if (swap.status === 'failed') return;
1710
+ var _prettifyErrorMessage9 = prettifyErrorMessage(error),
1711
+ extraMessage = _prettifyErrorMessage9.extraMessage,
1712
+ extraMessageDetail = _prettifyErrorMessage9.extraMessageDetail,
1713
+ extraMessageErrorCode = _prettifyErrorMessage9.extraMessageErrorCode;
1714
+ if (error && error != null && error.root && error != null && (_error$root13 = error.root) != null && _error$root13.message && error != null && (_error$root14 = error.root) != null && _error$root14.code && error != null && (_error$root15 = error.root) != null && _error$root15.reason) {
1715
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1716
+ }
1717
+ var updateResult = updateSwapStatus({
1718
+ getStorage: getStorage,
1719
+ setStorage: setStorage,
1720
+ nextStatus: 'failed',
1721
+ nextStepStatus: 'failed',
1722
+ message: extraMessage,
1723
+ details: extraMessageDetail,
1724
+ errorCode: extraMessageErrorCode
1725
+ });
1726
+ notifier(_extends({
1727
+ eventType: 'smart_contract_call_failed'
1728
+ }, updateResult));
1729
+ failed();
1730
+ onFinish();
1731
+ });
1732
+ }
1733
+ } else if (!!starknetTransaction) {
1734
+ var _updateResult9 = updateSwapStatus({
1735
+ getStorage: getStorage,
1736
+ setStorage: setStorage,
1737
+ nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1738
+ nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1739
+ message: executeMessage,
1740
+ details: executeDetails,
1741
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1742
+ errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1743
+ });
1744
+ var _notification5 = getSwapNotitfication('calling_smart_contract', _updateResult9);
1745
+ notifier(_notification5);
1746
+ if (_notification5.eventType === 'transaction_expired') {
1747
+ failed();
1748
+ onFinish();
1749
+ } else {
1750
+ walletSigners.getSigner(rangoSdk.TransactionType.STARKNET).signAndSendTx(starknetTransaction, walletAddress, null).then(function (id) {
1751
+ setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1752
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1753
+ next();
1754
+ onFinish();
1755
+ }, function (error) {
1756
+ var _error$root16, _error$root17, _error$root18;
1757
+ if (swap.status === 'failed') return;
1758
+ var _prettifyErrorMessage10 = prettifyErrorMessage(error),
1759
+ extraMessage = _prettifyErrorMessage10.extraMessage,
1760
+ extraMessageDetail = _prettifyErrorMessage10.extraMessageDetail,
1761
+ extraMessageErrorCode = _prettifyErrorMessage10.extraMessageErrorCode;
1762
+ if (error && error != null && error.root && error != null && (_error$root16 = error.root) != null && _error$root16.message && error != null && (_error$root17 = error.root) != null && _error$root17.code && error != null && (_error$root18 = error.root) != null && _error$root18.reason) {
1763
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1764
+ }
1765
+ var updateResult = updateSwapStatus({
1766
+ getStorage: getStorage,
1767
+ setStorage: setStorage,
1768
+ nextStatus: 'failed',
1769
+ nextStepStatus: 'failed',
1770
+ message: extraMessage,
1771
+ details: extraMessageDetail,
1772
+ errorCode: extraMessageErrorCode
1773
+ });
1774
+ notifier(_extends({
1775
+ eventType: 'smart_contract_call_failed'
1776
+ }, updateResult));
1777
+ failed();
1778
+ onFinish();
1779
+ });
1780
+ }
1781
+ }
1782
+ }
1783
+ function checkWaitingForConnectWalletChange(params) {
1784
+ var wallet_network = params.wallet_network,
1785
+ evmChains = params.evmChains,
1786
+ manager = params.manager;
1787
+ var _splitWalletNetwork = splitWalletNetwork(wallet_network),
1788
+ wallet = _splitWalletNetwork[0],
1789
+ network = _splitWalletNetwork[1];
1790
+ // We only need change network for EVM chains.
1791
+ if (!evmChains.some(function (chain) {
1792
+ return chain.name == network;
1793
+ })) return;
1794
+ manager == null ? void 0 : manager.getAll().forEach(function (q) {
1795
+ var queueStorage = q.list.getStorage();
1796
+ var swap = queueStorage == null ? void 0 : queueStorage.swapDetails;
1797
+ if (swap && swap.status === 'running') {
1798
+ var currentStep = getCurrentStep(swap);
1799
+ if (currentStep) {
1800
+ var _queueStorage$swapDet;
1801
+ var currentStepRequiredWallet = queueStorage == null ? void 0 : (_queueStorage$swapDet = queueStorage.swapDetails.wallets[currentStep.fromBlockchain]) == null ? void 0 : _queueStorage$swapDet.walletType;
1802
+ var hasWaitingForConnect = Object.keys(q.list.state.tasks).some(function (taskId) {
1803
+ var _task$blockedFor;
1804
+ var task = q.list.state.tasks[taskId];
1805
+ return task.status === queueManagerCore.Status.BLOCKED &&
1806
+ // TODO double check later
1807
+ [BlockReason.WAIT_FOR_CONNECT_WALLET].includes((_task$blockedFor = task.blockedFor) == null ? void 0 : _task$blockedFor.reason);
1808
+ });
1809
+ if (currentStepRequiredWallet === wallet && hasWaitingForConnect && getCurrentBlockchainOfOrNull(swap, currentStep) != network) {
1810
+ var queueInstance = q.list;
1811
+ var _getRequiredWallet5 = getRequiredWallet(swap),
1812
+ type = _getRequiredWallet5.type;
1813
+ var description = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(type);
1814
+ q.list.block({
1815
+ reason: {
1816
+ reason: BlockReason.WAIT_FOR_NETWORK_CHANGE,
1817
+ description: description
1818
+ },
1819
+ silent: true
1820
+ });
1821
+ var result = markRunningSwapAsSwitchingNetwork({
1822
+ getStorage: queueInstance.getStorage.bind(queueInstance),
1823
+ setStorage: queueInstance.setStorage.bind(queueInstance)
1824
+ });
1825
+ if (result) {
1826
+ params == null ? void 0 : params.notifier({
1827
+ eventType: 'waiting_for_network_change',
1828
+ swap: result.swap,
1829
+ step: result.step
1830
+ });
1831
+ }
1832
+ }
1833
+ }
1834
+ }
1835
+ });
1836
+ }
1837
+ function checkWaitingForNetworkChange(manager) {
1838
+ manager == null ? void 0 : manager.getAll().forEach(function (q) {
1839
+ var hasWaitingForNetwork = Object.keys(q.list.state.tasks).some(function (taskId) {
1840
+ var _task$blockedFor2;
1841
+ var task = q.list.state.tasks[taskId];
1842
+ return task.status === queueManagerCore.Status.BLOCKED && [BlockReason.WAIT_FOR_NETWORK_CHANGE, BlockReason.DEPENDS_ON_OTHER_QUEUES].includes((_task$blockedFor2 = task.blockedFor) == null ? void 0 : _task$blockedFor2.reason);
1843
+ });
1844
+ if (hasWaitingForNetwork) {
1845
+ var _q$list$getStorage;
1846
+ var swap = (_q$list$getStorage = q.list.getStorage()) == null ? void 0 : _q$list$getStorage.swapDetails;
1847
+ if (swap.status === 'running') {
1848
+ var _getRequiredWallet6 = getRequiredWallet(swap),
1849
+ type = _getRequiredWallet6.type;
1850
+ var description = ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type);
1851
+ // Change the block reason to waiting for connecting wallet
1852
+ q.list.block({
1853
+ reason: {
1854
+ reason: BlockReason.WAIT_FOR_CONNECT_WALLET,
1855
+ description: description
1856
+ }
1857
+ });
1858
+ }
1859
+ }
1860
+ });
1861
+ }
1862
+ /**
1863
+ * Get list of all running swaps
1864
+ *
1865
+ * @param manager
1866
+ * @returns list of pending swaps
1867
+ */
1868
+ function getRunningSwaps(manager) {
1869
+ var queues = (manager == null ? void 0 : manager.getAll()) || new Map();
1870
+ var result = [];
1871
+ queues.forEach(function (q) {
1872
+ // retry only on affected queues
1873
+ var queueStorage = q.list.getStorage();
1874
+ var swap = queueStorage == null ? void 0 : queueStorage.swapDetails;
1875
+ if (!swap || swap.status !== 'running') return;
1876
+ result.push(swap);
1877
+ });
1878
+ return result;
1879
+ }
1880
+ /**
1881
+ *
1882
+ * Trying to reset notifications for pending swaps to correct message on page load.
1883
+ * We could remove this after supporting auto connect for wallets.
1884
+ *
1885
+ * @param swaps
1886
+ * @param notifier
1887
+ * @returns
1888
+ */
1889
+ function resetRunningSwapNotifsOnPageLoad(runningSwaps, notifier) {
1890
+ runningSwaps.forEach(function (swap) {
1891
+ var currentStep = getCurrentStep(swap);
1892
+ var eventType;
1893
+ if ((currentStep == null ? void 0 : currentStep.networkStatus) === exports.PendingSwapNetworkStatus.WaitingForQueue) eventType = 'waiting_for_queue';else if ((swap == null ? void 0 : swap.status) === 'running') {
1894
+ eventType = 'waiting_for_connecting_wallet';
1895
+ }
1896
+ if (!!eventType && !!notifier) {
1897
+ notifier({
1898
+ eventType: eventType,
1899
+ swap: swap,
1900
+ step: currentStep
1901
+ });
1902
+ }
1903
+ });
1904
+ }
1905
+ /**
1906
+ *
1907
+ * Try to run blocked tasks by wallet and network name.
1908
+ * Goes through queues and extract blocked queues with matched wallet.
1909
+ * If found any blocked tasks with same wallet and network, runs them.
1910
+ * If not, runs only blocked tasks with matched wallet.
1911
+ *
1912
+ * @param wallet_network a string includes `wallet` type and `network` type.
1913
+ * @param manager
1914
+ * @returns
1915
+ */
1916
+ function retryOn(wallet_network, notifier, manager, options) {
1917
+ var _finalQueueToBeRun;
1918
+ if (options === void 0) {
1919
+ options = {
1920
+ fallbackToOnlyWallet: true
1921
+ };
1922
+ }
1923
+ var _splitWalletNetwork2 = splitWalletNetwork(wallet_network),
1924
+ wallet = _splitWalletNetwork2[0],
1925
+ network = _splitWalletNetwork2[1];
1926
+ if (!wallet || !network) {
1927
+ return;
1928
+ }
1929
+ var walletAndNetworkMatched = [];
1930
+ var onlyWalletMatched = [];
1931
+ manager == null ? void 0 : manager.getAll().forEach(function (q) {
1932
+ // retry only on affected queues
1933
+ if (q.status === queueManagerCore.Status.BLOCKED) {
1934
+ var queueStorage = q.list.getStorage();
1935
+ var swap = queueStorage == null ? void 0 : queueStorage.swapDetails;
1936
+ if (swap && swap.status === 'running') {
1937
+ var currentStep = getCurrentStep(swap);
1938
+ if (currentStep) {
1939
+ var _queueStorage$swapDet2, _queueStorage$swapDet3;
1940
+ if (getCurrentBlockchainOfOrNull(swap, currentStep) == network && (queueStorage == null ? void 0 : (_queueStorage$swapDet2 = queueStorage.swapDetails.wallets[network]) == null ? void 0 : _queueStorage$swapDet2.walletType) === wallet) {
1941
+ walletAndNetworkMatched.push(q.list);
1942
+ } else if ((queueStorage == null ? void 0 : (_queueStorage$swapDet3 = queueStorage.swapDetails.wallets[currentStep.fromBlockchain]) == null ? void 0 : _queueStorage$swapDet3.walletType) === wallet) {
1943
+ onlyWalletMatched.push(q.list);
1944
+ }
1945
+ }
1946
+ }
1947
+ }
1948
+ });
1949
+ var finalQueueToBeRun = undefined;
1950
+ if (walletAndNetworkMatched.length > 0) {
1951
+ finalQueueToBeRun = walletAndNetworkMatched[0];
1952
+ if (walletAndNetworkMatched.length > 1) {
1953
+ for (var i = 1; i < walletAndNetworkMatched.length; i++) {
1954
+ var currentQueue = walletAndNetworkMatched[i];
1955
+ markRunningSwapAsDependsOnOtherQueues({
1956
+ getStorage: currentQueue.getStorage.bind(currentQueue),
1957
+ setStorage: currentQueue.setStorage.bind(currentQueue),
1958
+ notifier: notifier
1959
+ });
1960
+ }
1961
+ }
1962
+ } else if (onlyWalletMatched.length > 0 && options.fallbackToOnlyWallet) {
1963
+ finalQueueToBeRun = onlyWalletMatched[0];
1964
+ }
1965
+ (_finalQueueToBeRun = finalQueueToBeRun) == null ? void 0 : _finalQueueToBeRun.checkBlock();
1966
+ }
1967
+ /*
1968
+ For avoiding conflict by making too many requests to wallet, we need to make sure
1969
+ We only run one request at a time (In parallel mode).
1970
+ */
1971
+ function isNeedBlockQueueForParallel(step) {
1972
+ return !!step.evmTransaction || !!step.evmApprovalTransaction || !!step.cosmosTransaction;
1973
+ }
1974
+ /*
1975
+ Create transaction endpoint doesn't return error code on http status code,
1976
+ For backward compatibilty with server and sdk, we use this wrapper to reject the promise.
1977
+ */
1978
+ function throwOnOK(_x7) {
1979
+ return _throwOnOK.apply(this, arguments);
1980
+ }
1981
+ function _throwOnOK() {
1982
+ _throwOnOK = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(rawResponse) {
1983
+ var responseBody;
1984
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1985
+ while (1) switch (_context3.prev = _context3.next) {
1986
+ case 0:
1987
+ _context3.prev = 0;
1988
+ _context3.next = 3;
1989
+ return rawResponse;
1990
+ case 3:
1991
+ responseBody = _context3.sent;
1992
+ if (!(!responseBody.ok || !responseBody.transaction)) {
1993
+ _context3.next = 6;
1994
+ break;
1995
+ }
1996
+ throw PrettyError.CreateTransaction(responseBody.error || 'bad response from create tx endpoint');
1997
+ case 6:
1998
+ return _context3.abrupt("return", responseBody);
1999
+ case 9:
2000
+ _context3.prev = 9;
2001
+ _context3.t0 = _context3["catch"](0);
2002
+ throw _context3.t0;
2003
+ case 12:
2004
+ case "end":
2005
+ return _context3.stop();
2006
+ }
2007
+ }, _callee3, null, [[0, 9]]);
2008
+ }));
2009
+ return _throwOnOK.apply(this, arguments);
2010
+ }
2011
+ function cancelSwap(swap) {
2012
+ swap.actions.cancel();
2013
+ return updateSwapStatus({
2014
+ getStorage: swap.actions.getStorage,
2015
+ setStorage: swap.actions.setStorage,
2016
+ message: 'Swap canceled by user.',
2017
+ details: "Warning: If you've already signed and sent a transaction, it won't be affected, but next swap steps will not be executed.",
2018
+ nextStatus: 'failed',
2019
+ nextStepStatus: 'failed',
2020
+ errorCode: 'USER_CANCEL'
2021
+ });
2022
+ }
2023
+
2024
+ var INTERVAL_FOR_CHECK = 3000;
2025
+ /**
2026
+ * Subscribe to status of swap transaction by checking from server periodically.
2027
+ * After getting the status, notify the user and schedule `SCHEDULE_NEXT_STEP`.
2028
+ */
2029
+ function checkTransactionStatus(_x) {
2030
+ return _checkTransactionStatus.apply(this, arguments);
2031
+ }
2032
+ /**
2033
+ * Subscribe to status of approval transaction by checking from server periodically.
2034
+ * After getting the status, notify the user and schedule `SCHEDULE_NEXT_STEP`.
2035
+ */
2036
+ function _checkTransactionStatus() {
2037
+ _checkTransactionStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
2038
+ var _status, _status2, _status3, _status4, _status5, _status6, _status7, _status8, _status9, _status10;
2039
+ var getStorage, setStorage, next, schedule, retry, context, swap, currentStep, txId, status, outputAmount, prevOutputAmount, newTransaction, nextStep;
2040
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2041
+ while (1) switch (_context.prev = _context.next) {
2042
+ case 0:
2043
+ getStorage = _ref.getStorage, setStorage = _ref.setStorage, next = _ref.next, schedule = _ref.schedule, retry = _ref.retry, context = _ref.context;
2044
+ swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2045
+ currentStep = getCurrentStep(swap);
2046
+ txId = currentStep.executedTransactionId;
2047
+ status = null;
2048
+ _context.prev = 5;
2049
+ _context.next = 8;
2050
+ return httpService.checkStatus({
2051
+ requestId: swap.requestId,
2052
+ txId: txId,
2053
+ step: currentStep.id
2054
+ });
2055
+ case 8:
2056
+ status = _context.sent;
2057
+ _context.next = 17;
2058
+ break;
2059
+ case 11:
2060
+ _context.prev = 11;
2061
+ _context.t0 = _context["catch"](5);
2062
+ _context.next = 15;
2063
+ return delay(INTERVAL_FOR_CHECK);
2064
+ case 15:
2065
+ retry();
2066
+ return _context.abrupt("return");
2067
+ case 17:
2068
+ outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? currentStep.outputAmount : null);
2069
+ prevOutputAmount = currentStep.outputAmount;
2070
+ swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
2071
+ swap.extraMessageSeverity = exports.MessageSeverity.info;
2072
+ swap.extraMessageDetail = '';
2073
+ currentStep.status = ((_status3 = status) == null ? void 0 : _status3.status) || currentStep.status;
2074
+ currentStep.diagnosisUrl = ((_status4 = status) == null ? void 0 : _status4.diagnosisUrl) || currentStep.diagnosisUrl || null;
2075
+ currentStep.outputAmount = outputAmount || currentStep.outputAmount;
2076
+ currentStep.explorerUrl = ((_status5 = status) == null ? void 0 : _status5.explorerUrl) || currentStep.explorerUrl;
2077
+ currentStep.internalSteps = ((_status6 = status) == null ? void 0 : _status6.steps) || null;
2078
+ newTransaction = (_status7 = status) == null ? void 0 : _status7.newTx;
2079
+ if (!!newTransaction) {
2080
+ currentStep.status = 'created';
2081
+ currentStep.executedTransactionId = null;
2082
+ currentStep.executedTransactionTime = null;
2083
+ currentStep.transferTransaction = null;
2084
+ currentStep.cosmosTransaction = null;
2085
+ currentStep.evmTransaction = null;
2086
+ currentStep.solanaTransaction = null;
2087
+ currentStep.evmApprovalTransaction = null;
2088
+ currentStep.starknetApprovalTransaction = null;
2089
+ currentStep.starknetTransaction = null;
2090
+ currentStep.tronApprovalTransaction = null;
2091
+ currentStep.tronTransaction = null;
2092
+ if (isEvmTransaction(newTransaction)) {
2093
+ if (newTransaction.isApprovalTx) currentStep.evmApprovalTransaction = newTransaction;else currentStep.evmTransaction = newTransaction;
2094
+ } else if (isCosmosTransaction(newTransaction)) {
2095
+ currentStep.cosmosTransaction = newTransaction;
2096
+ } else if (isSolanaTransaction(newTransaction)) {
2097
+ currentStep.solanaTransaction = newTransaction;
2098
+ } else if (isTrasnferTransaction(newTransaction)) {
2099
+ currentStep.transferTransaction = newTransaction;
2100
+ } else if (isStarknetTransaction(newTransaction)) {
2101
+ if (newTransaction.isApprovalTx) currentStep.starknetApprovalTransaction = newTransaction;else currentStep.starknetTransaction = newTransaction;
2102
+ } else if (isTronTransaction(newTransaction)) {
2103
+ if (newTransaction.isApprovalTx) currentStep.tronApprovalTransaction = newTransaction;else currentStep.tronTransaction = newTransaction;
2104
+ }
2105
+ }
2106
+ if (prevOutputAmount === null && outputAmount !== null) context.notifier({
2107
+ eventType: 'step_completed_with_output',
2108
+ swap: swap,
2109
+ step: currentStep
2110
+ });else if (prevOutputAmount === null && outputAmount === null) {
2111
+ // it is needed to set notification after reloading the page
2112
+ context.notifier({
2113
+ eventType: 'check_tx_status',
2114
+ swap: swap,
2115
+ step: currentStep
2116
+ });
2117
+ }
2118
+ if (currentStep.status === 'success') {
2119
+ nextStep = getNextStep(swap, currentStep);
2120
+ swap.extraMessageDetail = '';
2121
+ swap.extraMessage = !!nextStep ? "starting next step: " + nextStep.swapperId + ": " + nextStep.fromBlockchain + " -> " + nextStep.toBlockchain : '';
2122
+ } else if (currentStep.status === 'failed') {
2123
+ swap.extraMessage = 'Transaction failed in blockchain';
2124
+ swap.extraMessageSeverity = exports.MessageSeverity.error;
2125
+ swap.extraMessageDetail = '';
2126
+ }
2127
+ // Sync data with storage
2128
+ setStorage(_extends({}, getStorage(), {
2129
+ swapDetails: swap
2130
+ }));
2131
+ if (!(((_status8 = status) == null ? void 0 : _status8.status) === 'failed' || ((_status9 = status) == null ? void 0 : _status9.status) === 'success' || ((_status10 = status) == null ? void 0 : _status10.status) === 'running' && !!status.newTx)) {
2132
+ _context.next = 37;
2133
+ break;
2134
+ }
2135
+ schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2136
+ next();
2137
+ _context.next = 40;
2138
+ break;
2139
+ case 37:
2140
+ _context.next = 39;
2141
+ return delay(INTERVAL_FOR_CHECK);
2142
+ case 39:
2143
+ retry();
2144
+ case 40:
2145
+ case "end":
2146
+ return _context.stop();
2147
+ }
2148
+ }, _callee, null, [[5, 11]]);
2149
+ }));
2150
+ return _checkTransactionStatus.apply(this, arguments);
2151
+ }
2152
+ function checkApprovalStatus(_x2) {
2153
+ return _checkApprovalStatus.apply(this, arguments);
2154
+ }
2155
+ /**
2156
+ *
2157
+ * For doing a swap the user needs to accept a `contract` so it can use the user balance.
2158
+ * There is two types of check status:
2159
+ * 1. Checking approval transaction (Give permission to a contract)
2160
+ * 2. Checking swap transaction.
2161
+ *
2162
+ */
2163
+ function _checkApprovalStatus() {
2164
+ _checkApprovalStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
2165
+ var getStorage, setStorage, next, schedule, retry, failed, context, swap, currentStep, isApproved, response, updateResult;
2166
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2167
+ while (1) switch (_context2.prev = _context2.next) {
2168
+ case 0:
2169
+ getStorage = _ref2.getStorage, setStorage = _ref2.setStorage, next = _ref2.next, schedule = _ref2.schedule, retry = _ref2.retry, failed = _ref2.failed, context = _ref2.context;
2170
+ swap = getStorage().swapDetails; // double check it after fixing parallel
2171
+ // const onFinish = () => {
2172
+ // // TODO resetClaimedBy is undefined here
2173
+ // if (context.resetClaimedBy) {
2174
+ // context.resetClaimedBy();
2175
+ // }
2176
+ // };
2177
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2178
+ currentStep = getCurrentStep(swap);
2179
+ isApproved = false;
2180
+ _context2.prev = 4;
2181
+ _context2.next = 7;
2182
+ return httpService.checkApproval(swap.requestId, currentStep.executedTransactionId || '');
2183
+ case 7:
2184
+ response = _context2.sent;
2185
+ isApproved = response.isApproved;
2186
+ if (!isApproved && response.txStatus === 'failed') {
2187
+ // approve transaction failed on
2188
+ // we should fail the whole swap
2189
+ updateResult = updateSwapStatus({
2190
+ getStorage: getStorage,
2191
+ setStorage: setStorage,
2192
+ nextStatus: 'failed',
2193
+ nextStepStatus: 'failed',
2194
+ errorCode: 'SEND_TX_FAILED',
2195
+ message: 'Approve transaction failed',
2196
+ details: 'Smart contract approval failed in blockchain.'
2197
+ });
2198
+ context.notifier(_extends({
2199
+ eventType: 'smart_contract_call_failed'
2200
+ }, updateResult));
2201
+ failed();
2202
+ // onFinish();
2203
+ } else if (!isApproved) {
2204
+ // it is needed to set notification after reloading the page
2205
+ context.notifier({
2206
+ eventType: 'check_approve_tx_status',
2207
+ swap: swap,
2208
+ step: currentStep
2209
+ });
2210
+ }
2211
+ _context2.next = 16;
2212
+ break;
2213
+ case 12:
2214
+ _context2.prev = 12;
2215
+ _context2.t0 = _context2["catch"](4);
2216
+ console.error('Failed to check getApprovedAmount', _context2.t0);
2217
+ isApproved = false;
2218
+ case 16:
2219
+ if (!isApproved) {
2220
+ _context2.next = 32;
2221
+ break;
2222
+ }
2223
+ currentStep.status = 'approved';
2224
+ swap.extraMessage = "Spending " + currentStep.fromSymbol + " approved successfully.";
2225
+ swap.extraMessageDetail = null;
2226
+ swap.extraMessageSeverity = exports.MessageSeverity.success;
2227
+ currentStep.evmApprovalTransaction = null;
2228
+ currentStep.executedTransactionId = null;
2229
+ currentStep.executedTransactionTime = null;
2230
+ currentStep.starknetApprovalTransaction = null;
2231
+ currentStep.tronApprovalTransaction = null;
2232
+ setStorage(_extends({}, getStorage(), {
2233
+ swapDetails: swap
2234
+ }));
2235
+ context.notifier({
2236
+ eventType: 'contract_confirmed',
2237
+ swap: swap,
2238
+ step: currentStep
2239
+ });
2240
+ schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2241
+ next();
2242
+ _context2.next = 35;
2243
+ break;
2244
+ case 32:
2245
+ _context2.next = 34;
2246
+ return delay(2000);
2247
+ case 34:
2248
+ retry();
2249
+ case 35:
2250
+ case "end":
2251
+ return _context2.stop();
2252
+ }
2253
+ }, _callee2, null, [[4, 12]]);
2254
+ }));
2255
+ return _checkApprovalStatus.apply(this, arguments);
2256
+ }
2257
+ function checkStatus(_x3) {
2258
+ return _checkStatus.apply(this, arguments);
2259
+ }
2260
+ function _checkStatus() {
2261
+ _checkStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(actions) {
2262
+ var swap, currentStep;
2263
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2264
+ while (1) switch (_context3.prev = _context3.next) {
2265
+ case 0:
2266
+ swap = actions.getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2267
+ currentStep = getCurrentStep(swap); // Reset network status
2268
+ // Because when check status is on `loading` or `failed` status, it shows previous message that isn't related to current state.
2269
+ resetNetworkStatus(actions);
2270
+ if (!(currentStep.status === 'running')) {
2271
+ _context3.next = 8;
2272
+ break;
2273
+ }
2274
+ _context3.next = 6;
2275
+ return checkTransactionStatus(actions);
2276
+ case 6:
2277
+ _context3.next = 11;
2278
+ break;
2279
+ case 8:
2280
+ if (!(currentStep.status === 'waitingForApproval')) {
2281
+ _context3.next = 11;
2282
+ break;
2283
+ }
2284
+ _context3.next = 11;
2285
+ return checkApprovalStatus(actions);
2286
+ case 11:
2287
+ case "end":
2288
+ return _context3.stop();
2289
+ }
2290
+ }, _callee3);
2291
+ }));
2292
+ return _checkStatus.apply(this, arguments);
2293
+ }
2294
+
2295
+ /**
2296
+ *
2297
+ * When a user asks for a swap, We first create the transaction by sending a request to server
2298
+ * Server will return the transaction that need to be sent to wallet.
2299
+ * It can be failed if server goes through an error, If not, we will schedule the `EXECTUTE_TRANSACTION`.
2300
+ *
2301
+ */
2302
+ function createTransaction(_x) {
2303
+ return _createTransaction.apply(this, arguments);
2304
+ }
2305
+ function _createTransaction() {
2306
+ _createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
2307
+ var setStorage, getStorage, next, schedule, context, swap, currentStep, evmTransaction, cosmosTransaction, transferTransaction, evmApprovalTransaction, solanaTransaction, tronTransaction, tronApprovalTransaction, starknetTransaction, starknetApprovalTransaction, request, _yield$throwOnOK, transaction, _prettifyErrorMessage, extraMessage, extraMessageDetail, updateResult;
2308
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2309
+ while (1) switch (_context.prev = _context.next) {
2310
+ case 0:
2311
+ setStorage = actions.setStorage, getStorage = actions.getStorage, next = actions.next, schedule = actions.schedule, context = actions.context;
2312
+ swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2313
+ currentStep = getCurrentStep(swap);
2314
+ evmTransaction = currentStep.evmTransaction, cosmosTransaction = currentStep.cosmosTransaction, transferTransaction = currentStep.transferTransaction, evmApprovalTransaction = currentStep.evmApprovalTransaction, solanaTransaction = currentStep.solanaTransaction, tronTransaction = currentStep.tronTransaction, tronApprovalTransaction = currentStep.tronApprovalTransaction, starknetTransaction = currentStep.starknetTransaction, starknetApprovalTransaction = currentStep.starknetApprovalTransaction;
2315
+ if (!(!evmTransaction && !evmApprovalTransaction && !tronTransaction && !tronApprovalTransaction && !starknetTransaction && !starknetApprovalTransaction && !cosmosTransaction && !transferTransaction && !solanaTransaction)) {
2316
+ _context.next = 25;
2317
+ break;
2318
+ }
2319
+ request = {
2320
+ requestId: swap.requestId,
2321
+ step: currentStep.id,
2322
+ userSettings: {
2323
+ slippage: swap.settings.slippage,
2324
+ infiniteApprove: swap.settings.infiniteApprove
2325
+ },
2326
+ validations: {
2327
+ balance: swap.validateBalanceOrFee,
2328
+ fee: swap.validateBalanceOrFee
2329
+ }
2330
+ };
2331
+ _context.prev = 6;
2332
+ _context.next = 9;
2333
+ return throwOnOK(httpService.createTransaction(request));
2334
+ case 9:
2335
+ _yield$throwOnOK = _context.sent;
2336
+ transaction = _yield$throwOnOK.transaction;
2337
+ if (transaction) {
2338
+ if (isEvmTransaction(transaction)) {
2339
+ if (transaction.isApprovalTx) currentStep.evmApprovalTransaction = transaction;else currentStep.evmTransaction = transaction;
2340
+ } else if (isCosmosTransaction(transaction)) {
2341
+ currentStep.cosmosTransaction = transaction;
2342
+ } else if (isSolanaTransaction(transaction)) {
2343
+ currentStep.solanaTransaction = transaction;
2344
+ } else if (isTrasnferTransaction(transaction)) {
2345
+ currentStep.transferTransaction = transaction;
2346
+ } else if (isStarknetTransaction(transaction)) {
2347
+ if (transaction.isApprovalTx) currentStep.starknetApprovalTransaction = transaction;else currentStep.starknetTransaction = transaction;
2348
+ } else if (isTronTransaction(transaction)) {
2349
+ if (transaction.isApprovalTx) currentStep.tronApprovalTransaction = transaction;else currentStep.tronTransaction = transaction;
2350
+ }
2351
+ }
2352
+ setStorage(_extends({}, getStorage(), {
2353
+ swapDetails: swap
2354
+ }));
2355
+ schedule(SwapActionTypes.EXECUTE_TRANSACTION);
2356
+ next();
2357
+ _context.next = 25;
2358
+ break;
2359
+ case 17:
2360
+ _context.prev = 17;
2361
+ _context.t0 = _context["catch"](6);
2362
+ swap.status = 'failed';
2363
+ swap.finishTime = new Date().getTime().toString();
2364
+ _prettifyErrorMessage = prettifyErrorMessage(_context.t0), extraMessage = _prettifyErrorMessage.extraMessage, extraMessageDetail = _prettifyErrorMessage.extraMessageDetail;
2365
+ updateResult = updateSwapStatus({
2366
+ getStorage: getStorage,
2367
+ setStorage: setStorage,
2368
+ nextStatus: 'failed',
2369
+ nextStepStatus: 'failed',
2370
+ message: extraMessage,
2371
+ details: extraMessageDetail,
2372
+ errorCode: 'FETCH_TX_FAILED'
2373
+ });
2374
+ context.notifier(_extends({
2375
+ eventType: 'task_failed'
2376
+ }, updateResult));
2377
+ actions.failed();
2378
+ case 25:
2379
+ case "end":
2380
+ return _context.stop();
2381
+ }
2382
+ }, _callee, null, [[6, 17]]);
2383
+ }));
2384
+ return _createTransaction.apply(this, arguments);
2385
+ }
2386
+
2387
+ /**
2388
+ * Excecute a created transaction.
2389
+ *
2390
+ * This function implemented the parallel mode by `claim` mechanism which means
2391
+ * All the queues the meet certain situation (like multiple evm transaction) will go through
2392
+ * a `claim` mechanims that decides which queue should be run and it blocks other ones.
2393
+ *
2394
+ * A queue will be go to sign process, if the wallet and network is matched.
2395
+ */
2396
+ function executeTransaction(_x) {
2397
+ return _executeTransaction.apply(this, arguments);
2398
+ }
2399
+ function _executeTransaction() {
2400
+ _executeTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
2401
+ var _context$_queue;
2402
+ var getStorage, context, meta, wallets, providers, isClaimed, requestBlock, swap, currentStep, isWrongAddress, _wallets$blockchains, _getRequiredWallet, type, address, isWalletInCompatible, description, blockedFor, needsToBlockQueue, _blockedFor, networkMatched, fromBlockchain, details, _blockedFor2;
2403
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2404
+ while (1) switch (_context.prev = _context.next) {
2405
+ case 0:
2406
+ getStorage = actions.getStorage, context = actions.context;
2407
+ meta = context.meta, wallets = context.wallets, providers = context.providers;
2408
+ isClaimed = context.claimedBy === ((_context$_queue = context._queue) == null ? void 0 : _context$_queue.id);
2409
+ requestBlock = function requestBlock(blockedFor) {
2410
+ actions.block(blockedFor);
2411
+ if (isClaimed && actions.context.resetClaimedBy) {
2412
+ actions.context.resetClaimedBy();
2413
+ }
2414
+ };
2415
+ swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2416
+ currentStep = getCurrentStep(swap); // Resetting network status, so we will set it again during the running of this task.
2417
+ resetNetworkStatus(actions);
2418
+ /* Make sure wallet is connected and also the connected wallet is matched with tx by checking address. */
2419
+ isWrongAddress = !isRequiredWalletConnected(swap, context.state).ok;
2420
+ if (!isWrongAddress) {
2421
+ _context.next = 15;
2422
+ break;
2423
+ }
2424
+ _getRequiredWallet = getRequiredWallet(swap), type = _getRequiredWallet.type, address = _getRequiredWallet.address;
2425
+ isWalletInCompatible = wallets == null ? void 0 : (_wallets$blockchains = wallets.blockchains) == null ? void 0 : _wallets$blockchains.find(function (w) {
2426
+ var _w$accounts;
2427
+ return !((_w$accounts = w.accounts) != null && _w$accounts.find(function (account) {
2428
+ return account.walletType === type;
2429
+ }));
2430
+ });
2431
+ description = !wallets || isWalletInCompatible ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
2432
+ blockedFor = {
2433
+ reason: BlockReason.WAIT_FOR_CONNECT_WALLET,
2434
+ description: description
2435
+ };
2436
+ requestBlock(blockedFor);
2437
+ return _context.abrupt("return");
2438
+ case 15:
2439
+ /*
2440
+ For avoiding conflict by making too many requests to wallet, we need to make sure
2441
+ We only run one request at a time (In parallel mode).
2442
+ */
2443
+ needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
2444
+ if (!(needsToBlockQueue && !isClaimed && context.claimedBy)) {
2445
+ _context.next = 20;
2446
+ break;
2447
+ }
2448
+ _blockedFor = {
2449
+ reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
2450
+ description: 'Waiting for other swaps to complete',
2451
+ details: {}
2452
+ };
2453
+ requestBlock(_blockedFor);
2454
+ return _context.abrupt("return");
2455
+ case 20:
2456
+ _context.next = 22;
2457
+ return isNetworkMatchedForTransaction(swap, currentStep, wallets, meta, providers);
2458
+ case 22:
2459
+ networkMatched = _context.sent;
2460
+ if (networkMatched) {
2461
+ _context.next = 31;
2462
+ break;
2463
+ }
2464
+ fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
2465
+ details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(fromBlockchain);
2466
+ _blockedFor2 = {
2467
+ reason: BlockReason.WAIT_FOR_NETWORK_CHANGE,
2468
+ details: details
2469
+ };
2470
+ requestBlock(_blockedFor2);
2471
+ return _context.abrupt("return");
2472
+ case 31:
2473
+ // Update network to mark it as network changed successfully.
2474
+ updateNetworkStatus(actions, {
2475
+ message: '',
2476
+ details: 'Wallet network changed successfully',
2477
+ status: exports.PendingSwapNetworkStatus.NetworkChanged
2478
+ });
2479
+ case 32:
2480
+ // All the conditions are met. We can safely send the tx to wallet for sign.
2481
+ singTransaction(actions);
2482
+ case 33:
2483
+ case "end":
2484
+ return _context.stop();
2485
+ }
2486
+ }, _callee);
2487
+ }));
2488
+ return _executeTransaction.apply(this, arguments);
2489
+ }
2490
+
2491
+ /**
2492
+ *
2493
+ * This function is responsibe for scheduling the correct `action` based on `PendingSwap` status.
2494
+ * It means `action`s schedule this step to decide what should be the next step/task.
2495
+ *
2496
+ * It's acts like a `while(true)` and will `break` the loop on certain `action`s like `CHECK_STATUS`.
2497
+ *
2498
+ *
2499
+ */
2500
+ function scheduleNextStep(_ref) {
2501
+ var schedule = _ref.schedule,
2502
+ next = _ref.next,
2503
+ failed = _ref.failed,
2504
+ setStorage = _ref.setStorage,
2505
+ getStorage = _ref.getStorage,
2506
+ context = _ref.context;
2507
+ var swap = getStorage().swapDetails;
2508
+ var currentStep = getCurrentStep(swap);
2509
+ if (!!currentStep) {
2510
+ if (isTxAlreadyCreated(swap, currentStep)) {
2511
+ schedule(SwapActionTypes.EXECUTE_TRANSACTION);
2512
+ return next();
2513
+ }
2514
+ // TODO double check it after approval changes
2515
+ if (currentStep != null && currentStep.executedTransactionId) {
2516
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
2517
+ return next();
2518
+ }
2519
+ swap.status = 'running';
2520
+ setStorage(_extends({}, getStorage(), {
2521
+ swapDetails: swap
2522
+ }));
2523
+ schedule(SwapActionTypes.CREATE_TRANSACTION);
2524
+ next();
2525
+ } else {
2526
+ var isFailed = swap.steps.find(function (step) {
2527
+ return step.status === 'failed';
2528
+ });
2529
+ swap.status = isFailed ? 'failed' : 'success';
2530
+ swap.finishTime = new Date().getTime().toString();
2531
+ setStorage(_extends({}, getStorage(), {
2532
+ swapDetails: swap
2533
+ }));
2534
+ context.notifier({
2535
+ eventType: isFailed ? 'task_failed' : 'task_completed',
2536
+ swap: swap,
2537
+ step: null
2538
+ });
2539
+ if (isFailed) failed();else next();
2540
+ }
2541
+ }
2542
+
2543
+ function start(_ref) {
2544
+ var schedule = _ref.schedule,
2545
+ next = _ref.next;
2546
+ schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2547
+ next();
2548
+ }
2549
+
2550
+ var _actions;
2551
+ /**
2552
+ *
2553
+ * The idea behind this queue is to be able dynamically add some steps.
2554
+ * After running a swap, it can be blocked (like on waiting for switch netwrok)
2555
+ * or waits for something happend (like checking status of a transaction from server)
2556
+ *
2557
+ */
2558
+ var swapQueueDef = {
2559
+ name: 'swap',
2560
+ actions: (_actions = {}, _actions[SwapActionTypes.START] = start, _actions[SwapActionTypes.SCHEDULE_NEXT_STEP] = scheduleNextStep, _actions[SwapActionTypes.CREATE_TRANSACTION] = createTransaction, _actions[SwapActionTypes.EXECUTE_TRANSACTION] = executeTransaction, _actions[SwapActionTypes.CHECK_TRANSACTION_STATUS] = checkStatus, _actions),
2561
+ run: [SwapActionTypes.START],
2562
+ whenTaskBlocked: function whenTaskBlocked(event, meta) {
2563
+ if (event.reason.reason === BlockReason.WAIT_FOR_CONNECT_WALLET) {
2564
+ onBlockForConnectWallet(event, meta);
2565
+ } else if (event.reason.reason === BlockReason.WAIT_FOR_NETWORK_CHANGE) {
2566
+ onBlockForChangeNetwork(event, meta);
2567
+ } else if (event.reason.reason === BlockReason.DEPENDS_ON_OTHER_QUEUES) {
2568
+ onDependsOnOtherQueues(event, meta);
2569
+ }
2570
+ }
2571
+ };
2572
+
2573
+ var MIGRATED_KEY = 'migratedToQueueManager';
2574
+ /**
2575
+ *
2576
+ * If `MIGRATED_KEY` is set, it means we already migrated data from localstorage.
2577
+ *
2578
+ */
2579
+ function migrated() {
2580
+ return !!window.localStorage.getItem(MIGRATED_KEY);
2581
+ }
2582
+ function hasQueueManagerOnIDB() {
2583
+ return _hasQueueManagerOnIDB.apply(this, arguments);
2584
+ }
2585
+ /**
2586
+ *
2587
+ * By calling this function, we first check if the data already migrated or not,
2588
+ * If not, starting to migrating to IndexedDb with proper format that queue manager is understand.
2589
+ *
2590
+ */
2591
+ function _hasQueueManagerOnIDB() {
2592
+ _hasQueueManagerOnIDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2593
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2594
+ while (1) switch (_context.prev = _context.next) {
2595
+ case 0:
2596
+ _context.prev = 0;
2597
+ _context.next = 3;
2598
+ return window.indexedDB.databases();
2599
+ case 3:
2600
+ return _context.abrupt("return", _context.sent.map(function (db) {
2601
+ return db.name;
2602
+ }).includes(queueManagerCore.DB_NAME));
2603
+ case 6:
2604
+ _context.prev = 6;
2605
+ _context.t0 = _context["catch"](0);
2606
+ return _context.abrupt("return", false);
2607
+ case 9:
2608
+ case "end":
2609
+ return _context.stop();
2610
+ }
2611
+ }, _callee, null, [[0, 6]]);
2612
+ }));
2613
+ return _hasQueueManagerOnIDB.apply(this, arguments);
2614
+ }
2615
+ function migration() {
2616
+ return _migration.apply(this, arguments);
2617
+ }
2618
+ function _migration() {
2619
+ _migration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
2620
+ var swapsFromStorage, hasIndexDB, swaps, convertedSwaps, persistor, promises;
2621
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2622
+ while (1) switch (_context2.prev = _context2.next) {
2623
+ case 0:
2624
+ swapsFromStorage = window.localStorage.getItem('pendingSwaps');
2625
+ _context2.next = 3;
2626
+ return hasQueueManagerOnIDB();
2627
+ case 3:
2628
+ hasIndexDB = _context2.sent;
2629
+ if (!(!swapsFromStorage || migrated() || hasIndexDB)) {
2630
+ _context2.next = 6;
2631
+ break;
2632
+ }
2633
+ return _context2.abrupt("return", true);
2634
+ case 6:
2635
+ // For old users, but they didn't do any swaps yet.
2636
+ swaps = JSON.parse(swapsFromStorage);
2637
+ convertedSwaps = [];
2638
+ swaps.forEach(function (swap) {
2639
+ /*
2640
+ For running task we need to add some more work
2641
+ We need to create a queue task to be run and resume the running task from queue manager.
2642
+ */
2643
+ if (swap.status === 'running') {
2644
+ var _tasks;
2645
+ var taskId = uuid.v4();
2646
+ var convertedSwap = {
2647
+ id: swap.requestId,
2648
+ createdAt: Number(swap.creationTime),
2649
+ name: 'swap',
2650
+ status: queueManagerCore.Status.RUNNING,
2651
+ storage: {
2652
+ swapDetails: swap
2653
+ },
2654
+ state: {
2655
+ status: queueManagerCore.Status.RUNNING,
2656
+ activeTaskIndex: 0,
2657
+ tasks: (_tasks = {}, _tasks[taskId] = {
2658
+ blockedFor: null,
2659
+ status: queueManagerCore.Status.RUNNING
2660
+ }, _tasks)
2661
+ },
2662
+ tasks: [{
2663
+ id: taskId,
2664
+ action: SwapActionTypes.SCHEDULE_NEXT_STEP
2665
+ }]
2666
+ };
2667
+ convertedSwaps.push(convertedSwap);
2668
+ } else {
2669
+ /*
2670
+ * For failed or successful swaps, we only move it to IndexedDB,
2671
+ * And there is no need to consider them to be run.
2672
+ */
2673
+ var status = swap.status === 'success' ? queueManagerCore.Status.SUCCESS : queueManagerCore.Status.FAILED;
2674
+ var _convertedSwap = {
2675
+ id: swap.requestId,
2676
+ createdAt: Number(swap.creationTime),
2677
+ name: 'swap',
2678
+ status: status,
2679
+ storage: {
2680
+ swapDetails: swap
2681
+ },
2682
+ state: {
2683
+ status: status,
2684
+ activeTaskIndex: 0,
2685
+ tasks: {}
2686
+ },
2687
+ tasks: []
2688
+ };
2689
+ convertedSwaps.push(_convertedSwap);
2690
+ }
2691
+ });
2692
+ // Getting an instance from persistor, so we can directly put our data inside it.
2693
+ persistor = new queueManagerCore.Persistor();
2694
+ promises = convertedSwaps.map(function (queue) {
2695
+ return persistor.insertQueue(queue);
2696
+ });
2697
+ _context2.next = 13;
2698
+ return Promise.all(promises);
2699
+ case 13:
2700
+ // Mark as the data has been successfully migrated.
2701
+ window.localStorage.setItem(MIGRATED_KEY, '1');
2702
+ return _context2.abrupt("return", true);
2703
+ case 15:
2704
+ case "end":
2705
+ return _context2.stop();
2706
+ }
2707
+ }, _callee2);
2708
+ }));
2709
+ return _migration.apply(this, arguments);
2710
+ }
2711
+
2712
+ var isCalled = 0;
2713
+ /**
2714
+ *
2715
+ * Runs a migration (old swaps from localstorage to queue manager's IndexedDB)
2716
+ * It will be run only once on page load.
2717
+ *
2718
+ */
2719
+ function useMigration() {
2720
+ var isMigrated = migrated();
2721
+ var _useState = react.useState(isMigrated),
2722
+ status = _useState[0],
2723
+ setStatus = _useState[1];
2724
+ react.useEffect(function () {
2725
+ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2726
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2727
+ while (1) switch (_context.prev = _context.next) {
2728
+ case 0:
2729
+ if (!isCalled) {
2730
+ _context.next = 2;
2731
+ break;
2732
+ }
2733
+ return _context.abrupt("return");
2734
+ case 2:
2735
+ isCalled = 1;
2736
+ migration()["finally"](function () {
2737
+ setStatus(true);
2738
+ });
2739
+ case 4:
2740
+ case "end":
2741
+ return _context.stop();
2742
+ }
2743
+ }, _callee);
2744
+ }))();
2745
+ }, []);
2746
+ return {
2747
+ status: status
2748
+ };
2749
+ }
2750
+ /**
2751
+ *
2752
+ * On initial load and also connect/disconnet we may need to update swap's notified message.
2753
+ * And also if a new wallet is connected we will retry the queue to see we can resume it or not.
2754
+ *
2755
+ */
2756
+ function useQueueManager(params) {
2757
+ var _useManager = queueManagerReact.useManager(),
2758
+ manager = _useManager.manager;
2759
+ react.useEffect(function () {
2760
+ if (params.lastConnectedWallet) {
2761
+ checkWaitingForConnectWalletChange({
2762
+ evmChains: params.evmChains,
2763
+ wallet_network: params.lastConnectedWallet,
2764
+ manager: manager,
2765
+ notifier: params.notifier
2766
+ });
2767
+ retryOn(params.lastConnectedWallet, params.notifier, manager);
2768
+ }
2769
+ }, [params.lastConnectedWallet]);
2770
+ react.useEffect(function () {
2771
+ if (params.disconnectedWallet) {
2772
+ checkWaitingForNetworkChange(manager);
2773
+ /*
2774
+ We need to reset the state value, so if a wallet disconnected twice (after reconnect),
2775
+ this effect will be run properly.
2776
+ */
2777
+ params.clearDisconnectedWallet();
2778
+ }
2779
+ }, [params.disconnectedWallet]);
2780
+ }
2781
+
2782
+ exports.PrettyError = PrettyError;
2783
+ exports.cancelSwap = cancelSwap;
2784
+ exports.checkWaitingForNetworkChange = checkWaitingForNetworkChange;
2785
+ exports.getCurrentBlockchainOfOrNull = getCurrentBlockchainOfOrNull;
2786
+ exports.getCurrentStep = getCurrentStep;
2787
+ exports.getEvmProvider = getEvmProvider;
2788
+ exports.getRelatedWallet = getRelatedWallet;
2789
+ exports.getRelatedWalletOrNull = getRelatedWalletOrNull;
2790
+ exports.getRequiredWallet = getRequiredWallet;
2791
+ exports.getRunningSwaps = getRunningSwaps;
2792
+ exports.prettifyErrorMessage = prettifyErrorMessage;
2793
+ exports.resetRunningSwapNotifsOnPageLoad = resetRunningSwapNotifsOnPageLoad;
2794
+ exports.splitWalletNetwork = splitWalletNetwork;
2795
+ exports.swapQueueDef = swapQueueDef;
2796
+ exports.updateSwapStatus = updateSwapStatus;
2797
+ exports.useMigration = useMigration;
2798
+ exports.useQueueManager = useQueueManager;
2799
+ //# sourceMappingURL=queue-manager-rango-preset.cjs.development.js.map