@rango-dev/queue-manager-rango-preset 0.1.13-next.10 → 0.1.13-next.11

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.
@@ -2186,12 +2186,12 @@ function checkTransactionStatus(_x) {
2186
2186
  */
2187
2187
  function _checkTransactionStatus() {
2188
2188
  _checkTransactionStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
2189
- var _status, _status2, _status3, _status4, _status5, _status6, _status7, _status8, _status9, _status10;
2190
- var getStorage, setStorage, next, schedule, retry, context, swap, currentStep, txId, status, outputAmount, prevOutputAmount, newTransaction, nextStep;
2189
+ var _status, _status2, _status3, _status4, _status5, _status6, _status7, _status9, _status10, _status11;
2190
+ var getStorage, setStorage, next, schedule, retry, failed, context, swap, currentStep, txId, status, outputAmount, prevOutputAmount, newTransaction, nextStep, _status8;
2191
2191
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2192
2192
  while (1) switch (_context.prev = _context.next) {
2193
2193
  case 0:
2194
- getStorage = _ref.getStorage, setStorage = _ref.setStorage, next = _ref.next, schedule = _ref.schedule, retry = _ref.retry, context = _ref.context;
2194
+ getStorage = _ref.getStorage, setStorage = _ref.setStorage, next = _ref.next, schedule = _ref.schedule, retry = _ref.retry, failed = _ref.failed, context = _ref.context;
2195
2195
  swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2196
2196
  currentStep = getCurrentStep(swap);
2197
2197
  txId = currentStep.executedTransactionId;
@@ -2279,26 +2279,36 @@ function _checkTransactionStatus() {
2279
2279
  } else if (currentStep.status === 'failed') {
2280
2280
  swap.extraMessage = 'Transaction failed in blockchain';
2281
2281
  swap.extraMessageSeverity = MessageSeverity.error;
2282
- swap.extraMessageDetail = '';
2282
+ swap.extraMessageDetail = ((_status8 = status) == null ? void 0 : _status8.extraMessage) || '';
2283
+ swap.status = 'failed';
2284
+ swap.finishTime = new Date().getTime().toString();
2283
2285
  }
2284
2286
  // Sync data with storage
2285
2287
  setStorage(_extends({}, getStorage(), {
2286
2288
  swapDetails: swap
2287
2289
  }));
2288
- 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)) {
2289
- _context.next = 39;
2290
+ if (!(((_status9 = status) == null ? void 0 : _status9.status) === 'failed')) {
2291
+ _context.next = 38;
2292
+ break;
2293
+ }
2294
+ failed();
2295
+ _context.next = 46;
2296
+ break;
2297
+ case 38:
2298
+ if (!(((_status10 = status) == null ? void 0 : _status10.status) === 'success' || ((_status11 = status) == null ? void 0 : _status11.status) === 'running' && !!status.newTx)) {
2299
+ _context.next = 43;
2290
2300
  break;
2291
2301
  }
2292
2302
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2293
2303
  next();
2294
- _context.next = 42;
2304
+ _context.next = 46;
2295
2305
  break;
2296
- case 39:
2297
- _context.next = 41;
2306
+ case 43:
2307
+ _context.next = 45;
2298
2308
  return delay(INTERVAL_FOR_CHECK);
2299
- case 41:
2309
+ case 45:
2300
2310
  retry();
2301
- case 42:
2311
+ case 46:
2302
2312
  case "end":
2303
2313
  return _context.stop();
2304
2314
  }
@@ -2319,7 +2329,7 @@ function checkApprovalStatus(_x2) {
2319
2329
  */
2320
2330
  function _checkApprovalStatus() {
2321
2331
  _checkApprovalStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
2322
- var getStorage, setStorage, next, schedule, retry, failed, context, swap, currentStep, isApproved, response, updateResult;
2332
+ var getStorage, setStorage, next, schedule, retry, failed, context, swap, currentStep, isApproved, response, message, details, updateResult;
2323
2333
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2324
2334
  while (1) switch (_context2.prev = _context2.next) {
2325
2335
  case 0:
@@ -2339,7 +2349,14 @@ function _checkApprovalStatus() {
2339
2349
  return _context2.abrupt("return");
2340
2350
  case 10:
2341
2351
  isApproved = response.isApproved;
2342
- if (!isApproved && response.txStatus === 'failed') {
2352
+ if (!isApproved && (response.txStatus === 'failed' || response.txStatus === 'success')) {
2353
+ if (response.txStatus === 'failed') {
2354
+ message = 'Approve transaction failed';
2355
+ details = 'Smart contract approval failed in blockchain.';
2356
+ } else {
2357
+ message = 'Not enough approval';
2358
+ if (response.requiredApprovedAmount && response.currentApprovedAmount) details = "Required approval: " + response.requiredApprovedAmount + ", current approval: " + response.currentApprovedAmount;else details = "You still don't have enough approval for this swap.";
2359
+ }
2343
2360
  // approve transaction failed on
2344
2361
  // we should fail the whole swap
2345
2362
  updateResult = updateSwapStatus({
@@ -2348,14 +2365,13 @@ function _checkApprovalStatus() {
2348
2365
  nextStatus: 'failed',
2349
2366
  nextStepStatus: 'failed',
2350
2367
  errorCode: 'SEND_TX_FAILED',
2351
- message: 'Approve transaction failed',
2352
- details: 'Smart contract approval failed in blockchain.'
2368
+ message: message,
2369
+ details: details
2353
2370
  });
2354
2371
  context.notifier(_extends({
2355
2372
  eventType: 'smart_contract_call_failed'
2356
2373
  }, updateResult));
2357
2374
  failed();
2358
- // onFinish();
2359
2375
  } else if (!isApproved) {
2360
2376
  // it is needed to set notification after reloading the page
2361
2377
  context.notifier({
@@ -2676,12 +2692,14 @@ function scheduleNextStep(_ref) {
2676
2692
  context = _ref.context;
2677
2693
  var swap = getStorage().swapDetails;
2678
2694
  var currentStep = getCurrentStep(swap);
2679
- if (!!currentStep) {
2695
+ var isFailed = swap.steps.find(function (step) {
2696
+ return step.status === 'failed';
2697
+ });
2698
+ if (!!currentStep && !isFailed) {
2680
2699
  if (isTxAlreadyCreated(swap, currentStep)) {
2681
2700
  schedule(SwapActionTypes.EXECUTE_TRANSACTION);
2682
2701
  return next();
2683
2702
  }
2684
- // TODO double check it after approval changes
2685
2703
  if (currentStep != null && currentStep.executedTransactionId) {
2686
2704
  schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
2687
2705
  return next();
@@ -2693,9 +2711,6 @@ function scheduleNextStep(_ref) {
2693
2711
  schedule(SwapActionTypes.CREATE_TRANSACTION);
2694
2712
  next();
2695
2713
  } else {
2696
- var isFailed = swap.steps.find(function (step) {
2697
- return step.status === 'failed';
2698
- });
2699
2714
  swap.status = isFailed ? 'failed' : 'success';
2700
2715
  swap.finishTime = new Date().getTime().toString();
2701
2716
  setStorage(_extends({}, getStorage(), {