@rango-dev/queue-manager-rango-preset 0.1.10-next.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/checkStatus.d.ts +12 -0
- package/dist/actions/checkStatus.d.ts.map +1 -0
- package/dist/actions/createTransaction.d.ts +11 -0
- package/dist/actions/createTransaction.d.ts.map +1 -0
- package/dist/actions/executeTransaction.d.ts +13 -0
- package/dist/actions/executeTransaction.d.ts.map +1 -0
- package/dist/actions/scheduleNextStep.d.ts +13 -0
- package/dist/actions/scheduleNextStep.d.ts.map +1 -0
- package/dist/actions/start.d.ts +4 -0
- package/dist/actions/start.d.ts.map +1 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/helpers.d.ts +159 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/hooks.d.ts +19 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/migration.d.ts +15 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/queue-manager-rango-preset.cjs.development.js +2249 -0
- package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -0
- package/dist/queue-manager-rango-preset.cjs.production.min.js +2 -0
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -0
- package/dist/queue-manager-rango-preset.esm.js +2242 -0
- package/dist/queue-manager-rango-preset.esm.js.map +1 -0
- package/dist/queueDef.d.ts +10 -0
- package/dist/queueDef.d.ts.map +1 -0
- package/dist/shared-api.d.ts +10 -0
- package/dist/shared-api.d.ts.map +1 -0
- package/dist/shared-errors.d.ts +56 -0
- package/dist/shared-errors.d.ts.map +1 -0
- package/dist/shared-sentry.d.ts +4 -0
- package/dist/shared-sentry.d.ts.map +1 -0
- package/dist/shared.d.ts +149 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +59 -0
- package/readme.md +9 -0
- package/src/actions/checkStatus.ts +213 -0
- package/src/actions/createTransaction.ts +101 -0
- package/src/actions/executeTransaction.ts +117 -0
- package/src/actions/scheduleNextStep.ts +60 -0
- package/src/actions/start.ts +10 -0
- package/src/constants.ts +23 -0
- package/src/helpers.ts +1252 -0
- package/src/hooks.ts +75 -0
- package/src/index.ts +39 -0
- package/src/migration.ts +112 -0
- package/src/queueDef.ts +39 -0
- package/src/shared-api.ts +175 -0
- package/src/shared-errors.ts +156 -0
- package/src/shared-sentry.ts +24 -0
- package/src/shared.ts +333 -0
- package/src/types.ts +76 -0
|
@@ -0,0 +1,2249 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var BigNumber = require('bignumber.js');
|
|
8
|
+
var BigNumber__default = _interopDefault(BigNumber);
|
|
9
|
+
var walletsShared = require('@rango-dev/wallets-shared');
|
|
10
|
+
var walletsCore = require('@rango-dev/wallets-core');
|
|
11
|
+
var queueManagerCore = require('@rango-dev/queue-manager-core');
|
|
12
|
+
var Sentry = require('@sentry/browser');
|
|
13
|
+
|
|
14
|
+
var SwapActionTypes;
|
|
15
|
+
(function (SwapActionTypes) {
|
|
16
|
+
SwapActionTypes["START"] = "START";
|
|
17
|
+
SwapActionTypes["SCHEDULE_NEXT_STEP"] = "SCHEDULE_NEXT_STEP";
|
|
18
|
+
SwapActionTypes["CREATE_TRANSACTION"] = "CREATE_TRANSACTION";
|
|
19
|
+
SwapActionTypes["EXECUTE_TRANSACTION"] = "EXECUTE_TRANSACTION";
|
|
20
|
+
SwapActionTypes["CHECK_TRANSACTION_STATUS"] = "CHECK_TRANSACTION_STATUS";
|
|
21
|
+
})(SwapActionTypes || (SwapActionTypes = {}));
|
|
22
|
+
var BlockReason;
|
|
23
|
+
(function (BlockReason) {
|
|
24
|
+
BlockReason["WAIT_FOR_CONNECT_WALLET"] = "waiting_for_connecting_wallet";
|
|
25
|
+
BlockReason["WAIT_FOR_NETWORK_CHANGE"] = "waiting_for_network_change";
|
|
26
|
+
BlockReason["DEPENDS_ON_OTHER_QUEUES"] = "depends_on_other_queues";
|
|
27
|
+
})(BlockReason || (BlockReason = {}));
|
|
28
|
+
|
|
29
|
+
function _regeneratorRuntime() {
|
|
30
|
+
_regeneratorRuntime = function () {
|
|
31
|
+
return exports;
|
|
32
|
+
};
|
|
33
|
+
var exports = {},
|
|
34
|
+
Op = Object.prototype,
|
|
35
|
+
hasOwn = Op.hasOwnProperty,
|
|
36
|
+
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
37
|
+
obj[key] = desc.value;
|
|
38
|
+
},
|
|
39
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
40
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
41
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
42
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
43
|
+
function define(obj, key, value) {
|
|
44
|
+
return Object.defineProperty(obj, key, {
|
|
45
|
+
value: value,
|
|
46
|
+
enumerable: !0,
|
|
47
|
+
configurable: !0,
|
|
48
|
+
writable: !0
|
|
49
|
+
}), obj[key];
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
define({}, "");
|
|
53
|
+
} catch (err) {
|
|
54
|
+
define = function (obj, key, value) {
|
|
55
|
+
return obj[key] = value;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
59
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
60
|
+
generator = Object.create(protoGenerator.prototype),
|
|
61
|
+
context = new Context(tryLocsList || []);
|
|
62
|
+
return defineProperty(generator, "_invoke", {
|
|
63
|
+
value: makeInvokeMethod(innerFn, self, context)
|
|
64
|
+
}), generator;
|
|
65
|
+
}
|
|
66
|
+
function tryCatch(fn, obj, arg) {
|
|
67
|
+
try {
|
|
68
|
+
return {
|
|
69
|
+
type: "normal",
|
|
70
|
+
arg: fn.call(obj, arg)
|
|
71
|
+
};
|
|
72
|
+
} catch (err) {
|
|
73
|
+
return {
|
|
74
|
+
type: "throw",
|
|
75
|
+
arg: err
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.wrap = wrap;
|
|
80
|
+
var ContinueSentinel = {};
|
|
81
|
+
function Generator() {}
|
|
82
|
+
function GeneratorFunction() {}
|
|
83
|
+
function GeneratorFunctionPrototype() {}
|
|
84
|
+
var IteratorPrototype = {};
|
|
85
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
86
|
+
return this;
|
|
87
|
+
});
|
|
88
|
+
var getProto = Object.getPrototypeOf,
|
|
89
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
90
|
+
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
91
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
92
|
+
function defineIteratorMethods(prototype) {
|
|
93
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
94
|
+
define(prototype, method, function (arg) {
|
|
95
|
+
return this._invoke(method, arg);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
100
|
+
function invoke(method, arg, resolve, reject) {
|
|
101
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
102
|
+
if ("throw" !== record.type) {
|
|
103
|
+
var result = record.arg,
|
|
104
|
+
value = result.value;
|
|
105
|
+
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
106
|
+
invoke("next", value, resolve, reject);
|
|
107
|
+
}, function (err) {
|
|
108
|
+
invoke("throw", err, resolve, reject);
|
|
109
|
+
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
110
|
+
result.value = unwrapped, resolve(result);
|
|
111
|
+
}, function (error) {
|
|
112
|
+
return invoke("throw", error, resolve, reject);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
reject(record.arg);
|
|
116
|
+
}
|
|
117
|
+
var previousPromise;
|
|
118
|
+
defineProperty(this, "_invoke", {
|
|
119
|
+
value: function (method, arg) {
|
|
120
|
+
function callInvokeWithMethodAndArg() {
|
|
121
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
122
|
+
invoke(method, arg, resolve, reject);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
130
|
+
var state = "suspendedStart";
|
|
131
|
+
return function (method, arg) {
|
|
132
|
+
if ("executing" === state) throw new Error("Generator is already running");
|
|
133
|
+
if ("completed" === state) {
|
|
134
|
+
if ("throw" === method) throw arg;
|
|
135
|
+
return doneResult();
|
|
136
|
+
}
|
|
137
|
+
for (context.method = method, context.arg = arg;;) {
|
|
138
|
+
var delegate = context.delegate;
|
|
139
|
+
if (delegate) {
|
|
140
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
141
|
+
if (delegateResult) {
|
|
142
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
143
|
+
return delegateResult;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
147
|
+
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
148
|
+
context.dispatchException(context.arg);
|
|
149
|
+
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
150
|
+
state = "executing";
|
|
151
|
+
var record = tryCatch(innerFn, self, context);
|
|
152
|
+
if ("normal" === record.type) {
|
|
153
|
+
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
154
|
+
return {
|
|
155
|
+
value: record.arg,
|
|
156
|
+
done: context.done
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
164
|
+
var methodName = context.method,
|
|
165
|
+
method = delegate.iterator[methodName];
|
|
166
|
+
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;
|
|
167
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
168
|
+
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
169
|
+
var info = record.arg;
|
|
170
|
+
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);
|
|
171
|
+
}
|
|
172
|
+
function pushTryEntry(locs) {
|
|
173
|
+
var entry = {
|
|
174
|
+
tryLoc: locs[0]
|
|
175
|
+
};
|
|
176
|
+
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
177
|
+
}
|
|
178
|
+
function resetTryEntry(entry) {
|
|
179
|
+
var record = entry.completion || {};
|
|
180
|
+
record.type = "normal", delete record.arg, entry.completion = record;
|
|
181
|
+
}
|
|
182
|
+
function Context(tryLocsList) {
|
|
183
|
+
this.tryEntries = [{
|
|
184
|
+
tryLoc: "root"
|
|
185
|
+
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
186
|
+
}
|
|
187
|
+
function values(iterable) {
|
|
188
|
+
if (iterable) {
|
|
189
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
190
|
+
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
191
|
+
if ("function" == typeof iterable.next) return iterable;
|
|
192
|
+
if (!isNaN(iterable.length)) {
|
|
193
|
+
var i = -1,
|
|
194
|
+
next = function next() {
|
|
195
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
196
|
+
return next.value = undefined, next.done = !0, next;
|
|
197
|
+
};
|
|
198
|
+
return next.next = next;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
next: doneResult
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function doneResult() {
|
|
206
|
+
return {
|
|
207
|
+
value: undefined,
|
|
208
|
+
done: !0
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
212
|
+
value: GeneratorFunctionPrototype,
|
|
213
|
+
configurable: !0
|
|
214
|
+
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
215
|
+
value: GeneratorFunction,
|
|
216
|
+
configurable: !0
|
|
217
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
218
|
+
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
219
|
+
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
220
|
+
}, exports.mark = function (genFun) {
|
|
221
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
222
|
+
}, exports.awrap = function (arg) {
|
|
223
|
+
return {
|
|
224
|
+
__await: arg
|
|
225
|
+
};
|
|
226
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
227
|
+
return this;
|
|
228
|
+
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
229
|
+
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
230
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
231
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
232
|
+
return result.done ? result.value : iter.next();
|
|
233
|
+
});
|
|
234
|
+
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
235
|
+
return this;
|
|
236
|
+
}), define(Gp, "toString", function () {
|
|
237
|
+
return "[object Generator]";
|
|
238
|
+
}), exports.keys = function (val) {
|
|
239
|
+
var object = Object(val),
|
|
240
|
+
keys = [];
|
|
241
|
+
for (var key in object) keys.push(key);
|
|
242
|
+
return keys.reverse(), function next() {
|
|
243
|
+
for (; keys.length;) {
|
|
244
|
+
var key = keys.pop();
|
|
245
|
+
if (key in object) return next.value = key, next.done = !1, next;
|
|
246
|
+
}
|
|
247
|
+
return next.done = !0, next;
|
|
248
|
+
};
|
|
249
|
+
}, exports.values = values, Context.prototype = {
|
|
250
|
+
constructor: Context,
|
|
251
|
+
reset: function (skipTempReset) {
|
|
252
|
+
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);
|
|
253
|
+
},
|
|
254
|
+
stop: function () {
|
|
255
|
+
this.done = !0;
|
|
256
|
+
var rootRecord = this.tryEntries[0].completion;
|
|
257
|
+
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
258
|
+
return this.rval;
|
|
259
|
+
},
|
|
260
|
+
dispatchException: function (exception) {
|
|
261
|
+
if (this.done) throw exception;
|
|
262
|
+
var context = this;
|
|
263
|
+
function handle(loc, caught) {
|
|
264
|
+
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
265
|
+
}
|
|
266
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
267
|
+
var entry = this.tryEntries[i],
|
|
268
|
+
record = entry.completion;
|
|
269
|
+
if ("root" === entry.tryLoc) return handle("end");
|
|
270
|
+
if (entry.tryLoc <= this.prev) {
|
|
271
|
+
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
272
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
273
|
+
if (hasCatch && hasFinally) {
|
|
274
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
275
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
276
|
+
} else if (hasCatch) {
|
|
277
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
278
|
+
} else {
|
|
279
|
+
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
280
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
abrupt: function (type, arg) {
|
|
286
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
287
|
+
var entry = this.tryEntries[i];
|
|
288
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
289
|
+
var finallyEntry = entry;
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
294
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
295
|
+
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
296
|
+
},
|
|
297
|
+
complete: function (record, afterLoc) {
|
|
298
|
+
if ("throw" === record.type) throw record.arg;
|
|
299
|
+
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;
|
|
300
|
+
},
|
|
301
|
+
finish: function (finallyLoc) {
|
|
302
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
303
|
+
var entry = this.tryEntries[i];
|
|
304
|
+
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
catch: function (tryLoc) {
|
|
308
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
309
|
+
var entry = this.tryEntries[i];
|
|
310
|
+
if (entry.tryLoc === tryLoc) {
|
|
311
|
+
var record = entry.completion;
|
|
312
|
+
if ("throw" === record.type) {
|
|
313
|
+
var thrown = record.arg;
|
|
314
|
+
resetTryEntry(entry);
|
|
315
|
+
}
|
|
316
|
+
return thrown;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
throw new Error("illegal catch attempt");
|
|
320
|
+
},
|
|
321
|
+
delegateYield: function (iterable, resultName, nextLoc) {
|
|
322
|
+
return this.delegate = {
|
|
323
|
+
iterator: values(iterable),
|
|
324
|
+
resultName: resultName,
|
|
325
|
+
nextLoc: nextLoc
|
|
326
|
+
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
327
|
+
}
|
|
328
|
+
}, exports;
|
|
329
|
+
}
|
|
330
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
331
|
+
try {
|
|
332
|
+
var info = gen[key](arg);
|
|
333
|
+
var value = info.value;
|
|
334
|
+
} catch (error) {
|
|
335
|
+
reject(error);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (info.done) {
|
|
339
|
+
resolve(value);
|
|
340
|
+
} else {
|
|
341
|
+
Promise.resolve(value).then(_next, _throw);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function _asyncToGenerator(fn) {
|
|
345
|
+
return function () {
|
|
346
|
+
var self = this,
|
|
347
|
+
args = arguments;
|
|
348
|
+
return new Promise(function (resolve, reject) {
|
|
349
|
+
var gen = fn.apply(self, args);
|
|
350
|
+
function _next(value) {
|
|
351
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
352
|
+
}
|
|
353
|
+
function _throw(err) {
|
|
354
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
355
|
+
}
|
|
356
|
+
_next(undefined);
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function _extends() {
|
|
361
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
362
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
363
|
+
var source = arguments[i];
|
|
364
|
+
for (var key in source) {
|
|
365
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
366
|
+
target[key] = source[key];
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return target;
|
|
371
|
+
};
|
|
372
|
+
return _extends.apply(this, arguments);
|
|
373
|
+
}
|
|
374
|
+
function _inheritsLoose(subClass, superClass) {
|
|
375
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
376
|
+
subClass.prototype.constructor = subClass;
|
|
377
|
+
_setPrototypeOf(subClass, superClass);
|
|
378
|
+
}
|
|
379
|
+
function _getPrototypeOf(o) {
|
|
380
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
381
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
382
|
+
};
|
|
383
|
+
return _getPrototypeOf(o);
|
|
384
|
+
}
|
|
385
|
+
function _setPrototypeOf(o, p) {
|
|
386
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
387
|
+
o.__proto__ = p;
|
|
388
|
+
return o;
|
|
389
|
+
};
|
|
390
|
+
return _setPrototypeOf(o, p);
|
|
391
|
+
}
|
|
392
|
+
function _isNativeReflectConstruct() {
|
|
393
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
394
|
+
if (Reflect.construct.sham) return false;
|
|
395
|
+
if (typeof Proxy === "function") return true;
|
|
396
|
+
try {
|
|
397
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
398
|
+
return true;
|
|
399
|
+
} catch (e) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function _construct(Parent, args, Class) {
|
|
404
|
+
if (_isNativeReflectConstruct()) {
|
|
405
|
+
_construct = Reflect.construct.bind();
|
|
406
|
+
} else {
|
|
407
|
+
_construct = function _construct(Parent, args, Class) {
|
|
408
|
+
var a = [null];
|
|
409
|
+
a.push.apply(a, args);
|
|
410
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
411
|
+
var instance = new Constructor();
|
|
412
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
413
|
+
return instance;
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return _construct.apply(null, arguments);
|
|
417
|
+
}
|
|
418
|
+
function _isNativeFunction(fn) {
|
|
419
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
420
|
+
}
|
|
421
|
+
function _wrapNativeSuper(Class) {
|
|
422
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
423
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
424
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
425
|
+
if (typeof Class !== "function") {
|
|
426
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
427
|
+
}
|
|
428
|
+
if (typeof _cache !== "undefined") {
|
|
429
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
430
|
+
_cache.set(Class, Wrapper);
|
|
431
|
+
}
|
|
432
|
+
function Wrapper() {
|
|
433
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
434
|
+
}
|
|
435
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
436
|
+
constructor: {
|
|
437
|
+
value: Wrapper,
|
|
438
|
+
enumerable: false,
|
|
439
|
+
writable: true,
|
|
440
|
+
configurable: true
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
444
|
+
};
|
|
445
|
+
return _wrapNativeSuper(Class);
|
|
446
|
+
}
|
|
447
|
+
function _assertThisInitialized(self) {
|
|
448
|
+
if (self === void 0) {
|
|
449
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
450
|
+
}
|
|
451
|
+
return self;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
var RANGO_DAPP_ID_QUERY = process.env.REACT_APP_RANGO_DAPP_ID_QUERY;
|
|
455
|
+
var BASE_URL = process.env.REACT_APP_BASE_URL;
|
|
456
|
+
var RANGO_COOKIE_HEADER = 'X-Rango-Id';
|
|
457
|
+
var ERROR_MESSAGE_WAIT_FOR_WALLET = 'Waiting for connecting wallet';
|
|
458
|
+
var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address) {
|
|
459
|
+
return "Please change your " + (type || 'wallet') + " account to " + (address || 'proper address');
|
|
460
|
+
};
|
|
461
|
+
var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) {
|
|
462
|
+
return "Please connect to " + (type || 'your wallet') + " by using bellow button or top right button on page.";
|
|
463
|
+
};
|
|
464
|
+
var ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK = function ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(network) {
|
|
465
|
+
return "Please change your network to " + network + ".";
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
var APIErrorCode;
|
|
469
|
+
(function (APIErrorCode) {
|
|
470
|
+
APIErrorCode["TX_FAIL"] = "TX_FAIL";
|
|
471
|
+
APIErrorCode["FETCH_TX_FAILED"] = "FETCH_TX_FAILED";
|
|
472
|
+
APIErrorCode["USER_REJECT"] = "USER_REJECT";
|
|
473
|
+
APIErrorCode["CALL_WALLET_FAILED"] = "CALL_WALLET_FAILED";
|
|
474
|
+
APIErrorCode["SEND_TX_FAILED"] = "SEND_TX_FAILED";
|
|
475
|
+
APIErrorCode["CALL_OR_SEND_FAILED"] = "CALL_OR_SEND_FAILED";
|
|
476
|
+
APIErrorCode["USER_CANCEL"] = "USER_CANCEL";
|
|
477
|
+
APIErrorCode["CLIENT_UNEXPECTED_BEHAVIOUR"] = "CLIENT_UNEXPECTED_BEHAVIOUR";
|
|
478
|
+
})(APIErrorCode || (APIErrorCode = {}));
|
|
479
|
+
var ApiMethodName;
|
|
480
|
+
(function (ApiMethodName) {
|
|
481
|
+
ApiMethodName["RequestingSwapTransaction"] = "Requesting Swap Transaction";
|
|
482
|
+
ApiMethodName["CreatingSwap"] = "Creating Swap";
|
|
483
|
+
ApiMethodName["CheckingTransactionStatus"] = "Checking transaction status";
|
|
484
|
+
ApiMethodName["CreateTransaction"] = "Create Transaction";
|
|
485
|
+
ApiMethodName["CheckApproval"] = "Check TX Approval";
|
|
486
|
+
ApiMethodName["GettingSwapDetail"] = "Getting Swap Detail";
|
|
487
|
+
ApiMethodName["GettingUserLimits"] = "Getting user limits";
|
|
488
|
+
})(ApiMethodName || (ApiMethodName = {}));
|
|
489
|
+
var TransactionName;
|
|
490
|
+
(function (TransactionName) {
|
|
491
|
+
TransactionName["GenericTransaction"] = "transaction";
|
|
492
|
+
TransactionName["SendingOneInchTransaction"] = "1inch transaction";
|
|
493
|
+
TransactionName["Approval"] = "approve transaction";
|
|
494
|
+
})(TransactionName || (TransactionName = {}));
|
|
495
|
+
var ERROR_ASSERTION_FAILED = 'Assertion failed (Unexpected behaviour)';
|
|
496
|
+
var ERROR_COMMUNICATING_WITH_API = function ERROR_COMMUNICATING_WITH_API(apiMethodName) {
|
|
497
|
+
return "Unexpected response from API (" + apiMethodName + ")";
|
|
498
|
+
};
|
|
499
|
+
var ERROR_CREATE_TRANSACTION = 'Create transaction failed in Rango Server';
|
|
500
|
+
var ERROR_INPUT_WALLET_NOT_FOUND = 'Input wallet not found';
|
|
501
|
+
var PrettyError = /*#__PURE__*/function (_Error) {
|
|
502
|
+
_inheritsLoose(PrettyError, _Error);
|
|
503
|
+
function PrettyError(code, m, root, detail) {
|
|
504
|
+
var _this;
|
|
505
|
+
_this = _Error.call(this, m) || this;
|
|
506
|
+
Object.setPrototypeOf(_assertThisInitialized(_this), PrettyError.prototype);
|
|
507
|
+
_this.code = code;
|
|
508
|
+
_this.detail = detail;
|
|
509
|
+
_this.root = root;
|
|
510
|
+
return _this;
|
|
511
|
+
}
|
|
512
|
+
var _proto = PrettyError.prototype;
|
|
513
|
+
_proto.getErrorDetail = function getErrorDetail() {
|
|
514
|
+
var rawMessage = typeof this.root === 'object' && this.root && this.root.error ? this.root.error : JSON.stringify(this.root);
|
|
515
|
+
var rootStr = typeof this.root === 'string' ? this.root : this.root instanceof Error ? this.root.message : rawMessage;
|
|
516
|
+
return {
|
|
517
|
+
extraMessage: this.message,
|
|
518
|
+
extraMessageDetail: this.detail || rootStr,
|
|
519
|
+
extraMessageErrorCode: this.code || null
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
PrettyError.AssertionFailed = function AssertionFailed(m) {
|
|
523
|
+
return new PrettyError(APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR, ERROR_ASSERTION_FAILED, m);
|
|
524
|
+
};
|
|
525
|
+
PrettyError.BadStatusCode = function BadStatusCode(message, statusCode) {
|
|
526
|
+
return new PrettyError(APIErrorCode.TX_FAIL, message, null, "status code = " + statusCode);
|
|
527
|
+
};
|
|
528
|
+
PrettyError.CreateTransaction = function CreateTransaction(detail) {
|
|
529
|
+
return new PrettyError(APIErrorCode.FETCH_TX_FAILED, ERROR_CREATE_TRANSACTION, null, detail);
|
|
530
|
+
};
|
|
531
|
+
PrettyError.WalletMissing = function WalletMissing() {
|
|
532
|
+
return new PrettyError(APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR, ERROR_INPUT_WALLET_NOT_FOUND, null, 'Server requested for a blockchain or address not selected by user');
|
|
533
|
+
};
|
|
534
|
+
PrettyError.BlockchainMissing = function BlockchainMissing() {
|
|
535
|
+
return new PrettyError(APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR, ERROR_INPUT_WALLET_NOT_FOUND, null, 'Server requested for a blockchain or address not selected by user');
|
|
536
|
+
};
|
|
537
|
+
return PrettyError;
|
|
538
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
539
|
+
|
|
540
|
+
var PendingSwapNetworkStatus;
|
|
541
|
+
(function (PendingSwapNetworkStatus) {
|
|
542
|
+
PendingSwapNetworkStatus["WaitingForConnectingWallet"] = "waitingForConnectingWallet";
|
|
543
|
+
PendingSwapNetworkStatus["WaitingForQueue"] = "waitingForQueue";
|
|
544
|
+
PendingSwapNetworkStatus["WaitingForNetworkChange"] = "waitingForNetworkChange";
|
|
545
|
+
PendingSwapNetworkStatus["NetworkChanged"] = "networkChanged";
|
|
546
|
+
})(PendingSwapNetworkStatus || (PendingSwapNetworkStatus = {}));
|
|
547
|
+
var MessageSeverity;
|
|
548
|
+
(function (MessageSeverity) {
|
|
549
|
+
MessageSeverity["error"] = "error";
|
|
550
|
+
MessageSeverity["warning"] = "warning";
|
|
551
|
+
MessageSeverity["info"] = "info";
|
|
552
|
+
MessageSeverity["success"] = "success";
|
|
553
|
+
})(MessageSeverity || (MessageSeverity = {}));
|
|
554
|
+
var getCurrentBlockchainOfOrNull = function getCurrentBlockchainOfOrNull(swap, step) {
|
|
555
|
+
try {
|
|
556
|
+
return getCurrentBlockchainOf(swap, step);
|
|
557
|
+
} catch (e) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
var getCurrentBlockchainOf = function getCurrentBlockchainOf(swap, step) {
|
|
562
|
+
var _step$evmTransaction, _step$evmApprovalTran, _step$starknetTransac, _step$starknetApprova, _step$tronTransaction, _step$tronApprovalTra, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac;
|
|
563
|
+
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);
|
|
564
|
+
if (!!b1) return b1;
|
|
565
|
+
var transferAddress = (_step$transferTransac = step.transferTransaction) == null ? void 0 : _step$transferTransac.fromWalletAddress;
|
|
566
|
+
if (!transferAddress) throw PrettyError.BlockchainMissing();
|
|
567
|
+
var blockchain = Object.keys(swap.wallets).find(function (b) {
|
|
568
|
+
var _swap$wallets$b;
|
|
569
|
+
return ((_swap$wallets$b = swap.wallets[b]) == null ? void 0 : _swap$wallets$b.address) === transferAddress;
|
|
570
|
+
}) || null;
|
|
571
|
+
if (blockchain == null) throw PrettyError.BlockchainMissing();
|
|
572
|
+
// TODO: check why it returns string
|
|
573
|
+
return blockchain;
|
|
574
|
+
};
|
|
575
|
+
var getEvmApproveUrl = function getEvmApproveUrl(tx, network, evmBasedBlockchains) {
|
|
576
|
+
var evmBlochain = evmBasedBlockchains.find(function (blockchain) {
|
|
577
|
+
return blockchain.name === network;
|
|
578
|
+
});
|
|
579
|
+
if (!evmBlochain) {
|
|
580
|
+
throw Error("unsupported network: " + network + " for getting approve url.");
|
|
581
|
+
}
|
|
582
|
+
if (evmBlochain.info.transactionUrl) return evmBlochain.info.transactionUrl.replace('{txHash}', tx.toLowerCase());
|
|
583
|
+
throw Error("Explorer url for " + network + " is not implemented");
|
|
584
|
+
};
|
|
585
|
+
var prettifyErrorMessage = function prettifyErrorMessage(obj) {
|
|
586
|
+
if (!obj) return {
|
|
587
|
+
extraMessage: '',
|
|
588
|
+
extraMessageErrorCode: null
|
|
589
|
+
};
|
|
590
|
+
if (obj instanceof PrettyError) return obj.getErrorDetail();
|
|
591
|
+
if (obj instanceof walletsShared.WalletError) {
|
|
592
|
+
var t = obj.getErrorDetail();
|
|
593
|
+
return {
|
|
594
|
+
extraMessage: t.message,
|
|
595
|
+
extraMessageDetail: t.detail,
|
|
596
|
+
extraMessageErrorCode: t.code
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
if (obj instanceof Error) return {
|
|
600
|
+
extraMessage: obj.toString(),
|
|
601
|
+
extraMessageErrorCode: null
|
|
602
|
+
};
|
|
603
|
+
if (typeof obj !== 'string') return {
|
|
604
|
+
extraMessage: JSON.stringify(obj),
|
|
605
|
+
extraMessageErrorCode: null
|
|
606
|
+
};
|
|
607
|
+
return {
|
|
608
|
+
extraMessage: obj,
|
|
609
|
+
extraMessageErrorCode: null
|
|
610
|
+
};
|
|
611
|
+
};
|
|
612
|
+
function getCookieId() {
|
|
613
|
+
var key = 'X-Rango-Id';
|
|
614
|
+
var cookieId = window.localStorage.getItem(key);
|
|
615
|
+
if (cookieId) {
|
|
616
|
+
return cookieId;
|
|
617
|
+
}
|
|
618
|
+
var value = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
619
|
+
window.localStorage.setItem(key, value);
|
|
620
|
+
return value;
|
|
621
|
+
}
|
|
622
|
+
function getNextStep(swap, currentStep) {
|
|
623
|
+
return swap.steps.find(function (step) {
|
|
624
|
+
return step.status !== 'failed' && step.status !== 'success' && step.id !== currentStep.id;
|
|
625
|
+
}) || null;
|
|
626
|
+
}
|
|
627
|
+
function getRelatedWalletOrNull(swap, currentStep) {
|
|
628
|
+
try {
|
|
629
|
+
return getRelatedWallet(swap, currentStep);
|
|
630
|
+
} catch (e) {
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function logRPCError(error, swap, currentStep, walletType) {
|
|
636
|
+
try {
|
|
637
|
+
Sentry.captureException(error, {
|
|
638
|
+
tags: {
|
|
639
|
+
requestId: swap.requestId,
|
|
640
|
+
rpc: true,
|
|
641
|
+
swapper: (currentStep == null ? void 0 : currentStep.swapperId) || '',
|
|
642
|
+
walletType: walletType || ''
|
|
643
|
+
},
|
|
644
|
+
level: 'warning'
|
|
645
|
+
});
|
|
646
|
+
} catch (e) {
|
|
647
|
+
console.log({
|
|
648
|
+
e: e
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function checkSwapStatus(_x, _x2, _x3) {
|
|
654
|
+
return _checkSwapStatus.apply(this, arguments);
|
|
655
|
+
}
|
|
656
|
+
function _checkSwapStatus() {
|
|
657
|
+
_checkSwapStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestId, txId, step) {
|
|
658
|
+
var _headers;
|
|
659
|
+
var url, body, response, apiError, res;
|
|
660
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
661
|
+
while (1) switch (_context.prev = _context.next) {
|
|
662
|
+
case 0:
|
|
663
|
+
url = BASE_URL + "/tx/check-status?" + RANGO_DAPP_ID_QUERY;
|
|
664
|
+
body = {
|
|
665
|
+
step: step,
|
|
666
|
+
txId: txId,
|
|
667
|
+
requestId: requestId
|
|
668
|
+
};
|
|
669
|
+
_context.next = 4;
|
|
670
|
+
return fetch(url, {
|
|
671
|
+
method: 'POST',
|
|
672
|
+
headers: (_headers = {}, _headers[RANGO_COOKIE_HEADER] = getCookieId(), _headers['content-type'] = 'application/json;charset=UTF-8', _headers),
|
|
673
|
+
body: JSON.stringify(body)
|
|
674
|
+
});
|
|
675
|
+
case 4:
|
|
676
|
+
response = _context.sent;
|
|
677
|
+
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
678
|
+
_context.next = 8;
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckingTransactionStatus);
|
|
682
|
+
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
683
|
+
case 8:
|
|
684
|
+
_context.next = 10;
|
|
685
|
+
return response.json();
|
|
686
|
+
case 10:
|
|
687
|
+
res = _context.sent;
|
|
688
|
+
return _context.abrupt("return", _extends({}, res, {
|
|
689
|
+
outputAmount: res.outputAmount ? new BigNumber.BigNumber(res.outputAmount) : null
|
|
690
|
+
}));
|
|
691
|
+
case 12:
|
|
692
|
+
case "end":
|
|
693
|
+
return _context.stop();
|
|
694
|
+
}
|
|
695
|
+
}, _callee);
|
|
696
|
+
}));
|
|
697
|
+
return _checkSwapStatus.apply(this, arguments);
|
|
698
|
+
}
|
|
699
|
+
function createTransaction(_x4) {
|
|
700
|
+
return _createTransaction.apply(this, arguments);
|
|
701
|
+
}
|
|
702
|
+
function _createTransaction() {
|
|
703
|
+
_createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(request) {
|
|
704
|
+
var url, _headers2, response, result;
|
|
705
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
706
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
707
|
+
case 0:
|
|
708
|
+
url = BASE_URL + "/tx/create?" + RANGO_DAPP_ID_QUERY;
|
|
709
|
+
_context2.prev = 1;
|
|
710
|
+
_context2.next = 4;
|
|
711
|
+
return fetch(url, {
|
|
712
|
+
method: 'POST',
|
|
713
|
+
headers: (_headers2 = {
|
|
714
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
715
|
+
}, _headers2[RANGO_COOKIE_HEADER] = getCookieId(), _headers2),
|
|
716
|
+
body: JSON.stringify(request)
|
|
717
|
+
});
|
|
718
|
+
case 4:
|
|
719
|
+
response = _context2.sent;
|
|
720
|
+
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
721
|
+
_context2.next = 7;
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
724
|
+
throw PrettyError.CreateTransaction("Error creating the transaction, status code: " + response.status);
|
|
725
|
+
case 7:
|
|
726
|
+
_context2.next = 9;
|
|
727
|
+
return response.json();
|
|
728
|
+
case 9:
|
|
729
|
+
result = _context2.sent;
|
|
730
|
+
if (!(!result.ok || !result.transaction)) {
|
|
731
|
+
_context2.next = 12;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
throw PrettyError.CreateTransaction(result.error || 'bad response from create tx endpoint');
|
|
735
|
+
case 12:
|
|
736
|
+
return _context2.abrupt("return", result);
|
|
737
|
+
case 15:
|
|
738
|
+
_context2.prev = 15;
|
|
739
|
+
_context2.t0 = _context2["catch"](1);
|
|
740
|
+
if (!(_context2.t0 instanceof Error)) {
|
|
741
|
+
_context2.next = 19;
|
|
742
|
+
break;
|
|
743
|
+
}
|
|
744
|
+
throw PrettyError.CreateTransaction(_context2.t0.message);
|
|
745
|
+
case 19:
|
|
746
|
+
throw _context2.t0;
|
|
747
|
+
case 20:
|
|
748
|
+
case "end":
|
|
749
|
+
return _context2.stop();
|
|
750
|
+
}
|
|
751
|
+
}, _callee2, null, [[1, 15]]);
|
|
752
|
+
}));
|
|
753
|
+
return _createTransaction.apply(this, arguments);
|
|
754
|
+
}
|
|
755
|
+
function checkApproved(_x5) {
|
|
756
|
+
return _checkApproved.apply(this, arguments);
|
|
757
|
+
}
|
|
758
|
+
function _checkApproved() {
|
|
759
|
+
_checkApproved = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(requestId) {
|
|
760
|
+
var _headers3;
|
|
761
|
+
var url, response, apiError;
|
|
762
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
763
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
764
|
+
case 0:
|
|
765
|
+
url = BASE_URL + "/tx/" + requestId + "/check-approval?" + RANGO_DAPP_ID_QUERY;
|
|
766
|
+
_context3.next = 3;
|
|
767
|
+
return fetch(url, {
|
|
768
|
+
method: 'GET',
|
|
769
|
+
headers: (_headers3 = {
|
|
770
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
771
|
+
}, _headers3[RANGO_COOKIE_HEADER] = getCookieId(), _headers3)
|
|
772
|
+
});
|
|
773
|
+
case 3:
|
|
774
|
+
response = _context3.sent;
|
|
775
|
+
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
776
|
+
_context3.next = 7;
|
|
777
|
+
break;
|
|
778
|
+
}
|
|
779
|
+
apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckApproval);
|
|
780
|
+
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
781
|
+
case 7:
|
|
782
|
+
_context3.next = 9;
|
|
783
|
+
return response.json();
|
|
784
|
+
case 9:
|
|
785
|
+
return _context3.abrupt("return", _context3.sent);
|
|
786
|
+
case 10:
|
|
787
|
+
case "end":
|
|
788
|
+
return _context3.stop();
|
|
789
|
+
}
|
|
790
|
+
}, _callee3);
|
|
791
|
+
}));
|
|
792
|
+
return _checkApproved.apply(this, arguments);
|
|
793
|
+
}
|
|
794
|
+
function isAPIErrorCode(value) {
|
|
795
|
+
return Object.values(APIErrorCode).includes(value);
|
|
796
|
+
}
|
|
797
|
+
function mapAppErrorCodesToAPIErrorCode(errorCode) {
|
|
798
|
+
var defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
|
|
799
|
+
try {
|
|
800
|
+
if (!errorCode) return defaultErrorCode;
|
|
801
|
+
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
802
|
+
if (walletsShared.isWalletErrorCode(errorCode)) {
|
|
803
|
+
var _t;
|
|
804
|
+
var t = (_t = {}, _t[walletsShared.WalletErrorCode.REJECTED_BY_USER] = APIErrorCode.USER_REJECT, _t[walletsShared.WalletErrorCode.SIGN_TX_ERROR] = APIErrorCode.CALL_WALLET_FAILED, _t[walletsShared.WalletErrorCode.SEND_TX_ERROR] = APIErrorCode.SEND_TX_FAILED, _t[walletsShared.WalletErrorCode.NOT_IMPLEMENTED] = defaultErrorCode, _t[walletsShared.WalletErrorCode.OPERATION_UNSUPPORTED] = defaultErrorCode, _t[walletsShared.WalletErrorCode.UNEXPECTED_BEHAVIOUR] = defaultErrorCode, _t);
|
|
805
|
+
return t[errorCode];
|
|
806
|
+
}
|
|
807
|
+
return defaultErrorCode;
|
|
808
|
+
} catch (err) {
|
|
809
|
+
return defaultErrorCode;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
function reportFailed(_x6, _x7, _x8, _x9, _x10) {
|
|
813
|
+
return _reportFailed.apply(this, arguments);
|
|
814
|
+
}
|
|
815
|
+
function _reportFailed() {
|
|
816
|
+
_reportFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(requestId, step, eventType, reason, walletType) {
|
|
817
|
+
var _headers4;
|
|
818
|
+
var url;
|
|
819
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
820
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
821
|
+
case 0:
|
|
822
|
+
url = BASE_URL + "/tx/report-tx?" + RANGO_DAPP_ID_QUERY;
|
|
823
|
+
_context4.next = 3;
|
|
824
|
+
return fetch(url, {
|
|
825
|
+
method: 'POST',
|
|
826
|
+
headers: (_headers4 = {
|
|
827
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
828
|
+
}, _headers4[RANGO_COOKIE_HEADER] = getCookieId(), _headers4),
|
|
829
|
+
body: JSON.stringify({
|
|
830
|
+
requestId: requestId,
|
|
831
|
+
step: step,
|
|
832
|
+
eventType: eventType,
|
|
833
|
+
reason: reason,
|
|
834
|
+
tags: {
|
|
835
|
+
wallet: walletType
|
|
836
|
+
}
|
|
837
|
+
})
|
|
838
|
+
});
|
|
839
|
+
case 3:
|
|
840
|
+
case "end":
|
|
841
|
+
return _context4.stop();
|
|
842
|
+
}
|
|
843
|
+
}, _callee4);
|
|
844
|
+
}));
|
|
845
|
+
return _reportFailed.apply(this, arguments);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
var swapClaimedBy = null;
|
|
849
|
+
/**
|
|
850
|
+
*
|
|
851
|
+
* We simply use module-level variable to keep track of which queue has claimed the execution of parallel runnings.
|
|
852
|
+
*
|
|
853
|
+
*/
|
|
854
|
+
function claimQueue() {
|
|
855
|
+
return {
|
|
856
|
+
claimedBy: function claimedBy() {
|
|
857
|
+
var _swapClaimedBy;
|
|
858
|
+
return (_swapClaimedBy = swapClaimedBy) == null ? void 0 : _swapClaimedBy.id;
|
|
859
|
+
},
|
|
860
|
+
setClaimer: function setClaimer(queue_id) {
|
|
861
|
+
swapClaimedBy = {
|
|
862
|
+
id: queue_id
|
|
863
|
+
};
|
|
864
|
+
},
|
|
865
|
+
reset: function reset() {
|
|
866
|
+
swapClaimedBy = null;
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
*
|
|
872
|
+
* Returns `steps`, if it's a `running` swap.
|
|
873
|
+
* Each `PendingSwap` has a `steps` inside it, `steps` shows how many tasks should be created and run to finish the swap.
|
|
874
|
+
*
|
|
875
|
+
*/
|
|
876
|
+
var getCurrentStep = function getCurrentStep(swap) {
|
|
877
|
+
return swap.steps.find(function (step) {
|
|
878
|
+
return step.status !== 'failed' && step.status !== 'success';
|
|
879
|
+
}) || null;
|
|
880
|
+
};
|
|
881
|
+
/**
|
|
882
|
+
* When we are doing a swap, there are some common fields that will be updated together.
|
|
883
|
+
* This function helps us to update a swap status and also it will update some more fields like `extraMessageSeverity` based on the input.
|
|
884
|
+
*/
|
|
885
|
+
function updateSwapStatus(_ref) {
|
|
886
|
+
var getStorage = _ref.getStorage,
|
|
887
|
+
setStorage = _ref.setStorage,
|
|
888
|
+
nextStatus = _ref.nextStatus,
|
|
889
|
+
nextStepStatus = _ref.nextStepStatus,
|
|
890
|
+
message = _ref.message,
|
|
891
|
+
details = _ref.details,
|
|
892
|
+
_ref$errorCode = _ref.errorCode,
|
|
893
|
+
errorCode = _ref$errorCode === void 0 ? null : _ref$errorCode;
|
|
894
|
+
var swap = getStorage().swapDetails;
|
|
895
|
+
var currentStep = getCurrentStep(swap);
|
|
896
|
+
if (!!nextStepStatus && !!currentStep) currentStep.status = nextStepStatus;
|
|
897
|
+
if (!!nextStatus) swap.status = nextStatus;
|
|
898
|
+
if (!!nextStatus && ['failed', 'success'].includes(nextStatus)) swap.finishTime = new Date().getTime().toString();
|
|
899
|
+
if (!!message) swap.extraMessage = message;
|
|
900
|
+
if (!!details) swap.extraMessageDetail = details;
|
|
901
|
+
if (!!nextStepStatus && ['failed'].includes(nextStepStatus)) {
|
|
902
|
+
var _getRelatedWalletOrNu;
|
|
903
|
+
//if user cancel the swap, we should pass relevant reason to the server.
|
|
904
|
+
var errorReason = details && details.includes('Warning') ? 'Swap canceled by user.' : details;
|
|
905
|
+
swap.extraMessageSeverity = MessageSeverity.error;
|
|
906
|
+
reportFailed(swap.requestId, (currentStep == null ? void 0 : currentStep.id) || 1, mapAppErrorCodesToAPIErrorCode(errorCode), errorReason || '', (currentStep ? (_getRelatedWalletOrNu = getRelatedWalletOrNull(swap, currentStep)) == null ? void 0 : _getRelatedWalletOrNu.walletType : null) || null).then();
|
|
907
|
+
} else if (!!nextStepStatus && ['running'].includes(nextStepStatus)) swap.extraMessageSeverity = MessageSeverity.info;else if (!!nextStepStatus && ['success', 'approved'].includes(nextStepStatus)) swap.extraMessageSeverity = MessageSeverity.success;else if (nextStepStatus && ['waitingForApproval'].includes(nextStepStatus)) swap.extraMessageSeverity = MessageSeverity.warning;
|
|
908
|
+
if (nextStepStatus === 'running' && currentStep) currentStep.startTransactionTime = new Date().getTime();
|
|
909
|
+
setStorage(_extends({}, getStorage(), {
|
|
910
|
+
swapDetails: swap
|
|
911
|
+
}));
|
|
912
|
+
return {
|
|
913
|
+
swap: swap,
|
|
914
|
+
step: currentStep
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
function setStepTransactionIds(_ref2, txId, eventType, notifier) {
|
|
918
|
+
var getStorage = _ref2.getStorage,
|
|
919
|
+
setStorage = _ref2.setStorage;
|
|
920
|
+
var swap = getStorage().swapDetails;
|
|
921
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
922
|
+
var currentStep = getCurrentStep(swap);
|
|
923
|
+
currentStep.executedTransactionId = txId || currentStep.executedTransactionId;
|
|
924
|
+
setStorage(_extends({}, getStorage(), {
|
|
925
|
+
swapDetails: swap
|
|
926
|
+
}));
|
|
927
|
+
notifier({
|
|
928
|
+
eventType: eventType,
|
|
929
|
+
swap: swap,
|
|
930
|
+
step: currentStep
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* If a swap needs a wallet to be connected,
|
|
935
|
+
* By calling this function some related fields will be updated to show a correct message and state for notfiying the user.
|
|
936
|
+
*/
|
|
937
|
+
function markRunningSwapAsWaitingForConnectingWallet(_ref3, reason, reasonDetail) {
|
|
938
|
+
var getStorage = _ref3.getStorage,
|
|
939
|
+
setStorage = _ref3.setStorage;
|
|
940
|
+
var swap = getStorage().swapDetails;
|
|
941
|
+
var currentStep = getCurrentStep(swap);
|
|
942
|
+
if (!currentStep) return;
|
|
943
|
+
var currentTime = new Date();
|
|
944
|
+
swap.lastNotificationTime = currentTime.getTime().toString();
|
|
945
|
+
var isAlreadyMarked = currentStep.networkStatus === PendingSwapNetworkStatus.WaitingForConnectingWallet && swap.networkStatusExtraMessage === reason && swap.networkStatusExtraMessageDetail === reasonDetail;
|
|
946
|
+
if (isAlreadyMarked) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
currentStep.networkStatus = PendingSwapNetworkStatus.WaitingForConnectingWallet;
|
|
950
|
+
swap.networkStatusExtraMessage = reason;
|
|
951
|
+
swap.networkStatusExtraMessageDetail = reasonDetail;
|
|
952
|
+
setStorage(_extends({}, getStorage(), {
|
|
953
|
+
swapDetails: swap
|
|
954
|
+
}));
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* If a swap needs a certain network to proceed,
|
|
958
|
+
* By calling this function some related fields will be updated to show a correct message and state for notfiying the user.
|
|
959
|
+
*/
|
|
960
|
+
function markRunningSwapAsSwitchingNetwork(_ref4) {
|
|
961
|
+
var getStorage = _ref4.getStorage,
|
|
962
|
+
setStorage = _ref4.setStorage;
|
|
963
|
+
var swap = getStorage().swapDetails;
|
|
964
|
+
var currentStep = getCurrentStep(swap);
|
|
965
|
+
if (!currentStep) return;
|
|
966
|
+
// Generate message
|
|
967
|
+
var _getRequiredWallet = getRequiredWallet(swap),
|
|
968
|
+
type = _getRequiredWallet.type;
|
|
969
|
+
var fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
|
|
970
|
+
var reason = "Change " + type + " wallet network to " + fromBlockchain;
|
|
971
|
+
var metamaskMessage = '';
|
|
972
|
+
if (type === walletsShared.WalletType.META_MASK) metamaskMessage = "(Networks -> Select '" + fromBlockchain + "' network.)";
|
|
973
|
+
var reasonDetail = "Please change your " + type + " wallet network to " + fromBlockchain + ". " + metamaskMessage;
|
|
974
|
+
var currentTime = new Date();
|
|
975
|
+
swap.lastNotificationTime = currentTime.getTime().toString();
|
|
976
|
+
currentStep.networkStatus = PendingSwapNetworkStatus.WaitingForNetworkChange;
|
|
977
|
+
swap.networkStatusExtraMessage = reason;
|
|
978
|
+
swap.networkStatusExtraMessageDetail = reasonDetail;
|
|
979
|
+
setStorage(_extends({}, getStorage(), {
|
|
980
|
+
swapDetails: swap
|
|
981
|
+
}));
|
|
982
|
+
return {
|
|
983
|
+
swap: swap,
|
|
984
|
+
step: currentStep
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* We are marking the queue as it depends on other queues to be run (on Parallel mode)
|
|
989
|
+
* By calling this function some related fields will be updated to show a correct message and state for notfiying the user.
|
|
990
|
+
*/
|
|
991
|
+
function markRunningSwapAsDependsOnOtherQueues(_ref5) {
|
|
992
|
+
var getStorage = _ref5.getStorage,
|
|
993
|
+
setStorage = _ref5.setStorage;
|
|
994
|
+
var swap = getStorage().swapDetails;
|
|
995
|
+
var currentStep = getCurrentStep(swap);
|
|
996
|
+
if (!currentStep) return;
|
|
997
|
+
swap.networkStatusExtraMessage = '';
|
|
998
|
+
swap.networkStatusExtraMessageDetail = '';
|
|
999
|
+
currentStep.networkStatus = PendingSwapNetworkStatus.WaitingForQueue;
|
|
1000
|
+
setStorage(_extends({}, getStorage(), {
|
|
1001
|
+
swapDetails: swap
|
|
1002
|
+
}));
|
|
1003
|
+
return {
|
|
1004
|
+
swap: swap,
|
|
1005
|
+
step: currentStep
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
function delay(ms) {
|
|
1009
|
+
return new Promise(function (res) {
|
|
1010
|
+
return setTimeout(res, ms);
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
var isEvmTransaction = function isEvmTransaction(tx) {
|
|
1014
|
+
return tx.type === walletsShared.TransactionType.EVM;
|
|
1015
|
+
};
|
|
1016
|
+
var isCosmosTransaction = function isCosmosTransaction(tx) {
|
|
1017
|
+
return tx.type === walletsShared.TransactionType.COSMOS;
|
|
1018
|
+
};
|
|
1019
|
+
var isSolanaTransaction = function isSolanaTransaction(tx) {
|
|
1020
|
+
return tx.type === walletsShared.TransactionType.SOLANA;
|
|
1021
|
+
};
|
|
1022
|
+
var isTrasnferTransaction = function isTrasnferTransaction(tx) {
|
|
1023
|
+
return tx.type === walletsShared.TransactionType.TRANSFER;
|
|
1024
|
+
};
|
|
1025
|
+
var isStarknetTransaction = function isStarknetTransaction(tx) {
|
|
1026
|
+
return tx.type === walletsShared.TransactionType.STARKNET;
|
|
1027
|
+
};
|
|
1028
|
+
var isTronTransaction = function isTronTransaction(tx) {
|
|
1029
|
+
return tx.type === walletsShared.TransactionType.TRON;
|
|
1030
|
+
};
|
|
1031
|
+
/**
|
|
1032
|
+
*
|
|
1033
|
+
* To execute a swap, we are keeping the user prefrences on what wallet they are going to use for a sepecific blockchain
|
|
1034
|
+
* By passing the swap and the network we are looking for, it returns the wallet name that user selected.
|
|
1035
|
+
*
|
|
1036
|
+
*/
|
|
1037
|
+
var getSwapWalletType = function getSwapWalletType(swap, network) {
|
|
1038
|
+
var _swap$wallets$network;
|
|
1039
|
+
return (_swap$wallets$network = swap.wallets[network]) == null ? void 0 : _swap$wallets$network.walletType;
|
|
1040
|
+
};
|
|
1041
|
+
/**
|
|
1042
|
+
*
|
|
1043
|
+
* We are keeping the connected wallet in a specific structure (`Wallet`),
|
|
1044
|
+
* By using this function we normally want to check a specific wallet is connected and exists or not.
|
|
1045
|
+
*
|
|
1046
|
+
*/
|
|
1047
|
+
function isWalletNull(wallet) {
|
|
1048
|
+
return wallet === null || (wallet == null ? void 0 : wallet.blockchains) === null || (wallet == null ? void 0 : wallet.blockchains.length) === 0;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* On our implementation for `wallets` package, We keep the instance in 2 ways
|
|
1052
|
+
* If it's a single chain wallet, it returns the instance directly,
|
|
1053
|
+
* If it's a multichain wallet, it returns a `Map` of instances.
|
|
1054
|
+
* This function will get the `ETHEREUM` instance in both types.
|
|
1055
|
+
*/
|
|
1056
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1057
|
+
function getEvmProvider(providers, type) {
|
|
1058
|
+
if (type && providers[type]) {
|
|
1059
|
+
// 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.
|
|
1060
|
+
if (providers[type].size) return providers[type].get(walletsShared.Network.ETHEREUM);
|
|
1061
|
+
return providers[type];
|
|
1062
|
+
}
|
|
1063
|
+
return null;
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* In a `PendingSwap`, each step needs a wallet to proceed,
|
|
1067
|
+
* By using this function we can access what wallet exactly we need to run current step.
|
|
1068
|
+
*/
|
|
1069
|
+
function getRequiredWallet(swap) {
|
|
1070
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1071
|
+
var step = getCurrentStep(swap);
|
|
1072
|
+
var bcName = getCurrentBlockchainOfOrNull(swap, step);
|
|
1073
|
+
if (!bcName) {
|
|
1074
|
+
return {
|
|
1075
|
+
type: null,
|
|
1076
|
+
network: null,
|
|
1077
|
+
address: null
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
var walletType = getSwapWalletType(swap, bcName);
|
|
1081
|
+
var sourceWallet = swap.wallets[bcName];
|
|
1082
|
+
return {
|
|
1083
|
+
type: walletType || null,
|
|
1084
|
+
network: bcName,
|
|
1085
|
+
address: sourceWallet ? sourceWallet.address : null
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* On EVM compatible wallets, There is one instance with different chains (like Polygon)
|
|
1090
|
+
* To get the chain from instance we will use this function.
|
|
1091
|
+
*/
|
|
1092
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1093
|
+
function getChainId(_x) {
|
|
1094
|
+
return _getChainId.apply(this, arguments);
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* For running a swap safely, we need to make sure about the state of wallet
|
|
1098
|
+
* which means the netowrk/chain of wallet should be exactly on what a transaction needs.
|
|
1099
|
+
*/
|
|
1100
|
+
function _getChainId() {
|
|
1101
|
+
_getChainId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(provider) {
|
|
1102
|
+
var chainId;
|
|
1103
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1104
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1105
|
+
case 0:
|
|
1106
|
+
_context.next = 2;
|
|
1107
|
+
return provider.request({
|
|
1108
|
+
method: 'eth_chainId'
|
|
1109
|
+
});
|
|
1110
|
+
case 2:
|
|
1111
|
+
_context.t0 = _context.sent;
|
|
1112
|
+
if (_context.t0) {
|
|
1113
|
+
_context.next = 5;
|
|
1114
|
+
break;
|
|
1115
|
+
}
|
|
1116
|
+
_context.t0 = provider == null ? void 0 : provider.chainId;
|
|
1117
|
+
case 5:
|
|
1118
|
+
chainId = _context.t0;
|
|
1119
|
+
return _context.abrupt("return", chainId);
|
|
1120
|
+
case 7:
|
|
1121
|
+
case "end":
|
|
1122
|
+
return _context.stop();
|
|
1123
|
+
}
|
|
1124
|
+
}, _callee);
|
|
1125
|
+
}));
|
|
1126
|
+
return _getChainId.apply(this, arguments);
|
|
1127
|
+
}
|
|
1128
|
+
function isNetworkMatchedForTransaction(_x2, _x3, _x4, _x5, _x6) {
|
|
1129
|
+
return _isNetworkMatchedForTransaction.apply(this, arguments);
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Returns the wallet address, based on the current step of `PendingSwap`.
|
|
1133
|
+
*/
|
|
1134
|
+
function _isNetworkMatchedForTransaction() {
|
|
1135
|
+
_isNetworkMatchedForTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(swap, step, wallet, meta, providers) {
|
|
1136
|
+
var fromBlockChain, sourceWallet, provider, chainId, blockChain;
|
|
1137
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1138
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1139
|
+
case 0:
|
|
1140
|
+
if (!isWalletNull(wallet)) {
|
|
1141
|
+
_context2.next = 3;
|
|
1142
|
+
break;
|
|
1143
|
+
}
|
|
1144
|
+
console.warn('wallet object is null');
|
|
1145
|
+
return _context2.abrupt("return", false);
|
|
1146
|
+
case 3:
|
|
1147
|
+
fromBlockChain = getCurrentBlockchainOfOrNull(swap, step);
|
|
1148
|
+
if (fromBlockChain) {
|
|
1149
|
+
_context2.next = 6;
|
|
1150
|
+
break;
|
|
1151
|
+
}
|
|
1152
|
+
return _context2.abrupt("return", false);
|
|
1153
|
+
case 6:
|
|
1154
|
+
if (!meta.evmBasedChains.find(function (evmBlochain) {
|
|
1155
|
+
return evmBlochain.name === fromBlockChain;
|
|
1156
|
+
})) {
|
|
1157
|
+
_context2.next = 30;
|
|
1158
|
+
break;
|
|
1159
|
+
}
|
|
1160
|
+
_context2.prev = 7;
|
|
1161
|
+
sourceWallet = swap.wallets[fromBlockChain];
|
|
1162
|
+
if (!sourceWallet) {
|
|
1163
|
+
_context2.next = 24;
|
|
1164
|
+
break;
|
|
1165
|
+
}
|
|
1166
|
+
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].includes(sourceWallet.walletType)) {
|
|
1167
|
+
_context2.next = 23;
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
provider = getEvmProvider(providers, sourceWallet.walletType);
|
|
1171
|
+
_context2.next = 14;
|
|
1172
|
+
return getChainId(provider);
|
|
1173
|
+
case 14:
|
|
1174
|
+
chainId = _context2.sent;
|
|
1175
|
+
if (!chainId) {
|
|
1176
|
+
_context2.next = 21;
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
blockChain = walletsShared.getBlockChainNameFromId(chainId, Object.entries(meta.blockchains).map(function (_ref7) {
|
|
1180
|
+
var blockchainMeta = _ref7[1];
|
|
1181
|
+
return blockchainMeta;
|
|
1182
|
+
}));
|
|
1183
|
+
if (!(blockChain && blockChain.toLowerCase() === fromBlockChain.toLowerCase())) {
|
|
1184
|
+
_context2.next = 19;
|
|
1185
|
+
break;
|
|
1186
|
+
}
|
|
1187
|
+
return _context2.abrupt("return", true);
|
|
1188
|
+
case 19:
|
|
1189
|
+
if (!(blockChain && blockChain.toLowerCase() !== fromBlockChain.toLowerCase())) {
|
|
1190
|
+
_context2.next = 21;
|
|
1191
|
+
break;
|
|
1192
|
+
}
|
|
1193
|
+
return _context2.abrupt("return", false);
|
|
1194
|
+
case 21:
|
|
1195
|
+
_context2.next = 24;
|
|
1196
|
+
break;
|
|
1197
|
+
case 23:
|
|
1198
|
+
return _context2.abrupt("return", true);
|
|
1199
|
+
case 24:
|
|
1200
|
+
_context2.next = 29;
|
|
1201
|
+
break;
|
|
1202
|
+
case 26:
|
|
1203
|
+
_context2.prev = 26;
|
|
1204
|
+
_context2.t0 = _context2["catch"](7);
|
|
1205
|
+
console.log(_context2.t0);
|
|
1206
|
+
case 29:
|
|
1207
|
+
return _context2.abrupt("return", false);
|
|
1208
|
+
case 30:
|
|
1209
|
+
return _context2.abrupt("return", true);
|
|
1210
|
+
case 31:
|
|
1211
|
+
case "end":
|
|
1212
|
+
return _context2.stop();
|
|
1213
|
+
}
|
|
1214
|
+
}, _callee2, null, [[7, 26]]);
|
|
1215
|
+
}));
|
|
1216
|
+
return _isNetworkMatchedForTransaction.apply(this, arguments);
|
|
1217
|
+
}
|
|
1218
|
+
var getCurrentAddressOf = function getCurrentAddressOf(swap, step) {
|
|
1219
|
+
var _step$evmTransaction, _step$evmApprovalTran, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac, _step$transferTransac2;
|
|
1220
|
+
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$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 && _step$transferTransac.fromWalletAddress ? {
|
|
1221
|
+
address: (_step$transferTransac2 = step.transferTransaction) == null ? void 0 : _step$transferTransac2.fromWalletAddress
|
|
1222
|
+
} : null) || null;
|
|
1223
|
+
if (result == null) throw PrettyError.WalletMissing();
|
|
1224
|
+
return result.address;
|
|
1225
|
+
};
|
|
1226
|
+
// Todo: Is it same with `getRequiredWallet`?
|
|
1227
|
+
function getRelatedWallet(swap, currentStep) {
|
|
1228
|
+
var walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
1229
|
+
var walletKV = Object.keys(swap.wallets).map(function (k) {
|
|
1230
|
+
return {
|
|
1231
|
+
k: k,
|
|
1232
|
+
v: swap.wallets[k]
|
|
1233
|
+
};
|
|
1234
|
+
}).find(function (_ref6) {
|
|
1235
|
+
var v = _ref6.v;
|
|
1236
|
+
return v.address === walletAddress;
|
|
1237
|
+
}) || null;
|
|
1238
|
+
var blockchain = (walletKV == null ? void 0 : walletKV.k) || null;
|
|
1239
|
+
var wallet = (walletKV == null ? void 0 : walletKV.v) || null;
|
|
1240
|
+
var walletType = wallet == null ? void 0 : wallet.walletType;
|
|
1241
|
+
if (walletType === walletsShared.WalletType.UNKNOWN || wallet === null) throw PrettyError.AssertionFailed("Wallet for source " + blockchain + " not passed to transfer: walletType: " + walletType);
|
|
1242
|
+
return wallet;
|
|
1243
|
+
}
|
|
1244
|
+
var isTxAlreadyCreated = function isTxAlreadyCreated(swap, step) {
|
|
1245
|
+
var _step$evmTransaction2, _step$evmApprovalTran2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac3;
|
|
1246
|
+
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$cosmosTransacti2 = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti2.blockChain) || ''] || swap.wallets[((_step$solanaTransacti2 = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti2.blockChain) || ''] || ((_step$transferTransac3 = step.transferTransaction) == null ? void 0 : _step$transferTransac3.fromWalletAddress) || null;
|
|
1247
|
+
return result !== null;
|
|
1248
|
+
};
|
|
1249
|
+
function resetNetworkStatus(actions) {
|
|
1250
|
+
var getStorage = actions.getStorage,
|
|
1251
|
+
setStorage = actions.setStorage;
|
|
1252
|
+
var swap = getStorage().swapDetails;
|
|
1253
|
+
var currentStep = getCurrentStep(swap);
|
|
1254
|
+
if (currentStep != null && currentStep.networkStatus) {
|
|
1255
|
+
currentStep.networkStatus = null;
|
|
1256
|
+
setStorage(_extends({}, getStorage(), {
|
|
1257
|
+
swapDetails: swap
|
|
1258
|
+
}));
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
function updateNetworkStatus(actions, data) {
|
|
1262
|
+
if (data === void 0) {
|
|
1263
|
+
data = {
|
|
1264
|
+
message: '',
|
|
1265
|
+
details: '',
|
|
1266
|
+
status: null
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
var _data = data,
|
|
1270
|
+
message = _data.message,
|
|
1271
|
+
details = _data.details,
|
|
1272
|
+
status = _data.status;
|
|
1273
|
+
var getStorage = actions.getStorage,
|
|
1274
|
+
setStorage = actions.setStorage;
|
|
1275
|
+
var swap = getStorage().swapDetails;
|
|
1276
|
+
var currentStep = getCurrentStep(swap);
|
|
1277
|
+
if (currentStep != null && currentStep.networkStatus) {
|
|
1278
|
+
swap.networkStatusExtraMessage = message;
|
|
1279
|
+
swap.networkStatusExtraMessageDetail = details;
|
|
1280
|
+
currentStep.networkStatus = status;
|
|
1281
|
+
setStorage(_extends({}, getStorage(), {
|
|
1282
|
+
swapDetails: swap
|
|
1283
|
+
}));
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Event handler for blocked tasks.
|
|
1288
|
+
* If a transcation execution is manually blocked (like for parallel or waiting for walle),
|
|
1289
|
+
* This function will be called by queue manager using `queue definition`.
|
|
1290
|
+
*
|
|
1291
|
+
* It checks if the required wallet is connected, unblock the queue to be run.
|
|
1292
|
+
*/
|
|
1293
|
+
function onBlockForConnectWallet(event, meta) {
|
|
1294
|
+
var context = meta.context,
|
|
1295
|
+
queue = meta.queue;
|
|
1296
|
+
var swap = queue.getStorage().swapDetails;
|
|
1297
|
+
if (!isRequiredWalletConnected(swap, context.state)) {
|
|
1298
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1299
|
+
var currentStep = getCurrentStep(swap);
|
|
1300
|
+
context.notifier({
|
|
1301
|
+
eventType: 'waiting_for_connecting_wallet',
|
|
1302
|
+
swap: swap,
|
|
1303
|
+
step: currentStep
|
|
1304
|
+
});
|
|
1305
|
+
markRunningSwapAsWaitingForConnectingWallet({
|
|
1306
|
+
getStorage: queue.getStorage.bind(queue),
|
|
1307
|
+
setStorage: queue.setStorage.bind(queue)
|
|
1308
|
+
}, ERROR_MESSAGE_WAIT_FOR_WALLET, event.reason.description);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
queue.unblock();
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Event handler for blocked tasks.
|
|
1315
|
+
* If a transcation execution is manually blocked (like for parallel or waiting for walle),
|
|
1316
|
+
* This function will be called by queue manager using `queue definition`.
|
|
1317
|
+
*
|
|
1318
|
+
* It checks if the required network is connected, unblock the queue to be run.
|
|
1319
|
+
* Note: it automatically try to switch the network if its `provider` supports.
|
|
1320
|
+
*/
|
|
1321
|
+
function onBlockForChangeNetwork(_event, meta) {
|
|
1322
|
+
var context = meta.context,
|
|
1323
|
+
queue = meta.queue;
|
|
1324
|
+
var swap = queue.getStorage().swapDetails;
|
|
1325
|
+
var currentStep = getCurrentStep(swap);
|
|
1326
|
+
if (!currentStep) return;
|
|
1327
|
+
var result = markRunningSwapAsSwitchingNetwork({
|
|
1328
|
+
getStorage: queue.getStorage.bind(queue),
|
|
1329
|
+
setStorage: queue.setStorage.bind(queue)
|
|
1330
|
+
});
|
|
1331
|
+
if (result) {
|
|
1332
|
+
context.notifier({
|
|
1333
|
+
eventType: 'waiting_for_network_change',
|
|
1334
|
+
swap: result.swap,
|
|
1335
|
+
step: result.step
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
// Try to auto switch
|
|
1339
|
+
var _getRequiredWallet2 = getRequiredWallet(swap),
|
|
1340
|
+
type = _getRequiredWallet2.type,
|
|
1341
|
+
network = _getRequiredWallet2.network;
|
|
1342
|
+
if (!!type && !!network) {
|
|
1343
|
+
var _result = context.switchNetwork(type, network);
|
|
1344
|
+
if (_result) {
|
|
1345
|
+
_result.then(function () {
|
|
1346
|
+
queue.unblock();
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Event handler for blocked tasks. (Parallel mode)
|
|
1353
|
+
* If a transcation execution is manually blocked (like for parallel or waiting for walle),
|
|
1354
|
+
* This function will be called by queue manager using `queue definition`.
|
|
1355
|
+
*
|
|
1356
|
+
* It checks the blocked tasks, if there is no active `claimed` queue, try to give it to the best candidate.
|
|
1357
|
+
*/
|
|
1358
|
+
function onDependsOnOtherQueues(_event, meta) {
|
|
1359
|
+
var getBlockedTasks = meta.getBlockedTasks,
|
|
1360
|
+
forceExecute = meta.forceExecute,
|
|
1361
|
+
queue = meta.queue,
|
|
1362
|
+
manager = meta.manager;
|
|
1363
|
+
var _claimQueue = claimQueue(),
|
|
1364
|
+
setClaimer = _claimQueue.setClaimer,
|
|
1365
|
+
claimedBy = _claimQueue.claimedBy,
|
|
1366
|
+
reset = _claimQueue.reset;
|
|
1367
|
+
// We only needs those blocked tasks that have DEPENDS_ON_OTHER_QUEUES reason.
|
|
1368
|
+
var blockedTasks = getBlockedTasks().filter(function (task) {
|
|
1369
|
+
return task.reason.reason === BlockReason.DEPENDS_ON_OTHER_QUEUES;
|
|
1370
|
+
});
|
|
1371
|
+
if (blockedTasks.length === 0) {
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
var claimerId = claimedBy();
|
|
1375
|
+
var isClaimedByAnyQueue = !!claimerId;
|
|
1376
|
+
// Check if any queue `claimed` before, if yes, we don't should do anything.
|
|
1377
|
+
if (isClaimedByAnyQueue) {
|
|
1378
|
+
// We need to keep the latest swap messages
|
|
1379
|
+
markRunningSwapAsDependsOnOtherQueues({
|
|
1380
|
+
getStorage: queue.getStorage.bind(queue),
|
|
1381
|
+
setStorage: queue.setStorage.bind(queue)
|
|
1382
|
+
});
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
// Prioritize current queue to be run first.
|
|
1386
|
+
var task = blockedTasks.find(function (task) {
|
|
1387
|
+
return task.queue_id === meta.queue_id;
|
|
1388
|
+
});
|
|
1389
|
+
// If current task isn't available anymore, fallback to first blocked task.
|
|
1390
|
+
if (!task) {
|
|
1391
|
+
var firstBlockedTask = blockedTasks[0];
|
|
1392
|
+
task = firstBlockedTask;
|
|
1393
|
+
}
|
|
1394
|
+
setClaimer(task.queue_id);
|
|
1395
|
+
var claimedStorage = task.storage.get();
|
|
1396
|
+
var _getRequiredWallet3 = getRequiredWallet(claimedStorage.swapDetails),
|
|
1397
|
+
type = _getRequiredWallet3.type,
|
|
1398
|
+
network = _getRequiredWallet3.network,
|
|
1399
|
+
address = _getRequiredWallet3.address;
|
|
1400
|
+
// Run
|
|
1401
|
+
forceExecute(task.queue_id, {
|
|
1402
|
+
claimedBy: claimedBy(),
|
|
1403
|
+
resetClaimedBy: function resetClaimedBy() {
|
|
1404
|
+
reset();
|
|
1405
|
+
// TODO: Use key generator
|
|
1406
|
+
retryOn(type + "-" + network + "-" + address, manager);
|
|
1407
|
+
}
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
function isRequiredWalletConnected(swap, getState) {
|
|
1411
|
+
var _getRequiredWallet4 = getRequiredWallet(swap),
|
|
1412
|
+
type = _getRequiredWallet4.type,
|
|
1413
|
+
address = _getRequiredWallet4.address;
|
|
1414
|
+
if (!type || !address) {
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
var walletState = getState(type);
|
|
1418
|
+
var accounts = walletState.accounts;
|
|
1419
|
+
var connectedAccounts = accounts || [];
|
|
1420
|
+
return connectedAccounts.some(function (account) {
|
|
1421
|
+
var _readAccountAddress = walletsCore.readAccountAddress(account),
|
|
1422
|
+
accountAddress = _readAccountAddress.address;
|
|
1423
|
+
return address === accountAddress;
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
function singTransaction(actions) {
|
|
1427
|
+
var getStorage = actions.getStorage,
|
|
1428
|
+
setStorage = actions.setStorage,
|
|
1429
|
+
failed = actions.failed,
|
|
1430
|
+
next = actions.next,
|
|
1431
|
+
schedule = actions.schedule,
|
|
1432
|
+
context = actions.context;
|
|
1433
|
+
var meta = context.meta,
|
|
1434
|
+
getSigners = context.getSigners,
|
|
1435
|
+
notifier = context.notifier;
|
|
1436
|
+
var swap = getStorage().swapDetails;
|
|
1437
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1438
|
+
var currentStep = getCurrentStep(swap);
|
|
1439
|
+
var evmTransaction = currentStep.evmTransaction,
|
|
1440
|
+
evmApprovalTransaction = currentStep.evmApprovalTransaction,
|
|
1441
|
+
cosmosTransaction = currentStep.cosmosTransaction,
|
|
1442
|
+
solanaTransaction = currentStep.solanaTransaction,
|
|
1443
|
+
transferTransaction = currentStep.transferTransaction;
|
|
1444
|
+
var sourceWallet = getRelatedWallet(swap, currentStep);
|
|
1445
|
+
var walletSigners = getSigners(sourceWallet.walletType);
|
|
1446
|
+
var onFinish = function onFinish() {
|
|
1447
|
+
if (actions.context.resetClaimedBy) {
|
|
1448
|
+
actions.context.resetClaimedBy();
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
if (!!evmApprovalTransaction) {
|
|
1452
|
+
var spenderContract = evmApprovalTransaction == null ? void 0 : evmApprovalTransaction.to;
|
|
1453
|
+
if (!spenderContract) throw PrettyError.AssertionFailed('contract address is null for checking approval');
|
|
1454
|
+
// Update swap status
|
|
1455
|
+
var message = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
|
|
1456
|
+
var updateResult = updateSwapStatus({
|
|
1457
|
+
getStorage: getStorage,
|
|
1458
|
+
setStorage: setStorage,
|
|
1459
|
+
nextStepStatus: 'waitingForApproval',
|
|
1460
|
+
message: message,
|
|
1461
|
+
details: 'Waiting for approve transaction to be mined and confirmed successfully'
|
|
1462
|
+
});
|
|
1463
|
+
notifier(_extends({
|
|
1464
|
+
eventType: 'confirm_contract'
|
|
1465
|
+
}, updateResult));
|
|
1466
|
+
// Execute transaction
|
|
1467
|
+
walletSigners.executeEvmTransaction(evmApprovalTransaction, meta).then(function (hash) {
|
|
1468
|
+
console.debug('transaction of approval minted successfully', hash);
|
|
1469
|
+
var approveUrl = getEvmApproveUrl(hash, getCurrentBlockchainOf(swap, currentStep), meta.evmBasedChains);
|
|
1470
|
+
currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
|
|
1471
|
+
url: approveUrl,
|
|
1472
|
+
description: "approve"
|
|
1473
|
+
}]);
|
|
1474
|
+
// `currentStep` has been mutated, let's update storage.
|
|
1475
|
+
setStorage(_extends({}, getStorage(), {
|
|
1476
|
+
swapDetails: swap
|
|
1477
|
+
}));
|
|
1478
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1479
|
+
next();
|
|
1480
|
+
onFinish();
|
|
1481
|
+
}, function (error) {
|
|
1482
|
+
var _error$root, _error$root2, _error$root3;
|
|
1483
|
+
if (swap.status === 'failed') return;
|
|
1484
|
+
console.debug('error in approving', error);
|
|
1485
|
+
var _prettifyErrorMessage = prettifyErrorMessage(error),
|
|
1486
|
+
extraMessage = _prettifyErrorMessage.extraMessage,
|
|
1487
|
+
extraMessageDetail = _prettifyErrorMessage.extraMessageDetail,
|
|
1488
|
+
extraMessageErrorCode = _prettifyErrorMessage.extraMessageErrorCode;
|
|
1489
|
+
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) {
|
|
1490
|
+
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1491
|
+
}
|
|
1492
|
+
var updateResult = updateSwapStatus({
|
|
1493
|
+
getStorage: getStorage,
|
|
1494
|
+
setStorage: setStorage,
|
|
1495
|
+
nextStatus: 'failed',
|
|
1496
|
+
nextStepStatus: 'failed',
|
|
1497
|
+
message: extraMessage,
|
|
1498
|
+
details: extraMessageDetail,
|
|
1499
|
+
errorCode: extraMessageErrorCode
|
|
1500
|
+
});
|
|
1501
|
+
notifier(_extends({
|
|
1502
|
+
eventType: 'contract_rejected'
|
|
1503
|
+
}, updateResult));
|
|
1504
|
+
failed();
|
|
1505
|
+
onFinish();
|
|
1506
|
+
});
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
var executeMessage = 'executing transaction';
|
|
1510
|
+
var executeDetails = "" + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'Check your mobile phone' : '');
|
|
1511
|
+
if (!!transferTransaction) {
|
|
1512
|
+
var _updateResult = updateSwapStatus({
|
|
1513
|
+
getStorage: getStorage,
|
|
1514
|
+
setStorage: setStorage,
|
|
1515
|
+
nextStepStatus: 'running',
|
|
1516
|
+
message: executeMessage,
|
|
1517
|
+
details: executeDetails
|
|
1518
|
+
});
|
|
1519
|
+
notifier(_extends({
|
|
1520
|
+
eventType: 'confirm_transfer'
|
|
1521
|
+
}, _updateResult));
|
|
1522
|
+
walletSigners.executeTransfer(transferTransaction, meta).then(function (txId) {
|
|
1523
|
+
setStepTransactionIds(actions, txId, 'transfer_confirmed', notifier);
|
|
1524
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1525
|
+
next();
|
|
1526
|
+
onFinish();
|
|
1527
|
+
}, function (error) {
|
|
1528
|
+
if (swap.status === 'failed') return;
|
|
1529
|
+
var _prettifyErrorMessage2 = prettifyErrorMessage(error),
|
|
1530
|
+
extraMessage = _prettifyErrorMessage2.extraMessage,
|
|
1531
|
+
extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail,
|
|
1532
|
+
extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
|
|
1533
|
+
var updateResult = updateSwapStatus({
|
|
1534
|
+
getStorage: getStorage,
|
|
1535
|
+
setStorage: setStorage,
|
|
1536
|
+
nextStatus: 'failed',
|
|
1537
|
+
nextStepStatus: 'failed',
|
|
1538
|
+
message: extraMessage,
|
|
1539
|
+
details: extraMessageDetail,
|
|
1540
|
+
errorCode: extraMessageErrorCode
|
|
1541
|
+
});
|
|
1542
|
+
notifier(_extends({
|
|
1543
|
+
eventType: 'transfer_rejected'
|
|
1544
|
+
}, updateResult));
|
|
1545
|
+
failed();
|
|
1546
|
+
onFinish();
|
|
1547
|
+
});
|
|
1548
|
+
} else if (!!evmTransaction) {
|
|
1549
|
+
var _updateResult2 = updateSwapStatus({
|
|
1550
|
+
getStorage: getStorage,
|
|
1551
|
+
setStorage: setStorage,
|
|
1552
|
+
nextStepStatus: 'running',
|
|
1553
|
+
message: executeMessage,
|
|
1554
|
+
details: executeDetails
|
|
1555
|
+
});
|
|
1556
|
+
notifier(_extends({
|
|
1557
|
+
eventType: 'calling_smart_contract'
|
|
1558
|
+
}, _updateResult2));
|
|
1559
|
+
walletSigners.executeEvmTransaction(evmTransaction, meta).then(function (id) {
|
|
1560
|
+
setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
|
|
1561
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1562
|
+
next();
|
|
1563
|
+
onFinish();
|
|
1564
|
+
}, function (error) {
|
|
1565
|
+
var _error$root4, _error$root5, _error$root6;
|
|
1566
|
+
if (swap.status === 'failed') return;
|
|
1567
|
+
var _prettifyErrorMessage3 = prettifyErrorMessage(error),
|
|
1568
|
+
extraMessage = _prettifyErrorMessage3.extraMessage,
|
|
1569
|
+
extraMessageDetail = _prettifyErrorMessage3.extraMessageDetail,
|
|
1570
|
+
extraMessageErrorCode = _prettifyErrorMessage3.extraMessageErrorCode;
|
|
1571
|
+
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) {
|
|
1572
|
+
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1573
|
+
}
|
|
1574
|
+
var updateResult = updateSwapStatus({
|
|
1575
|
+
getStorage: getStorage,
|
|
1576
|
+
setStorage: setStorage,
|
|
1577
|
+
nextStatus: 'failed',
|
|
1578
|
+
nextStepStatus: 'failed',
|
|
1579
|
+
message: extraMessage,
|
|
1580
|
+
details: extraMessageDetail,
|
|
1581
|
+
errorCode: extraMessageErrorCode
|
|
1582
|
+
});
|
|
1583
|
+
notifier(_extends({
|
|
1584
|
+
eventType: 'smart_contract_call_failed'
|
|
1585
|
+
}, updateResult));
|
|
1586
|
+
failed();
|
|
1587
|
+
onFinish();
|
|
1588
|
+
});
|
|
1589
|
+
} else if (!!cosmosTransaction) {
|
|
1590
|
+
var _updateResult3 = updateSwapStatus({
|
|
1591
|
+
getStorage: getStorage,
|
|
1592
|
+
setStorage: setStorage,
|
|
1593
|
+
nextStepStatus: 'running',
|
|
1594
|
+
message: executeMessage,
|
|
1595
|
+
details: executeDetails
|
|
1596
|
+
});
|
|
1597
|
+
notifier(_extends({
|
|
1598
|
+
eventType: 'calling_smart_contract'
|
|
1599
|
+
}, _updateResult3));
|
|
1600
|
+
// If keplr wallet is executing contracts on terra, throw error. keplr doesn't support transfer or execute contracts. only IBC messages are supported
|
|
1601
|
+
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) &&
|
|
1602
|
+
// here we must allow ibc on terrastatus
|
|
1603
|
+
sourceWallet.walletType === walletsShared.WalletType.KEPLR) {
|
|
1604
|
+
var _prettifyErrorMessage4 = 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'),
|
|
1605
|
+
extraMessage = _prettifyErrorMessage4.extraMessage,
|
|
1606
|
+
extraMessageDetail = _prettifyErrorMessage4.extraMessageDetail,
|
|
1607
|
+
extraMessageErrorCode = _prettifyErrorMessage4.extraMessageErrorCode;
|
|
1608
|
+
var _updateResult4 = updateSwapStatus({
|
|
1609
|
+
getStorage: getStorage,
|
|
1610
|
+
setStorage: setStorage,
|
|
1611
|
+
nextStatus: 'failed',
|
|
1612
|
+
nextStepStatus: 'failed',
|
|
1613
|
+
message: extraMessage,
|
|
1614
|
+
details: extraMessageDetail,
|
|
1615
|
+
errorCode: extraMessageErrorCode
|
|
1616
|
+
});
|
|
1617
|
+
notifier(_extends({
|
|
1618
|
+
eventType: 'smart_contract_call_failed'
|
|
1619
|
+
}, _updateResult4));
|
|
1620
|
+
failed();
|
|
1621
|
+
onFinish();
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
walletSigners.executeCosmosMessage(cosmosTransaction, meta).then(
|
|
1625
|
+
// todo
|
|
1626
|
+
function (id) {
|
|
1627
|
+
setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
|
|
1628
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1629
|
+
next();
|
|
1630
|
+
onFinish();
|
|
1631
|
+
}, function (error) {
|
|
1632
|
+
if (swap.status === 'failed') return;
|
|
1633
|
+
var _prettifyErrorMessage5 = prettifyErrorMessage(error),
|
|
1634
|
+
extraMessage = _prettifyErrorMessage5.extraMessage,
|
|
1635
|
+
extraMessageDetail = _prettifyErrorMessage5.extraMessageDetail,
|
|
1636
|
+
extraMessageErrorCode = _prettifyErrorMessage5.extraMessageErrorCode;
|
|
1637
|
+
var updateResult = updateSwapStatus({
|
|
1638
|
+
getStorage: getStorage,
|
|
1639
|
+
setStorage: setStorage,
|
|
1640
|
+
nextStatus: 'failed',
|
|
1641
|
+
nextStepStatus: 'failed',
|
|
1642
|
+
message: extraMessage,
|
|
1643
|
+
details: extraMessageDetail,
|
|
1644
|
+
errorCode: extraMessageErrorCode
|
|
1645
|
+
});
|
|
1646
|
+
notifier(_extends({
|
|
1647
|
+
eventType: 'smart_contract_call_failed'
|
|
1648
|
+
}, updateResult));
|
|
1649
|
+
failed();
|
|
1650
|
+
onFinish();
|
|
1651
|
+
});
|
|
1652
|
+
} else if (!!solanaTransaction) {
|
|
1653
|
+
var _updateResult5 = updateSwapStatus({
|
|
1654
|
+
getStorage: getStorage,
|
|
1655
|
+
setStorage: setStorage,
|
|
1656
|
+
nextStepStatus: 'running',
|
|
1657
|
+
message: executeMessage,
|
|
1658
|
+
details: executeDetails
|
|
1659
|
+
});
|
|
1660
|
+
notifier(_extends({
|
|
1661
|
+
eventType: 'calling_smart_contract'
|
|
1662
|
+
}, _updateResult5));
|
|
1663
|
+
var tx = solanaTransaction;
|
|
1664
|
+
walletSigners.executeSolanaTransaction(tx, swap.requestId).then(function (txId) {
|
|
1665
|
+
setStepTransactionIds(actions, txId, 'smart_contract_called', notifier);
|
|
1666
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1667
|
+
next();
|
|
1668
|
+
onFinish();
|
|
1669
|
+
}, function (error) {
|
|
1670
|
+
if (swap.status === 'failed') return;
|
|
1671
|
+
var _prettifyErrorMessage6 = prettifyErrorMessage(error),
|
|
1672
|
+
extraMessage = _prettifyErrorMessage6.extraMessage,
|
|
1673
|
+
extraMessageDetail = _prettifyErrorMessage6.extraMessageDetail,
|
|
1674
|
+
extraMessageErrorCode = _prettifyErrorMessage6.extraMessageErrorCode;
|
|
1675
|
+
var updateResult = updateSwapStatus({
|
|
1676
|
+
getStorage: getStorage,
|
|
1677
|
+
setStorage: setStorage,
|
|
1678
|
+
nextStatus: 'failed',
|
|
1679
|
+
nextStepStatus: 'failed',
|
|
1680
|
+
message: extraMessage,
|
|
1681
|
+
details: extraMessageDetail,
|
|
1682
|
+
errorCode: extraMessageErrorCode
|
|
1683
|
+
});
|
|
1684
|
+
notifier(_extends({
|
|
1685
|
+
eventType: 'smart_contract_call_failed'
|
|
1686
|
+
}, updateResult));
|
|
1687
|
+
failed();
|
|
1688
|
+
onFinish();
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
*
|
|
1694
|
+
* Try to run blocked tasks by wallet and network name.
|
|
1695
|
+
* Goes through queues and extract blocked queues with matched wallet.
|
|
1696
|
+
* If found any blocked tasks with same wallet and network, runs them.
|
|
1697
|
+
* If not, runs only blocked tasks with matched wallet.
|
|
1698
|
+
*
|
|
1699
|
+
* @param wallet_network a string includes `wallet` type and `network` type.
|
|
1700
|
+
* @param manager
|
|
1701
|
+
* @returns
|
|
1702
|
+
*/
|
|
1703
|
+
function retryOn(wallet_network, manager, options) {
|
|
1704
|
+
var _finalQueueToBeRun;
|
|
1705
|
+
if (options === void 0) {
|
|
1706
|
+
options = {
|
|
1707
|
+
fallbackToOnlyWallet: true
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
var _wallet_network$split2 = wallet_network.split('-'),
|
|
1711
|
+
wallet = _wallet_network$split2[0],
|
|
1712
|
+
network = _wallet_network$split2[1];
|
|
1713
|
+
if (!wallet || !network) {
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
var walletAndNetworkMatched = [];
|
|
1717
|
+
var onlyWalletMatched = [];
|
|
1718
|
+
manager == null ? void 0 : manager.getAll().forEach(function (q) {
|
|
1719
|
+
// retry only on affected queues
|
|
1720
|
+
if (q.status === queueManagerCore.Status.BLOCKED) {
|
|
1721
|
+
var queueStorage = q.list.getStorage();
|
|
1722
|
+
var swap = queueStorage == null ? void 0 : queueStorage.swapDetails;
|
|
1723
|
+
if (swap) {
|
|
1724
|
+
var currentStep = getCurrentStep(swap);
|
|
1725
|
+
if (currentStep) {
|
|
1726
|
+
var _queueStorage$swapDet2, _queueStorage$swapDet3;
|
|
1727
|
+
if (currentStep.fromBlockchain == network && (queueStorage == null ? void 0 : (_queueStorage$swapDet2 = queueStorage.swapDetails.wallets[network]) == null ? void 0 : _queueStorage$swapDet2.walletType) === wallet) {
|
|
1728
|
+
walletAndNetworkMatched.push(q.list);
|
|
1729
|
+
} else if ((queueStorage == null ? void 0 : (_queueStorage$swapDet3 = queueStorage.swapDetails.wallets[currentStep.fromBlockchain]) == null ? void 0 : _queueStorage$swapDet3.walletType) === wallet) {
|
|
1730
|
+
onlyWalletMatched.push(q.list);
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
});
|
|
1736
|
+
// const isWaitingForConnectWallet = (status: Status) =>
|
|
1737
|
+
var finalQueueToBeRun = undefined;
|
|
1738
|
+
if (walletAndNetworkMatched.length > 0) {
|
|
1739
|
+
finalQueueToBeRun = walletAndNetworkMatched[0];
|
|
1740
|
+
if (walletAndNetworkMatched.length > 1) {
|
|
1741
|
+
for (var i = 1; i < walletAndNetworkMatched.length; i++) {
|
|
1742
|
+
var currentQueue = walletAndNetworkMatched[i];
|
|
1743
|
+
markRunningSwapAsDependsOnOtherQueues({
|
|
1744
|
+
getStorage: currentQueue.getStorage.bind(currentQueue),
|
|
1745
|
+
setStorage: currentQueue.setStorage.bind(currentQueue)
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
} else if (onlyWalletMatched.length > 0 && options.fallbackToOnlyWallet) {
|
|
1750
|
+
finalQueueToBeRun = onlyWalletMatched[0];
|
|
1751
|
+
}
|
|
1752
|
+
(_finalQueueToBeRun = finalQueueToBeRun) == null ? void 0 : _finalQueueToBeRun.checkBlock();
|
|
1753
|
+
}
|
|
1754
|
+
/*
|
|
1755
|
+
For avoiding conflict by making too many requests to wallet, we need to make sure
|
|
1756
|
+
We only run one request at a time (In parallel mode).
|
|
1757
|
+
*/
|
|
1758
|
+
function isNeedBlockQueueForParallel(step) {
|
|
1759
|
+
return !!step.evmTransaction || !!step.evmApprovalTransaction || !!step.cosmosTransaction;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
var INTERVAL_FOR_CHECK = 2000;
|
|
1763
|
+
/**
|
|
1764
|
+
* Subscribe to status of swap transaction by checking from server periodically.
|
|
1765
|
+
* After getting the status, notify the user and schedule `SCHEDULE_NEXT_STEP`.
|
|
1766
|
+
*/
|
|
1767
|
+
function checkTransactionStatus(_x) {
|
|
1768
|
+
return _checkTransactionStatus.apply(this, arguments);
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Subscribe to status of approval transaction by checking from server periodically.
|
|
1772
|
+
* After getting the status, notify the user and schedule `SCHEDULE_NEXT_STEP`.
|
|
1773
|
+
*/
|
|
1774
|
+
function _checkTransactionStatus() {
|
|
1775
|
+
_checkTransactionStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
1776
|
+
var _status, _status2, _status3, _status4, _status5, _status6, _status7, _status8, _status9, _status10;
|
|
1777
|
+
var getStorage, setStorage, next, schedule, retry, context, swap, currentStep, txId, status, outputAmount, prevOutputAmount, newTransaction, nextStep;
|
|
1778
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1779
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1780
|
+
case 0:
|
|
1781
|
+
getStorage = _ref.getStorage, setStorage = _ref.setStorage, next = _ref.next, schedule = _ref.schedule, retry = _ref.retry, context = _ref.context;
|
|
1782
|
+
swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1783
|
+
currentStep = getCurrentStep(swap);
|
|
1784
|
+
txId = currentStep.executedTransactionId;
|
|
1785
|
+
status = null;
|
|
1786
|
+
_context.prev = 5;
|
|
1787
|
+
_context.next = 8;
|
|
1788
|
+
return checkSwapStatus(swap.requestId, txId, currentStep.id);
|
|
1789
|
+
case 8:
|
|
1790
|
+
status = _context.sent;
|
|
1791
|
+
_context.next = 17;
|
|
1792
|
+
break;
|
|
1793
|
+
case 11:
|
|
1794
|
+
_context.prev = 11;
|
|
1795
|
+
_context.t0 = _context["catch"](5);
|
|
1796
|
+
_context.next = 15;
|
|
1797
|
+
return delay(INTERVAL_FOR_CHECK);
|
|
1798
|
+
case 15:
|
|
1799
|
+
retry();
|
|
1800
|
+
return _context.abrupt("return");
|
|
1801
|
+
case 17:
|
|
1802
|
+
outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? new BigNumber__default(currentStep.outputAmount) : null);
|
|
1803
|
+
prevOutputAmount = currentStep.outputAmount;
|
|
1804
|
+
swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
|
|
1805
|
+
swap.extraMessageSeverity = MessageSeverity.info;
|
|
1806
|
+
swap.extraMessageDetail = '';
|
|
1807
|
+
currentStep.status = ((_status3 = status) == null ? void 0 : _status3.status) || currentStep.status;
|
|
1808
|
+
currentStep.diagnosisUrl = ((_status4 = status) == null ? void 0 : _status4.diagnosisUrl) || currentStep.diagnosisUrl || null;
|
|
1809
|
+
currentStep.outputAmount = (outputAmount == null ? void 0 : outputAmount.toFixed()) || currentStep.outputAmount;
|
|
1810
|
+
currentStep.explorerUrl = ((_status5 = status) == null ? void 0 : _status5.explorerUrl) || currentStep.explorerUrl;
|
|
1811
|
+
currentStep.internalSteps = ((_status6 = status) == null ? void 0 : _status6.steps) || null;
|
|
1812
|
+
newTransaction = (_status7 = status) == null ? void 0 : _status7.newTx;
|
|
1813
|
+
if (!!newTransaction) {
|
|
1814
|
+
currentStep.status = 'created';
|
|
1815
|
+
currentStep.executedTransactionId = null;
|
|
1816
|
+
currentStep.transferTransaction = null;
|
|
1817
|
+
currentStep.cosmosTransaction = null;
|
|
1818
|
+
currentStep.evmTransaction = null;
|
|
1819
|
+
currentStep.solanaTransaction = null;
|
|
1820
|
+
currentStep.evmApprovalTransaction = null;
|
|
1821
|
+
currentStep.starknetApprovalTransaction = null;
|
|
1822
|
+
currentStep.starknetTransaction = null;
|
|
1823
|
+
currentStep.tronApprovalTransaction = null;
|
|
1824
|
+
currentStep.tronTransaction = null;
|
|
1825
|
+
if (isEvmTransaction(newTransaction)) {
|
|
1826
|
+
if (newTransaction.isApprovalTx) currentStep.evmApprovalTransaction = newTransaction;else currentStep.evmTransaction = newTransaction;
|
|
1827
|
+
} else if (isCosmosTransaction(newTransaction)) {
|
|
1828
|
+
currentStep.cosmosTransaction = newTransaction;
|
|
1829
|
+
} else if (isSolanaTransaction(newTransaction)) {
|
|
1830
|
+
currentStep.solanaTransaction = newTransaction;
|
|
1831
|
+
} else if (isTrasnferTransaction(newTransaction)) {
|
|
1832
|
+
currentStep.transferTransaction = newTransaction;
|
|
1833
|
+
} else if (isStarknetTransaction(newTransaction)) {
|
|
1834
|
+
if (newTransaction.isApprovalTx) currentStep.starknetApprovalTransaction = newTransaction;else currentStep.starknetTransaction = newTransaction;
|
|
1835
|
+
} else if (isTronTransaction(newTransaction)) {
|
|
1836
|
+
if (newTransaction.isApprovalTx) currentStep.tronApprovalTransaction = newTransaction;else currentStep.tronTransaction = newTransaction;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
if (prevOutputAmount === null && outputAmount !== null) context.notifier({
|
|
1840
|
+
eventType: 'step_completed_with_output',
|
|
1841
|
+
swap: swap,
|
|
1842
|
+
step: currentStep
|
|
1843
|
+
});
|
|
1844
|
+
if (currentStep.status === 'success') {
|
|
1845
|
+
nextStep = getNextStep(swap, currentStep);
|
|
1846
|
+
swap.extraMessageDetail = '';
|
|
1847
|
+
swap.extraMessage = !!nextStep ? "starting next step: " + nextStep.swapperId + ": " + nextStep.fromBlockchain + " -> " + nextStep.toBlockchain : '';
|
|
1848
|
+
}
|
|
1849
|
+
// Sync data with storage
|
|
1850
|
+
setStorage(_extends({}, getStorage(), {
|
|
1851
|
+
swapDetails: swap
|
|
1852
|
+
}));
|
|
1853
|
+
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)) {
|
|
1854
|
+
_context.next = 37;
|
|
1855
|
+
break;
|
|
1856
|
+
}
|
|
1857
|
+
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
1858
|
+
next();
|
|
1859
|
+
_context.next = 40;
|
|
1860
|
+
break;
|
|
1861
|
+
case 37:
|
|
1862
|
+
_context.next = 39;
|
|
1863
|
+
return delay(INTERVAL_FOR_CHECK);
|
|
1864
|
+
case 39:
|
|
1865
|
+
retry();
|
|
1866
|
+
case 40:
|
|
1867
|
+
case "end":
|
|
1868
|
+
return _context.stop();
|
|
1869
|
+
}
|
|
1870
|
+
}, _callee, null, [[5, 11]]);
|
|
1871
|
+
}));
|
|
1872
|
+
return _checkTransactionStatus.apply(this, arguments);
|
|
1873
|
+
}
|
|
1874
|
+
function checkApprovalStatus(_x2) {
|
|
1875
|
+
return _checkApprovalStatus.apply(this, arguments);
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
*
|
|
1879
|
+
* For doing a swap the user needs to accept a `contract` so it can use the user balance.
|
|
1880
|
+
* There is two types of check status:
|
|
1881
|
+
* 1. Checking approval transaction (Give permission to a contract)
|
|
1882
|
+
* 2. Checking swap transaction.
|
|
1883
|
+
*
|
|
1884
|
+
*/
|
|
1885
|
+
function _checkApprovalStatus() {
|
|
1886
|
+
_checkApprovalStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
1887
|
+
var getStorage, setStorage, next, schedule, retry, context, swap, currentStep, isApproved, response;
|
|
1888
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1889
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1890
|
+
case 0:
|
|
1891
|
+
getStorage = _ref2.getStorage, setStorage = _ref2.setStorage, next = _ref2.next, schedule = _ref2.schedule, retry = _ref2.retry, context = _ref2.context;
|
|
1892
|
+
swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1893
|
+
currentStep = getCurrentStep(swap);
|
|
1894
|
+
isApproved = false;
|
|
1895
|
+
_context2.prev = 4;
|
|
1896
|
+
_context2.next = 7;
|
|
1897
|
+
return checkApproved(swap.requestId);
|
|
1898
|
+
case 7:
|
|
1899
|
+
response = _context2.sent;
|
|
1900
|
+
isApproved = response.isApproved;
|
|
1901
|
+
_context2.next = 14;
|
|
1902
|
+
break;
|
|
1903
|
+
case 11:
|
|
1904
|
+
_context2.prev = 11;
|
|
1905
|
+
_context2.t0 = _context2["catch"](4);
|
|
1906
|
+
console.error('Failed to check getApprovedAmount', _context2.t0);
|
|
1907
|
+
case 14:
|
|
1908
|
+
if (!isApproved) {
|
|
1909
|
+
_context2.next = 27;
|
|
1910
|
+
break;
|
|
1911
|
+
}
|
|
1912
|
+
currentStep.status = 'approved';
|
|
1913
|
+
swap.extraMessage = "Spending " + currentStep.fromSymbol + " approved successfully.";
|
|
1914
|
+
swap.extraMessageDetail = null;
|
|
1915
|
+
swap.extraMessageSeverity = MessageSeverity.success;
|
|
1916
|
+
currentStep.evmApprovalTransaction = null;
|
|
1917
|
+
currentStep.executedTransactionId = null;
|
|
1918
|
+
setStorage(_extends({}, getStorage(), {
|
|
1919
|
+
swapDetails: swap
|
|
1920
|
+
}));
|
|
1921
|
+
context.notifier({
|
|
1922
|
+
eventType: 'contract_confirmed',
|
|
1923
|
+
swap: swap,
|
|
1924
|
+
step: currentStep
|
|
1925
|
+
});
|
|
1926
|
+
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
1927
|
+
next();
|
|
1928
|
+
_context2.next = 30;
|
|
1929
|
+
break;
|
|
1930
|
+
case 27:
|
|
1931
|
+
_context2.next = 29;
|
|
1932
|
+
return delay(2000);
|
|
1933
|
+
case 29:
|
|
1934
|
+
retry();
|
|
1935
|
+
case 30:
|
|
1936
|
+
case "end":
|
|
1937
|
+
return _context2.stop();
|
|
1938
|
+
}
|
|
1939
|
+
}, _callee2, null, [[4, 11]]);
|
|
1940
|
+
}));
|
|
1941
|
+
return _checkApprovalStatus.apply(this, arguments);
|
|
1942
|
+
}
|
|
1943
|
+
function checkStatus(_x3) {
|
|
1944
|
+
return _checkStatus.apply(this, arguments);
|
|
1945
|
+
}
|
|
1946
|
+
function _checkStatus() {
|
|
1947
|
+
_checkStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(actions) {
|
|
1948
|
+
var swap, currentStep;
|
|
1949
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1950
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1951
|
+
case 0:
|
|
1952
|
+
swap = actions.getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1953
|
+
currentStep = getCurrentStep(swap); // Reset network status
|
|
1954
|
+
// Because when check status is on `loading` or `failed` status, it shows previous message that isn't related to current state.
|
|
1955
|
+
resetNetworkStatus(actions);
|
|
1956
|
+
if (!(currentStep.status === 'running')) {
|
|
1957
|
+
_context3.next = 8;
|
|
1958
|
+
break;
|
|
1959
|
+
}
|
|
1960
|
+
_context3.next = 6;
|
|
1961
|
+
return checkTransactionStatus(actions);
|
|
1962
|
+
case 6:
|
|
1963
|
+
_context3.next = 11;
|
|
1964
|
+
break;
|
|
1965
|
+
case 8:
|
|
1966
|
+
if (!(currentStep.status === 'waitingForApproval')) {
|
|
1967
|
+
_context3.next = 11;
|
|
1968
|
+
break;
|
|
1969
|
+
}
|
|
1970
|
+
_context3.next = 11;
|
|
1971
|
+
return checkApprovalStatus(actions);
|
|
1972
|
+
case 11:
|
|
1973
|
+
case "end":
|
|
1974
|
+
return _context3.stop();
|
|
1975
|
+
}
|
|
1976
|
+
}, _callee3);
|
|
1977
|
+
}));
|
|
1978
|
+
return _checkStatus.apply(this, arguments);
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
/**
|
|
1982
|
+
*
|
|
1983
|
+
* When a user asks for a swap, We first create the transaction by sending a request to server
|
|
1984
|
+
* Server will return the transaction that need to be sent to wallet.
|
|
1985
|
+
* It can be failed if server goes through an error, If not, we will schedule the `EXECTUTE_TRANSACTION`.
|
|
1986
|
+
*
|
|
1987
|
+
*/
|
|
1988
|
+
function createTransaction$1(_x) {
|
|
1989
|
+
return _createTransaction$1.apply(this, arguments);
|
|
1990
|
+
}
|
|
1991
|
+
function _createTransaction$1() {
|
|
1992
|
+
_createTransaction$1 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
|
|
1993
|
+
var setStorage, getStorage, next, schedule, context, swap, currentStep, evmTransaction, cosmosTransaction, transferTransaction, evmApprovalTransaction, solanaTransaction, request, _yield$requestTransac, transaction, _prettifyErrorMessage, extraMessage, extraMessageDetail, updateResult;
|
|
1994
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1995
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1996
|
+
case 0:
|
|
1997
|
+
setStorage = actions.setStorage, getStorage = actions.getStorage, next = actions.next, schedule = actions.schedule, context = actions.context;
|
|
1998
|
+
swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1999
|
+
currentStep = getCurrentStep(swap);
|
|
2000
|
+
evmTransaction = currentStep.evmTransaction, cosmosTransaction = currentStep.cosmosTransaction, transferTransaction = currentStep.transferTransaction, evmApprovalTransaction = currentStep.evmApprovalTransaction, solanaTransaction = currentStep.solanaTransaction;
|
|
2001
|
+
if (!(!evmTransaction && !cosmosTransaction && !transferTransaction && !evmApprovalTransaction && !solanaTransaction)) {
|
|
2002
|
+
_context.next = 25;
|
|
2003
|
+
break;
|
|
2004
|
+
}
|
|
2005
|
+
request = {
|
|
2006
|
+
requestId: swap.requestId,
|
|
2007
|
+
step: currentStep.id,
|
|
2008
|
+
userSettings: {
|
|
2009
|
+
slippage: swap.settings.slippage,
|
|
2010
|
+
infiniteApprove: swap.settings.infiniteApprove
|
|
2011
|
+
},
|
|
2012
|
+
validations: {
|
|
2013
|
+
balance: swap.validateBalanceOrFee,
|
|
2014
|
+
fee: swap.validateBalanceOrFee
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
_context.prev = 6;
|
|
2018
|
+
_context.next = 9;
|
|
2019
|
+
return createTransaction(request);
|
|
2020
|
+
case 9:
|
|
2021
|
+
_yield$requestTransac = _context.sent;
|
|
2022
|
+
transaction = _yield$requestTransac.transaction;
|
|
2023
|
+
if (transaction) {
|
|
2024
|
+
if (isEvmTransaction(transaction)) {
|
|
2025
|
+
if (transaction.isApprovalTx) currentStep.evmApprovalTransaction = transaction;else currentStep.evmTransaction = transaction;
|
|
2026
|
+
} else if (isCosmosTransaction(transaction)) {
|
|
2027
|
+
currentStep.cosmosTransaction = transaction;
|
|
2028
|
+
} else if (isSolanaTransaction(transaction)) {
|
|
2029
|
+
currentStep.solanaTransaction = transaction;
|
|
2030
|
+
} else if (isTrasnferTransaction(transaction)) {
|
|
2031
|
+
currentStep.transferTransaction = transaction;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
setStorage(_extends({}, getStorage(), {
|
|
2035
|
+
swapDetails: swap
|
|
2036
|
+
}));
|
|
2037
|
+
schedule(SwapActionTypes.EXECUTE_TRANSACTION);
|
|
2038
|
+
next();
|
|
2039
|
+
_context.next = 25;
|
|
2040
|
+
break;
|
|
2041
|
+
case 17:
|
|
2042
|
+
_context.prev = 17;
|
|
2043
|
+
_context.t0 = _context["catch"](6);
|
|
2044
|
+
swap.status = 'failed';
|
|
2045
|
+
swap.finishTime = new Date().getTime().toString();
|
|
2046
|
+
_prettifyErrorMessage = prettifyErrorMessage(_context.t0), extraMessage = _prettifyErrorMessage.extraMessage, extraMessageDetail = _prettifyErrorMessage.extraMessageDetail;
|
|
2047
|
+
updateResult = updateSwapStatus({
|
|
2048
|
+
getStorage: getStorage,
|
|
2049
|
+
setStorage: setStorage,
|
|
2050
|
+
nextStatus: 'failed',
|
|
2051
|
+
nextStepStatus: 'failed',
|
|
2052
|
+
message: extraMessage,
|
|
2053
|
+
details: extraMessageDetail,
|
|
2054
|
+
errorCode: APIErrorCode.FETCH_TX_FAILED
|
|
2055
|
+
});
|
|
2056
|
+
context.notifier(_extends({
|
|
2057
|
+
eventType: 'task_failed'
|
|
2058
|
+
}, updateResult));
|
|
2059
|
+
actions.failed();
|
|
2060
|
+
case 25:
|
|
2061
|
+
case "end":
|
|
2062
|
+
return _context.stop();
|
|
2063
|
+
}
|
|
2064
|
+
}, _callee, null, [[6, 17]]);
|
|
2065
|
+
}));
|
|
2066
|
+
return _createTransaction$1.apply(this, arguments);
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
/**
|
|
2070
|
+
* Excecute a created transaction.
|
|
2071
|
+
*
|
|
2072
|
+
* This function implemented the parallel mode by `claim` mechanism which means
|
|
2073
|
+
* All the queues the meet certain situation (like multiple evm transaction) will go through
|
|
2074
|
+
* a `claim` mechanims that decides which queue should be run and it blocks other ones.
|
|
2075
|
+
*
|
|
2076
|
+
* A queue will be go to sign process, if the wallet and network is matched.
|
|
2077
|
+
*/
|
|
2078
|
+
function executeTransaction(_x) {
|
|
2079
|
+
return _executeTransaction.apply(this, arguments);
|
|
2080
|
+
}
|
|
2081
|
+
function _executeTransaction() {
|
|
2082
|
+
_executeTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
|
|
2083
|
+
var _context$_queue;
|
|
2084
|
+
var getStorage, context, meta, wallets, providers, isClaimed, requestBlock, swap, currentStep, isWrongAddress, _getRequiredWallet, type, address, description, blockedFor, needsToBlockQueue, _blockedFor, networkMatched, fromBlockchain, details, _blockedFor2;
|
|
2085
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2086
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2087
|
+
case 0:
|
|
2088
|
+
getStorage = actions.getStorage, context = actions.context;
|
|
2089
|
+
meta = context.meta, wallets = context.wallets, providers = context.providers;
|
|
2090
|
+
isClaimed = context.claimedBy === ((_context$_queue = context._queue) == null ? void 0 : _context$_queue.id);
|
|
2091
|
+
requestBlock = function requestBlock(blockedFor) {
|
|
2092
|
+
actions.block(blockedFor);
|
|
2093
|
+
if (isClaimed && actions.context.resetClaimedBy) {
|
|
2094
|
+
actions.context.resetClaimedBy();
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2098
|
+
currentStep = getCurrentStep(swap); // Resetting network status, so we will set it again during the running of this task.
|
|
2099
|
+
resetNetworkStatus(actions);
|
|
2100
|
+
/* Make sure wallet is connected and also the connected wallet is matched with tx by checking address. */
|
|
2101
|
+
isWrongAddress = !isRequiredWalletConnected(swap, context.state);
|
|
2102
|
+
if (!isWrongAddress) {
|
|
2103
|
+
_context.next = 14;
|
|
2104
|
+
break;
|
|
2105
|
+
}
|
|
2106
|
+
_getRequiredWallet = getRequiredWallet(swap), type = _getRequiredWallet.type, address = _getRequiredWallet.address;
|
|
2107
|
+
description = !wallets ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
|
|
2108
|
+
blockedFor = {
|
|
2109
|
+
reason: BlockReason.WAIT_FOR_CONNECT_WALLET,
|
|
2110
|
+
description: description
|
|
2111
|
+
};
|
|
2112
|
+
requestBlock(blockedFor);
|
|
2113
|
+
return _context.abrupt("return");
|
|
2114
|
+
case 14:
|
|
2115
|
+
/*
|
|
2116
|
+
For avoiding conflict by making too many requests to wallet, we need to make sure
|
|
2117
|
+
We only run one request at a time (In parallel mode).
|
|
2118
|
+
*/
|
|
2119
|
+
needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
|
|
2120
|
+
if (!(needsToBlockQueue && !isClaimed && context.claimedBy)) {
|
|
2121
|
+
_context.next = 19;
|
|
2122
|
+
break;
|
|
2123
|
+
}
|
|
2124
|
+
_blockedFor = {
|
|
2125
|
+
reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
|
|
2126
|
+
description: 'Waiting for other running tasks to be finished',
|
|
2127
|
+
details: {}
|
|
2128
|
+
};
|
|
2129
|
+
requestBlock(_blockedFor);
|
|
2130
|
+
return _context.abrupt("return");
|
|
2131
|
+
case 19:
|
|
2132
|
+
_context.next = 21;
|
|
2133
|
+
return isNetworkMatchedForTransaction(swap, currentStep, wallets, meta, providers);
|
|
2134
|
+
case 21:
|
|
2135
|
+
networkMatched = _context.sent;
|
|
2136
|
+
if (networkMatched) {
|
|
2137
|
+
_context.next = 30;
|
|
2138
|
+
break;
|
|
2139
|
+
}
|
|
2140
|
+
fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
|
|
2141
|
+
details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(fromBlockchain);
|
|
2142
|
+
_blockedFor2 = {
|
|
2143
|
+
reason: BlockReason.WAIT_FOR_NETWORK_CHANGE,
|
|
2144
|
+
details: details
|
|
2145
|
+
};
|
|
2146
|
+
requestBlock(_blockedFor2);
|
|
2147
|
+
return _context.abrupt("return");
|
|
2148
|
+
case 30:
|
|
2149
|
+
// Update network to mark it as network changed successfully.
|
|
2150
|
+
updateNetworkStatus(actions, {
|
|
2151
|
+
message: '',
|
|
2152
|
+
details: 'Wallet network changed successfully',
|
|
2153
|
+
status: PendingSwapNetworkStatus.NetworkChanged
|
|
2154
|
+
});
|
|
2155
|
+
case 31:
|
|
2156
|
+
// All the conditions are met. We can safely send the tx to wallet for sign.
|
|
2157
|
+
singTransaction(actions);
|
|
2158
|
+
case 32:
|
|
2159
|
+
case "end":
|
|
2160
|
+
return _context.stop();
|
|
2161
|
+
}
|
|
2162
|
+
}, _callee);
|
|
2163
|
+
}));
|
|
2164
|
+
return _executeTransaction.apply(this, arguments);
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
*
|
|
2169
|
+
* This function is responsibe for scheduling the correct `action` based on `PendingSwap` status.
|
|
2170
|
+
* It means `action`s schedule this step to decide what should be the next step/task.
|
|
2171
|
+
*
|
|
2172
|
+
* It's acts like a `while(true)` and will `break` the loop on certain `action`s like `CHECK_STATUS`.
|
|
2173
|
+
*
|
|
2174
|
+
*
|
|
2175
|
+
*/
|
|
2176
|
+
function scheduleNextStep(_ref) {
|
|
2177
|
+
var schedule = _ref.schedule,
|
|
2178
|
+
next = _ref.next,
|
|
2179
|
+
failed = _ref.failed,
|
|
2180
|
+
setStorage = _ref.setStorage,
|
|
2181
|
+
getStorage = _ref.getStorage,
|
|
2182
|
+
context = _ref.context;
|
|
2183
|
+
var swap = getStorage().swapDetails;
|
|
2184
|
+
var currentStep = getCurrentStep(swap);
|
|
2185
|
+
if (!!currentStep) {
|
|
2186
|
+
if (isTxAlreadyCreated(swap, currentStep)) {
|
|
2187
|
+
schedule(SwapActionTypes.EXECUTE_TRANSACTION);
|
|
2188
|
+
return next();
|
|
2189
|
+
}
|
|
2190
|
+
if (currentStep != null && currentStep.executedTransactionId) {
|
|
2191
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
2192
|
+
return next();
|
|
2193
|
+
}
|
|
2194
|
+
swap.status = 'running';
|
|
2195
|
+
setStorage(_extends({}, getStorage(), {
|
|
2196
|
+
swapDetails: swap
|
|
2197
|
+
}));
|
|
2198
|
+
schedule(SwapActionTypes.CREATE_TRANSACTION);
|
|
2199
|
+
next();
|
|
2200
|
+
} else {
|
|
2201
|
+
var isFailed = swap.steps.find(function (step) {
|
|
2202
|
+
return step.status === 'failed';
|
|
2203
|
+
});
|
|
2204
|
+
swap.status = isFailed ? 'failed' : 'success';
|
|
2205
|
+
swap.finishTime = new Date().getTime().toString();
|
|
2206
|
+
setStorage(_extends({}, getStorage(), {
|
|
2207
|
+
swapDetails: swap
|
|
2208
|
+
}));
|
|
2209
|
+
context.notifier({
|
|
2210
|
+
eventType: isFailed ? 'task_failed' : 'task_completed',
|
|
2211
|
+
swap: swap,
|
|
2212
|
+
step: null
|
|
2213
|
+
});
|
|
2214
|
+
if (isFailed) failed();else next();
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
function start(_ref) {
|
|
2219
|
+
var schedule = _ref.schedule,
|
|
2220
|
+
next = _ref.next;
|
|
2221
|
+
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
2222
|
+
next();
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
var _actions;
|
|
2226
|
+
/**
|
|
2227
|
+
*
|
|
2228
|
+
* The idea behind this queue is to be able dynamically add some steps.
|
|
2229
|
+
* After running a swap, it can be blocked (like on waiting for switch netwrok)
|
|
2230
|
+
* or waits for something happend (like checking status of a transaction from server)
|
|
2231
|
+
*
|
|
2232
|
+
*/
|
|
2233
|
+
var swapQueueDef = {
|
|
2234
|
+
name: 'swap',
|
|
2235
|
+
actions: (_actions = {}, _actions[SwapActionTypes.START] = start, _actions[SwapActionTypes.SCHEDULE_NEXT_STEP] = scheduleNextStep, _actions[SwapActionTypes.CREATE_TRANSACTION] = createTransaction$1, _actions[SwapActionTypes.EXECUTE_TRANSACTION] = executeTransaction, _actions[SwapActionTypes.CHECK_TRANSACTION_STATUS] = checkStatus, _actions),
|
|
2236
|
+
run: [SwapActionTypes.START],
|
|
2237
|
+
whenTaskBlocked: function whenTaskBlocked(event, meta) {
|
|
2238
|
+
if (event.reason.reason === BlockReason.WAIT_FOR_CONNECT_WALLET) {
|
|
2239
|
+
onBlockForConnectWallet(event, meta);
|
|
2240
|
+
} else if (event.reason.reason === BlockReason.WAIT_FOR_NETWORK_CHANGE) {
|
|
2241
|
+
onBlockForChangeNetwork(event, meta);
|
|
2242
|
+
} else if (event.reason.reason === BlockReason.DEPENDS_ON_OTHER_QUEUES) {
|
|
2243
|
+
onDependsOnOtherQueues(event, meta);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2248
|
+
exports.swapQueueDef = swapQueueDef;
|
|
2249
|
+
//# sourceMappingURL=queue-manager-rango-preset.cjs.development.js.map
|