@rango-dev/queue-manager-rango-preset 0.1.12 → 0.1.13-next.1

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.
@@ -469,6 +469,7 @@ function _assertThisInitialized(self) {
469
469
  return self;
470
470
  }
471
471
 
472
+ var ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES = 'Waiting for other swaps to complete';
472
473
  var ERROR_MESSAGE_WAIT_FOR_WALLET = 'Waiting for connecting wallet';
473
474
  var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address) {
474
475
  return "Please change your " + (type || 'wallet') + " account to " + (address || 'proper address');
@@ -2114,7 +2115,7 @@ function retryOn(wallet_network, notifier, manager, options) {
2114
2115
  We only run one request at a time (In parallel mode).
2115
2116
  */
2116
2117
  function isNeedBlockQueueForParallel(step) {
2117
- return !!step.evmTransaction || !!step.evmApprovalTransaction || !!step.cosmosTransaction;
2118
+ return !!step.evmTransaction || !!step.evmApprovalTransaction;
2118
2119
  }
2119
2120
  /*
2120
2121
  Create transaction endpoint doesn't return error code on http status code,
@@ -2215,6 +2216,12 @@ function _checkTransactionStatus() {
2215
2216
  retry();
2216
2217
  return _context.abrupt("return");
2217
2218
  case 17:
2219
+ if (!((currentStep == null ? void 0 : currentStep.status) === 'failed')) {
2220
+ _context.next = 19;
2221
+ break;
2222
+ }
2223
+ return _context.abrupt("return");
2224
+ case 19:
2218
2225
  outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? currentStep.outputAmount : null);
2219
2226
  prevOutputAmount = currentStep.outputAmount || null;
2220
2227
  swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
@@ -2279,19 +2286,19 @@ function _checkTransactionStatus() {
2279
2286
  swapDetails: swap
2280
2287
  }));
2281
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)) {
2282
- _context.next = 37;
2289
+ _context.next = 39;
2283
2290
  break;
2284
2291
  }
2285
2292
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2286
2293
  next();
2287
- _context.next = 40;
2294
+ _context.next = 42;
2288
2295
  break;
2289
- case 37:
2290
- _context.next = 39;
2291
- return delay(INTERVAL_FOR_CHECK);
2292
2296
  case 39:
2297
+ _context.next = 41;
2298
+ return delay(INTERVAL_FOR_CHECK);
2299
+ case 41:
2293
2300
  retry();
2294
- case 40:
2301
+ case 42:
2295
2302
  case "end":
2296
2303
  return _context.stop();
2297
2304
  }
@@ -2317,14 +2324,7 @@ function _checkApprovalStatus() {
2317
2324
  while (1) switch (_context2.prev = _context2.next) {
2318
2325
  case 0:
2319
2326
  getStorage = _ref2.getStorage, setStorage = _ref2.setStorage, next = _ref2.next, schedule = _ref2.schedule, retry = _ref2.retry, failed = _ref2.failed, context = _ref2.context;
2320
- swap = getStorage().swapDetails; // double check it after fixing parallel
2321
- // const onFinish = () => {
2322
- // // TODO resetClaimedBy is undefined here
2323
- // if (context.resetClaimedBy) {
2324
- // context.resetClaimedBy();
2325
- // }
2326
- // };
2327
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2327
+ swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2328
2328
  currentStep = getCurrentStep(swap);
2329
2329
  isApproved = false;
2330
2330
  _context2.prev = 4;
@@ -2332,6 +2332,12 @@ function _checkApprovalStatus() {
2332
2332
  return httpService().checkApproval(swap.requestId, currentStep.executedTransactionId || '');
2333
2333
  case 7:
2334
2334
  response = _context2.sent;
2335
+ if (!((currentStep == null ? void 0 : currentStep.status) === 'failed')) {
2336
+ _context2.next = 10;
2337
+ break;
2338
+ }
2339
+ return _context2.abrupt("return");
2340
+ case 10:
2335
2341
  isApproved = response.isApproved;
2336
2342
  if (!isApproved && response.txStatus === 'failed') {
2337
2343
  // approve transaction failed on
@@ -2358,15 +2364,15 @@ function _checkApprovalStatus() {
2358
2364
  step: currentStep
2359
2365
  });
2360
2366
  }
2361
- _context2.next = 15;
2367
+ _context2.next = 17;
2362
2368
  break;
2363
- case 12:
2364
- _context2.prev = 12;
2369
+ case 14:
2370
+ _context2.prev = 14;
2365
2371
  _context2.t0 = _context2["catch"](4);
2366
2372
  isApproved = false;
2367
- case 15:
2373
+ case 17:
2368
2374
  if (!isApproved) {
2369
- _context2.next = 31;
2375
+ _context2.next = 33;
2370
2376
  break;
2371
2377
  }
2372
2378
  currentStep.status = 'approved';
@@ -2388,18 +2394,18 @@ function _checkApprovalStatus() {
2388
2394
  });
2389
2395
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2390
2396
  next();
2391
- _context2.next = 34;
2397
+ _context2.next = 36;
2392
2398
  break;
2393
- case 31:
2394
- _context2.next = 33;
2395
- return delay(2000);
2396
2399
  case 33:
2400
+ _context2.next = 35;
2401
+ return delay(2000);
2402
+ case 35:
2397
2403
  retry();
2398
- case 34:
2404
+ case 36:
2399
2405
  case "end":
2400
2406
  return _context2.stop();
2401
2407
  }
2402
- }, _callee2, null, [[4, 12]]);
2408
+ }, _callee2, null, [[4, 14]]);
2403
2409
  }));
2404
2410
  return _checkApprovalStatus.apply(this, arguments);
2405
2411
  }
@@ -2548,12 +2554,13 @@ function executeTransaction(_x) {
2548
2554
  function _executeTransaction() {
2549
2555
  _executeTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
2550
2556
  var _context$_queue;
2551
- var getStorage, context, meta, wallets, providers, isClaimed, requestBlock, swap, currentStep, isWrongAddress, _wallets$blockchains, _getRequiredWallet, type, address, isWalletInCompatible, description, blockedFor, needsToBlockQueue, _blockedFor, networkMatched, fromBlockchain, details, _blockedFor2;
2557
+ var getStorage, context, meta, wallets, providers, _claimQueue, claimedBy, isClaimed, requestBlock, swap, currentStep, isWrongAddress, _wallets$blockchains, _getRequiredWallet, type, address, isWalletInCompatible, description, blockedFor, networkMatched, claimerId, isClaimedByAnyQueue, details, _blockedFor, fromBlockchain, _details, _blockedFor2, needsToBlockQueue, _blockedFor3;
2552
2558
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2553
2559
  while (1) switch (_context.prev = _context.next) {
2554
2560
  case 0:
2555
2561
  getStorage = actions.getStorage, context = actions.context;
2556
2562
  meta = context.meta, wallets = context.wallets, providers = context.providers;
2563
+ _claimQueue = claimQueue(), claimedBy = _claimQueue.claimedBy;
2557
2564
  isClaimed = context.claimedBy === ((_context$_queue = context._queue) == null ? void 0 : _context$_queue.id);
2558
2565
  requestBlock = function requestBlock(blockedFor) {
2559
2566
  actions.block(blockedFor);
@@ -2567,7 +2574,7 @@ function _executeTransaction() {
2567
2574
  /* Make sure wallet is connected and also the connected wallet is matched with tx by checking address. */
2568
2575
  isWrongAddress = !isRequiredWalletConnected(swap, context.state).ok;
2569
2576
  if (!isWrongAddress) {
2570
- _context.next = 15;
2577
+ _context.next = 16;
2571
2578
  break;
2572
2579
  }
2573
2580
  _getRequiredWallet = getRequiredWallet(swap), type = _getRequiredWallet.type, address = _getRequiredWallet.address;
@@ -2584,51 +2591,65 @@ function _executeTransaction() {
2584
2591
  };
2585
2592
  requestBlock(blockedFor);
2586
2593
  return _context.abrupt("return");
2587
- case 15:
2588
- /*
2589
- For avoiding conflict by making too many requests to wallet, we need to make sure
2590
- We only run one request at a time (In parallel mode).
2591
- */
2592
- needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
2593
- if (!(needsToBlockQueue && !isClaimed)) {
2594
- _context.next = 20;
2594
+ case 16:
2595
+ _context.next = 18;
2596
+ return isNetworkMatchedForTransaction(swap, currentStep, wallets, meta, providers);
2597
+ case 18:
2598
+ networkMatched = _context.sent;
2599
+ claimerId = claimedBy();
2600
+ isClaimedByAnyQueue = !!claimerId && !isClaimed;
2601
+ if (!(isClaimedByAnyQueue && !networkMatched)) {
2602
+ _context.next = 28;
2595
2603
  break;
2596
2604
  }
2605
+ details = ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES;
2597
2606
  _blockedFor = {
2598
2607
  reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
2599
- description: 'Waiting for other swaps to complete',
2600
- details: {}
2608
+ details: details
2601
2609
  };
2602
2610
  requestBlock(_blockedFor);
2603
2611
  return _context.abrupt("return");
2604
- case 20:
2605
- _context.next = 22;
2606
- return isNetworkMatchedForTransaction(swap, currentStep, wallets, meta, providers);
2607
- case 22:
2608
- networkMatched = _context.sent;
2612
+ case 28:
2609
2613
  if (networkMatched) {
2610
- _context.next = 31;
2614
+ _context.next = 36;
2611
2615
  break;
2612
2616
  }
2613
2617
  fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
2614
- details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(fromBlockchain);
2618
+ _details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(fromBlockchain);
2615
2619
  _blockedFor2 = {
2616
2620
  reason: BlockReason.WAIT_FOR_NETWORK_CHANGE,
2617
- details: details
2621
+ details: _details
2618
2622
  };
2619
2623
  requestBlock(_blockedFor2);
2620
2624
  return _context.abrupt("return");
2621
- case 31:
2625
+ case 36:
2622
2626
  // Update network to mark it as network changed successfully.
2623
2627
  updateNetworkStatus(actions, {
2624
2628
  message: '',
2625
2629
  details: 'Wallet network changed successfully',
2626
2630
  status: PendingSwapNetworkStatus.NetworkChanged
2627
2631
  });
2628
- case 32:
2632
+ case 37:
2633
+ /*
2634
+ For avoiding conflict by making too many requests to wallet, we need to make sure
2635
+ We only run one request at a time (In parallel mode).
2636
+ */
2637
+ needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
2638
+ if (!(needsToBlockQueue && !isClaimed)) {
2639
+ _context.next = 42;
2640
+ break;
2641
+ }
2642
+ _blockedFor3 = {
2643
+ reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
2644
+ description: ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES,
2645
+ details: {}
2646
+ };
2647
+ requestBlock(_blockedFor3);
2648
+ return _context.abrupt("return");
2649
+ case 42:
2629
2650
  // All the conditions are met. We can safely send the tx to wallet for sign.
2630
2651
  singTransaction(actions);
2631
- case 33:
2652
+ case 43:
2632
2653
  case "end":
2633
2654
  return _context.stop();
2634
2655
  }