@rango-dev/queue-manager-rango-preset 0.1.10-next.94 → 0.1.10-next.96

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.
@@ -1498,7 +1506,10 @@ function singTransaction(actions) {
1498
1506
  });
1499
1507
  var notification = getSwapNotitfication('confirm_transfer', _updateResult3);
1500
1508
  notifier(notification);
1501
- if (notification.eventType !== 'transaction_expired') {
1509
+ if (notification.eventType === 'transaction_expired') {
1510
+ failed();
1511
+ onFinish();
1512
+ } else {
1502
1513
  walletSigners.getSigner(TransactionType.TRANSFER).signAndSendTx(transferTransaction, walletAddress, null).then(function (txId) {
1503
1514
  setStepTransactionIds(actions, txId, 'transfer_confirmed', notifier);
1504
1515
  schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
@@ -1538,7 +1549,10 @@ function singTransaction(actions) {
1538
1549
  });
1539
1550
  var _notification = getSwapNotitfication('calling_smart_contract', _updateResult4);
1540
1551
  notifier(_notification);
1541
- if (_notification.eventType !== 'transaction_expired') {
1552
+ if (_notification.eventType === 'transaction_expired') {
1553
+ failed();
1554
+ onFinish();
1555
+ } else {
1542
1556
  walletSigners.getSigner(TransactionType.EVM).signAndSendTx(evmTransaction, walletAddress, null).then(function (id) {
1543
1557
  setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1544
1558
  schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
@@ -1582,7 +1596,10 @@ function singTransaction(actions) {
1582
1596
  });
1583
1597
  var _notification2 = getSwapNotitfication('calling_smart_contract', _updateResult5);
1584
1598
  notifier(_notification2);
1585
- if (_notification2.eventType !== 'transaction_expired') {
1599
+ if (_notification2.eventType === 'transaction_expired') {
1600
+ failed();
1601
+ onFinish();
1602
+ } else {
1586
1603
  // If keplr wallet is executing contracts on terra, throw error. keplr doesn't support transfer or execute contracts. only IBC messages are supported
1587
1604
  if (((currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'TerraSwap' || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'ThorChain' && (currentStep == null ? void 0 : currentStep.fromBlockchain) === Network.TERRA || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'Terra Bridge' && currentStep.fromBlockchain === Network.TERRA) &&
1588
1605
  // here we must allow ibc on terrastatus
@@ -1648,7 +1665,10 @@ function singTransaction(actions) {
1648
1665
  });
1649
1666
  var _notification3 = getSwapNotitfication('calling_smart_contract', _updateResult7);
1650
1667
  notifier(_notification3);
1651
- if (_notification3.eventType !== 'transaction_expired') {
1668
+ if (_notification3.eventType === 'transaction_expired') {
1669
+ failed();
1670
+ onFinish();
1671
+ } else {
1652
1672
  var tx = solanaTransaction;
1653
1673
  walletSigners.getSigner(TransactionType.SOLANA).signAndSendTx(tx, walletAddress, null).then(function (txId) {
1654
1674
  setStepTransactionIds(actions, txId, 'smart_contract_called', notifier);
@@ -1681,93 +1701,105 @@ function singTransaction(actions) {
1681
1701
  var _updateResult8 = updateSwapStatus({
1682
1702
  getStorage: getStorage,
1683
1703
  setStorage: setStorage,
1684
- nextStepStatus: 'running',
1704
+ nextStepStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1705
+ nextStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1685
1706
  message: executeMessage,
1686
- details: executeDetails
1707
+ details: executeDetails,
1708
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign
1687
1709
  });
1688
- notifier(_extends({
1689
- eventType: 'calling_smart_contract'
1690
- }, _updateResult8));
1691
- walletSigners.getSigner(TransactionType.TRON).signAndSendTx(tronTransaction, walletAddress, null).then(function (id) {
1692
- setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1693
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1694
- next();
1695
- onFinish();
1696
- }, function (error) {
1697
- var _error$root13, _error$root14, _error$root15;
1698
- if (swap.status === 'failed') return;
1699
- var _prettifyErrorMessage9 = prettifyErrorMessage(error),
1700
- extraMessage = _prettifyErrorMessage9.extraMessage,
1701
- extraMessageDetail = _prettifyErrorMessage9.extraMessageDetail,
1702
- extraMessageErrorCode = _prettifyErrorMessage9.extraMessageErrorCode;
1703
- if (error && error != null && error.root && error != null && (_error$root13 = error.root) != null && _error$root13.message && error != null && (_error$root14 = error.root) != null && _error$root14.code && error != null && (_error$root15 = error.root) != null && _error$root15.reason) {
1704
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1705
- }
1706
- var updateResult = updateSwapStatus({
1707
- getStorage: getStorage,
1708
- setStorage: setStorage,
1709
- nextStatus: 'failed',
1710
- nextStepStatus: 'failed',
1711
- message: extraMessage,
1712
- details: extraMessageDetail,
1713
- errorCode: extraMessageErrorCode
1714
- });
1715
- notifier(_extends({
1716
- eventType: 'smart_contract_call_failed'
1717
- }, updateResult));
1710
+ var _notification4 = getSwapNotitfication('calling_smart_contract', _updateResult8);
1711
+ notifier(_notification4);
1712
+ if (_notification4.eventType === 'transaction_expired') {
1718
1713
  failed();
1719
1714
  onFinish();
1720
- });
1715
+ } else {
1716
+ walletSigners.getSigner(TransactionType.TRON).signAndSendTx(tronTransaction, walletAddress, null).then(function (id) {
1717
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1718
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1719
+ next();
1720
+ onFinish();
1721
+ }, function (error) {
1722
+ var _error$root13, _error$root14, _error$root15;
1723
+ if (swap.status === 'failed') return;
1724
+ var _prettifyErrorMessage9 = prettifyErrorMessage(error),
1725
+ extraMessage = _prettifyErrorMessage9.extraMessage,
1726
+ extraMessageDetail = _prettifyErrorMessage9.extraMessageDetail,
1727
+ extraMessageErrorCode = _prettifyErrorMessage9.extraMessageErrorCode;
1728
+ if (error && error != null && error.root && error != null && (_error$root13 = error.root) != null && _error$root13.message && error != null && (_error$root14 = error.root) != null && _error$root14.code && error != null && (_error$root15 = error.root) != null && _error$root15.reason) {
1729
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1730
+ }
1731
+ var updateResult = updateSwapStatus({
1732
+ getStorage: getStorage,
1733
+ setStorage: setStorage,
1734
+ nextStatus: 'failed',
1735
+ nextStepStatus: 'failed',
1736
+ message: extraMessage,
1737
+ details: extraMessageDetail,
1738
+ errorCode: extraMessageErrorCode
1739
+ });
1740
+ notifier(_extends({
1741
+ eventType: 'smart_contract_call_failed'
1742
+ }, updateResult));
1743
+ failed();
1744
+ onFinish();
1745
+ });
1746
+ }
1721
1747
  } else if (!!starknetTransaction) {
1722
1748
  var _updateResult9 = updateSwapStatus({
1723
1749
  getStorage: getStorage,
1724
1750
  setStorage: setStorage,
1725
- nextStepStatus: 'running',
1751
+ nextStepStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1752
+ nextStatus: hasAlreadyProceededToSign ? 'failed' : 'running',
1726
1753
  message: executeMessage,
1727
- details: executeDetails
1754
+ details: executeDetails,
1755
+ hasAlreadyProceededToSign: hasAlreadyProceededToSign
1728
1756
  });
1729
- notifier(_extends({
1730
- eventType: 'calling_smart_contract'
1731
- }, _updateResult9));
1732
- walletSigners.getSigner(TransactionType.STARKNET).signAndSendTx(starknetTransaction, walletAddress, null).then(function (id) {
1733
- setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1734
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1735
- next();
1736
- onFinish();
1737
- }, function (error) {
1738
- var _error$root16, _error$root17, _error$root18;
1739
- if (swap.status === 'failed') return;
1740
- var _prettifyErrorMessage10 = prettifyErrorMessage(error),
1741
- extraMessage = _prettifyErrorMessage10.extraMessage,
1742
- extraMessageDetail = _prettifyErrorMessage10.extraMessageDetail,
1743
- extraMessageErrorCode = _prettifyErrorMessage10.extraMessageErrorCode;
1744
- if (error && error != null && error.root && error != null && (_error$root16 = error.root) != null && _error$root16.message && error != null && (_error$root17 = error.root) != null && _error$root17.code && error != null && (_error$root18 = error.root) != null && _error$root18.reason) {
1745
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1746
- }
1747
- var updateResult = updateSwapStatus({
1748
- getStorage: getStorage,
1749
- setStorage: setStorage,
1750
- nextStatus: 'failed',
1751
- nextStepStatus: 'failed',
1752
- message: extraMessage,
1753
- details: extraMessageDetail,
1754
- errorCode: extraMessageErrorCode
1755
- });
1756
- notifier(_extends({
1757
- eventType: 'smart_contract_call_failed'
1758
- }, updateResult));
1757
+ var _notification5 = getSwapNotitfication('calling_smart_contract', _updateResult9);
1758
+ notifier(_notification5);
1759
+ if (_notification5.eventType === 'transaction_expired') {
1759
1760
  failed();
1760
1761
  onFinish();
1761
- });
1762
+ } else {
1763
+ walletSigners.getSigner(TransactionType.STARKNET).signAndSendTx(starknetTransaction, walletAddress, null).then(function (id) {
1764
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1765
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1766
+ next();
1767
+ onFinish();
1768
+ }, function (error) {
1769
+ var _error$root16, _error$root17, _error$root18;
1770
+ if (swap.status === 'failed') return;
1771
+ var _prettifyErrorMessage10 = prettifyErrorMessage(error),
1772
+ extraMessage = _prettifyErrorMessage10.extraMessage,
1773
+ extraMessageDetail = _prettifyErrorMessage10.extraMessageDetail,
1774
+ extraMessageErrorCode = _prettifyErrorMessage10.extraMessageErrorCode;
1775
+ if (error && error != null && error.root && error != null && (_error$root16 = error.root) != null && _error$root16.message && error != null && (_error$root17 = error.root) != null && _error$root17.code && error != null && (_error$root18 = error.root) != null && _error$root18.reason) {
1776
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1777
+ }
1778
+ var updateResult = updateSwapStatus({
1779
+ getStorage: getStorage,
1780
+ setStorage: setStorage,
1781
+ nextStatus: 'failed',
1782
+ nextStepStatus: 'failed',
1783
+ message: extraMessage,
1784
+ details: extraMessageDetail,
1785
+ errorCode: extraMessageErrorCode
1786
+ });
1787
+ notifier(_extends({
1788
+ eventType: 'smart_contract_call_failed'
1789
+ }, updateResult));
1790
+ failed();
1791
+ onFinish();
1792
+ });
1793
+ }
1762
1794
  }
1763
1795
  }
1764
1796
  function checkWaitingForConnectWalletChange(params) {
1765
1797
  var wallet_network = params.wallet_network,
1766
1798
  evmChains = params.evmChains,
1767
1799
  manager = params.manager;
1768
- var _wallet_network$split = wallet_network.split('-'),
1769
- wallet = _wallet_network$split[0],
1770
- network = _wallet_network$split[1];
1800
+ var _splitWalletNetwork = splitWalletNetwork(wallet_network),
1801
+ wallet = _splitWalletNetwork[0],
1802
+ network = _splitWalletNetwork[1];
1771
1803
  // We only need change network for EVM chains.
1772
1804
  if (!evmChains.some(function (chain) {
1773
1805
  return chain.name == network;
@@ -1785,7 +1817,7 @@ function checkWaitingForConnectWalletChange(params) {
1785
1817
  var task = q.list.state.tasks[taskId];
1786
1818
  return task.status === Status.BLOCKED && [BlockReason.WAIT_FOR_CONNECT_WALLET].includes((_task$blockedFor = task.blockedFor) == null ? void 0 : _task$blockedFor.reason);
1787
1819
  });
1788
- if (currentStepRequiredWallet === wallet && hasWaitingForConnect) {
1820
+ if (currentStepRequiredWallet === wallet && hasWaitingForConnect && getCurrentBlockchainOfOrNull(swap, currentStep) != network) {
1789
1821
  var queueInstance = q.list;
1790
1822
  var _getRequiredWallet5 = getRequiredWallet(swap),
1791
1823
  type = _getRequiredWallet5.type;
@@ -1849,9 +1881,9 @@ function retryOn(wallet_network, manager, options) {
1849
1881
  fallbackToOnlyWallet: true
1850
1882
  };
1851
1883
  }
1852
- var _wallet_network$split2 = wallet_network.split('-'),
1853
- wallet = _wallet_network$split2[0],
1854
- network = _wallet_network$split2[1];
1884
+ var _splitWalletNetwork2 = splitWalletNetwork(wallet_network),
1885
+ wallet = _splitWalletNetwork2[0],
1886
+ network = _splitWalletNetwork2[1];
1855
1887
  if (!wallet || !network) {
1856
1888
  return;
1857
1889
  }
@@ -2005,6 +2037,7 @@ function _checkTransactionStatus() {
2005
2037
  currentStep.starknetTransaction = null;
2006
2038
  currentStep.tronApprovalTransaction = null;
2007
2039
  currentStep.tronTransaction = null;
2040
+ currentStep.fromBlockchain = newTransaction.blockChain;
2008
2041
  if (isEvmTransaction(newTransaction)) {
2009
2042
  if (newTransaction.isApprovalTx) currentStep.evmApprovalTransaction = newTransaction;else currentStep.evmTransaction = newTransaction;
2010
2043
  } else if (isCosmosTransaction(newTransaction)) {
@@ -2271,7 +2304,7 @@ function executeTransaction(_x) {
2271
2304
  function _executeTransaction() {
2272
2305
  _executeTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
2273
2306
  var _context$_queue;
2274
- var getStorage, context, meta, wallets, providers, isClaimed, requestBlock, swap, currentStep, isWrongAddress, _getRequiredWallet, type, address, description, blockedFor, needsToBlockQueue, _blockedFor, networkMatched, fromBlockchain, details, _blockedFor2;
2307
+ 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;
2275
2308
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2276
2309
  while (1) switch (_context.prev = _context.next) {
2277
2310
  case 0:
@@ -2290,25 +2323,31 @@ function _executeTransaction() {
2290
2323
  /* Make sure wallet is connected and also the connected wallet is matched with tx by checking address. */
2291
2324
  isWrongAddress = !isRequiredWalletConnected(swap, context.state);
2292
2325
  if (!isWrongAddress) {
2293
- _context.next = 14;
2326
+ _context.next = 15;
2294
2327
  break;
2295
2328
  }
2296
2329
  _getRequiredWallet = getRequiredWallet(swap), type = _getRequiredWallet.type, address = _getRequiredWallet.address;
2297
- description = !wallets ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
2330
+ isWalletInCompatible = wallets == null ? void 0 : (_wallets$blockchains = wallets.blockchains) == null ? void 0 : _wallets$blockchains.find(function (w) {
2331
+ var _w$accounts;
2332
+ return !((_w$accounts = w.accounts) != null && _w$accounts.find(function (account) {
2333
+ return account.walletType === type;
2334
+ }));
2335
+ });
2336
+ description = !wallets || isWalletInCompatible ? ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION(type) : ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address);
2298
2337
  blockedFor = {
2299
2338
  reason: BlockReason.WAIT_FOR_CONNECT_WALLET,
2300
2339
  description: description
2301
2340
  };
2302
2341
  requestBlock(blockedFor);
2303
2342
  return _context.abrupt("return");
2304
- case 14:
2343
+ case 15:
2305
2344
  /*
2306
2345
  For avoiding conflict by making too many requests to wallet, we need to make sure
2307
2346
  We only run one request at a time (In parallel mode).
2308
2347
  */
2309
2348
  needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
2310
2349
  if (!(needsToBlockQueue && !isClaimed && context.claimedBy)) {
2311
- _context.next = 19;
2350
+ _context.next = 20;
2312
2351
  break;
2313
2352
  }
2314
2353
  _blockedFor = {
@@ -2318,13 +2357,13 @@ function _executeTransaction() {
2318
2357
  };
2319
2358
  requestBlock(_blockedFor);
2320
2359
  return _context.abrupt("return");
2321
- case 19:
2322
- _context.next = 21;
2360
+ case 20:
2361
+ _context.next = 22;
2323
2362
  return isNetworkMatchedForTransaction(swap, currentStep, wallets, meta, providers);
2324
- case 21:
2363
+ case 22:
2325
2364
  networkMatched = _context.sent;
2326
2365
  if (networkMatched) {
2327
- _context.next = 30;
2366
+ _context.next = 31;
2328
2367
  break;
2329
2368
  }
2330
2369
  fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
@@ -2335,17 +2374,17 @@ function _executeTransaction() {
2335
2374
  };
2336
2375
  requestBlock(_blockedFor2);
2337
2376
  return _context.abrupt("return");
2338
- case 30:
2377
+ case 31:
2339
2378
  // Update network to mark it as network changed successfully.
2340
2379
  updateNetworkStatus(actions, {
2341
2380
  message: '',
2342
2381
  details: 'Wallet network changed successfully',
2343
2382
  status: PendingSwapNetworkStatus.NetworkChanged
2344
2383
  });
2345
- case 31:
2384
+ case 32:
2346
2385
  // All the conditions are met. We can safely send the tx to wallet for sign.
2347
2386
  singTransaction(actions);
2348
- case 32:
2387
+ case 33:
2349
2388
  case "end":
2350
2389
  return _context.stop();
2351
2390
  }