@rango-dev/queue-manager-rango-preset 0.1.10-next.95 → 0.1.10-next.98

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.
@@ -708,6 +708,14 @@ function claimQueue() {
708
708
  }
709
709
  };
710
710
  }
711
+ /**
712
+ *
713
+ * Returns "wallet and network" separately, even if the wallet is dashed inside.
714
+ *
715
+ */
716
+ function splitWalletNetwork(input) {
717
+ return input == null ? void 0 : input.split(/-(?=[^-]*$)/);
718
+ }
711
719
  /**
712
720
  *
713
721
  * Returns `steps`, if it's a `running` swap.
@@ -1789,9 +1797,9 @@ function checkWaitingForConnectWalletChange(params) {
1789
1797
  var wallet_network = params.wallet_network,
1790
1798
  evmChains = params.evmChains,
1791
1799
  manager = params.manager;
1792
- var _wallet_network$split = wallet_network.split('-'),
1793
- wallet = _wallet_network$split[0],
1794
- network = _wallet_network$split[1];
1800
+ var _splitWalletNetwork = splitWalletNetwork(wallet_network),
1801
+ wallet = _splitWalletNetwork[0],
1802
+ network = _splitWalletNetwork[1];
1795
1803
  // We only need change network for EVM chains.
1796
1804
  if (!evmChains.some(function (chain) {
1797
1805
  return chain.name == network;
@@ -1809,7 +1817,7 @@ function checkWaitingForConnectWalletChange(params) {
1809
1817
  var task = q.list.state.tasks[taskId];
1810
1818
  return task.status === Status.BLOCKED && [BlockReason.WAIT_FOR_CONNECT_WALLET].includes((_task$blockedFor = task.blockedFor) == null ? void 0 : _task$blockedFor.reason);
1811
1819
  });
1812
- if (currentStepRequiredWallet === wallet && hasWaitingForConnect) {
1820
+ if (currentStepRequiredWallet === wallet && hasWaitingForConnect && getCurrentBlockchainOfOrNull(swap, currentStep) != network) {
1813
1821
  var queueInstance = q.list;
1814
1822
  var _getRequiredWallet5 = getRequiredWallet(swap),
1815
1823
  type = _getRequiredWallet5.type;
@@ -1873,9 +1881,9 @@ function retryOn(wallet_network, manager, options) {
1873
1881
  fallbackToOnlyWallet: true
1874
1882
  };
1875
1883
  }
1876
- var _wallet_network$split2 = wallet_network.split('-'),
1877
- wallet = _wallet_network$split2[0],
1878
- network = _wallet_network$split2[1];
1884
+ var _splitWalletNetwork2 = splitWalletNetwork(wallet_network),
1885
+ wallet = _splitWalletNetwork2[0],
1886
+ network = _splitWalletNetwork2[1];
1879
1887
  if (!wallet || !network) {
1880
1888
  return;
1881
1889
  }
@@ -1890,7 +1898,7 @@ function retryOn(wallet_network, manager, options) {
1890
1898
  var currentStep = getCurrentStep(swap);
1891
1899
  if (currentStep) {
1892
1900
  var _queueStorage$swapDet2, _queueStorage$swapDet3;
1893
- if (currentStep.fromBlockchain == network && (queueStorage == null ? void 0 : (_queueStorage$swapDet2 = queueStorage.swapDetails.wallets[network]) == null ? void 0 : _queueStorage$swapDet2.walletType) === wallet) {
1901
+ if (getCurrentBlockchainOfOrNull(swap, currentStep) == network && (queueStorage == null ? void 0 : (_queueStorage$swapDet2 = queueStorage.swapDetails.wallets[network]) == null ? void 0 : _queueStorage$swapDet2.walletType) === wallet) {
1894
1902
  walletAndNetworkMatched.push(q.list);
1895
1903
  } else if ((queueStorage == null ? void 0 : (_queueStorage$swapDet3 = queueStorage.swapDetails.wallets[currentStep.fromBlockchain]) == null ? void 0 : _queueStorage$swapDet3.walletType) === wallet) {
1896
1904
  onlyWalletMatched.push(q.list);
@@ -1961,6 +1969,18 @@ function _throwOnOK() {
1961
1969
  }));
1962
1970
  return _throwOnOK.apply(this, arguments);
1963
1971
  }
1972
+ function cancelSwap(swap) {
1973
+ swap.actions.cancel();
1974
+ return updateSwapStatus({
1975
+ getStorage: swap.actions.getStorage,
1976
+ setStorage: swap.actions.setStorage,
1977
+ message: 'Swap canceled by user.',
1978
+ details: "Warning: If you've already signed and sent a transaction, it won't be affected, but next swap steps will not be executed.",
1979
+ nextStatus: 'failed',
1980
+ nextStepStatus: 'failed',
1981
+ errorCode: 'USER_CANCEL'
1982
+ });
1983
+ }
1964
1984
 
1965
1985
  var INTERVAL_FOR_CHECK = 2000;
1966
1986
  /**
@@ -2295,7 +2315,7 @@ function executeTransaction(_x) {
2295
2315
  function _executeTransaction() {
2296
2316
  _executeTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
2297
2317
  var _context$_queue;
2298
- var getStorage, context, meta, wallets, providers, isClaimed, requestBlock, swap, currentStep, isWrongAddress, _getRequiredWallet, type, address, description, blockedFor, needsToBlockQueue, _blockedFor, networkMatched, fromBlockchain, details, _blockedFor2;
2318
+ 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;
2299
2319
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2300
2320
  while (1) switch (_context.prev = _context.next) {
2301
2321
  case 0:
@@ -2314,25 +2334,31 @@ function _executeTransaction() {
2314
2334
  /* Make sure wallet is connected and also the connected wallet is matched with tx by checking address. */
2315
2335
  isWrongAddress = !isRequiredWalletConnected(swap, context.state);
2316
2336
  if (!isWrongAddress) {
2317
- _context.next = 14;
2337
+ _context.next = 15;
2318
2338
  break;
2319
2339
  }
2320
2340
  _getRequiredWallet = getRequiredWallet(swap), type = _getRequiredWallet.type, address = _getRequiredWallet.address;
2321
- description = !wallets ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
2341
+ isWalletInCompatible = wallets == null ? void 0 : (_wallets$blockchains = wallets.blockchains) == null ? void 0 : _wallets$blockchains.find(function (w) {
2342
+ var _w$accounts;
2343
+ return !((_w$accounts = w.accounts) != null && _w$accounts.find(function (account) {
2344
+ return account.walletType === type;
2345
+ }));
2346
+ });
2347
+ description = !wallets || isWalletInCompatible ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
2322
2348
  blockedFor = {
2323
2349
  reason: BlockReason.WAIT_FOR_CONNECT_WALLET,
2324
2350
  description: description
2325
2351
  };
2326
2352
  requestBlock(blockedFor);
2327
2353
  return _context.abrupt("return");
2328
- case 14:
2354
+ case 15:
2329
2355
  /*
2330
2356
  For avoiding conflict by making too many requests to wallet, we need to make sure
2331
2357
  We only run one request at a time (In parallel mode).
2332
2358
  */
2333
2359
  needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
2334
2360
  if (!(needsToBlockQueue && !isClaimed && context.claimedBy)) {
2335
- _context.next = 19;
2361
+ _context.next = 20;
2336
2362
  break;
2337
2363
  }
2338
2364
  _blockedFor = {
@@ -2342,13 +2368,13 @@ function _executeTransaction() {
2342
2368
  };
2343
2369
  requestBlock(_blockedFor);
2344
2370
  return _context.abrupt("return");
2345
- case 19:
2346
- _context.next = 21;
2371
+ case 20:
2372
+ _context.next = 22;
2347
2373
  return isNetworkMatchedForTransaction(swap, currentStep, wallets, meta, providers);
2348
- case 21:
2374
+ case 22:
2349
2375
  networkMatched = _context.sent;
2350
2376
  if (networkMatched) {
2351
- _context.next = 30;
2377
+ _context.next = 31;
2352
2378
  break;
2353
2379
  }
2354
2380
  fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
@@ -2359,17 +2385,17 @@ function _executeTransaction() {
2359
2385
  };
2360
2386
  requestBlock(_blockedFor2);
2361
2387
  return _context.abrupt("return");
2362
- case 30:
2388
+ case 31:
2363
2389
  // Update network to mark it as network changed successfully.
2364
2390
  updateNetworkStatus(actions, {
2365
2391
  message: '',
2366
2392
  details: 'Wallet network changed successfully',
2367
2393
  status: PendingSwapNetworkStatus.NetworkChanged
2368
2394
  });
2369
- case 31:
2395
+ case 32:
2370
2396
  // All the conditions are met. We can safely send the tx to wallet for sign.
2371
2397
  singTransaction(actions);
2372
- case 32:
2398
+ case 33:
2373
2399
  case "end":
2374
2400
  return _context.stop();
2375
2401
  }
@@ -2667,5 +2693,5 @@ var swapQueueDef = {
2667
2693
  }
2668
2694
  };
2669
2695
 
2670
- export { checkWaitingForNetworkChange, getCurrentStep, getEvmProvider, getRelatedWallet$1 as getRelatedWallet, swapQueueDef, updateSwapStatus, useMigration, useQueueManager };
2696
+ export { cancelSwap, checkWaitingForNetworkChange, getCurrentStep, getEvmProvider, getRelatedWallet$1 as getRelatedWallet, swapQueueDef, updateSwapStatus, useMigration, useQueueManager };
2671
2697
  //# sourceMappingURL=queue-manager-rango-preset.esm.js.map