@rango-dev/queue-manager-rango-preset 0.1.15-next.2 → 0.1.15-next.4

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.
@@ -637,21 +637,17 @@ var getCurrentBlockchainOf = function getCurrentBlockchainOf(swap, step) {
637
637
  // TODO: check why it returns string
638
638
  return blockchain;
639
639
  };
640
- var getEvmApproveUrl = function getEvmApproveUrl(tx, network, evmBasedBlockchains) {
641
- var evmBlochain = evmBasedBlockchains.find(function (blockchain) {
642
- return blockchain.name === network;
643
- });
644
- if (!evmBlochain) {
645
- throw Error("unsupported network: " + network + " for getting approve url.");
646
- }
647
- if (evmBlochain.info.transactionUrl) return evmBlochain.info.transactionUrl.replace('{txHash}', tx.toLowerCase());
648
- throw Error("Explorer url for " + network + " is not implemented");
640
+ var getBlockchainMetaExplorerBaseUrl = function getBlockchainMetaExplorerBaseUrl(blockchainMeta) {
641
+ var _blockchainMeta$info;
642
+ if (rangoTypes.isCosmosBlockchain(blockchainMeta)) return (_blockchainMeta$info = blockchainMeta.info) == null ? void 0 : _blockchainMeta$info.explorerUrlToTx;else if (rangoTypes.isEvmBlockchain(blockchainMeta) || rangoTypes.isStarknetBlockchain(blockchainMeta) || rangoTypes.isTronBlockchain(blockchainMeta)) return blockchainMeta.info.transactionUrl;
643
+ return;
649
644
  };
650
- var getStarknetApproveUrl = function getStarknetApproveUrl(tx) {
651
- return 'https://starkscan.co/tx/{txHash}'.replace('{txHash}', tx.toLowerCase());
652
- };
653
- var getTronApproveUrl = function getTronApproveUrl(tx) {
654
- return 'https://tronscan.org/#/transaction/{txHash}'.replace('{txHash}', tx.toLowerCase());
645
+ var getScannerUrl = function getScannerUrl(txHash, network, blockchainMetaMap) {
646
+ var blockchainMeta = blockchainMetaMap[network];
647
+ var baseUrl = getBlockchainMetaExplorerBaseUrl(blockchainMeta);
648
+ if (!baseUrl) return;
649
+ if (baseUrl.indexOf('/{txHash}') !== -1) return baseUrl.replace('{txHash}', txHash == null ? void 0 : txHash.toLowerCase());
650
+ return baseUrl + "/" + (txHash == null ? void 0 : txHash.toLowerCase());
655
651
  };
656
652
  function getNextStep(swap, currentStep) {
657
653
  return swap.steps.find(function (step) {
@@ -837,6 +833,23 @@ function claimQueue() {
837
833
  }
838
834
  };
839
835
  }
836
+ /**
837
+ *
838
+ * We use module-level variable to keep track of
839
+ * map of transactions hash to the TransactionResponse
840
+ *
841
+ */
842
+ var swapTransactionToResponseMap = {};
843
+ function useTransactionsResponse() {
844
+ return {
845
+ getTransactionResponseByHash: function getTransactionResponseByHash(hash) {
846
+ return swapTransactionToResponseMap[hash];
847
+ },
848
+ setTransactionResponseByHash: function setTransactionResponseByHash(hash, response) {
849
+ swapTransactionToResponseMap[hash] = response;
850
+ }
851
+ };
852
+ }
840
853
  /**
841
854
  * Sample inputs are:
842
855
  * - "metamask-ETH"
@@ -867,6 +880,73 @@ var getCurrentStep = function getCurrentStep(swap) {
867
880
  return step.status !== 'failed' && step.status !== 'success';
868
881
  }) || null;
869
882
  };
883
+ /**
884
+ *
885
+ * Returns current step transaction
886
+ *
887
+ */
888
+ var getCurrentStepTx = function getCurrentStepTx(currentStep) {
889
+ var evmTransaction = currentStep.evmTransaction,
890
+ evmApprovalTransaction = currentStep.evmApprovalTransaction,
891
+ cosmosTransaction = currentStep.cosmosTransaction,
892
+ solanaTransaction = currentStep.solanaTransaction,
893
+ transferTransaction = currentStep.transferTransaction,
894
+ starknetApprovalTransaction = currentStep.starknetApprovalTransaction,
895
+ starknetTransaction = currentStep.starknetTransaction,
896
+ tronApprovalTransaction = currentStep.tronApprovalTransaction,
897
+ tronTransaction = currentStep.tronTransaction;
898
+ return evmTransaction || evmApprovalTransaction || cosmosTransaction || solanaTransaction || transferTransaction || starknetApprovalTransaction || starknetTransaction || tronApprovalTransaction || tronTransaction;
899
+ };
900
+ /**
901
+ *
902
+ * Set current step transaction
903
+ *
904
+ */
905
+ var setCurrentStepTx = function setCurrentStepTx(currentStep, transaction) {
906
+ currentStep.transferTransaction = null;
907
+ currentStep.cosmosTransaction = null;
908
+ currentStep.evmTransaction = null;
909
+ currentStep.solanaTransaction = null;
910
+ currentStep.evmApprovalTransaction = null;
911
+ currentStep.starknetApprovalTransaction = null;
912
+ currentStep.starknetTransaction = null;
913
+ currentStep.tronApprovalTransaction = null;
914
+ currentStep.tronTransaction = null;
915
+ if (rangoSdk.isEvmTransaction(transaction)) {
916
+ if (transaction.isApprovalTx) currentStep.evmApprovalTransaction = transaction;else currentStep.evmTransaction = transaction;
917
+ } else if (rangoSdk.isCosmosTransaction(transaction)) {
918
+ currentStep.cosmosTransaction = transaction;
919
+ } else if (rangoSdk.isSolanaTransaction(transaction)) {
920
+ currentStep.solanaTransaction = transaction;
921
+ } else if (rangoSdk.isTransferTransaction(transaction)) {
922
+ currentStep.transferTransaction = transaction;
923
+ } else if (rangoSdk.isStarknetTransaction(transaction)) {
924
+ if (transaction.isApprovalTx) currentStep.starknetApprovalTransaction = transaction;else currentStep.starknetTransaction = transaction;
925
+ } else if (rangoSdk.isTronTransaction(transaction)) {
926
+ if (transaction.isApprovalTx) currentStep.tronApprovalTransaction = transaction;else currentStep.tronTransaction = transaction;
927
+ }
928
+ return currentStep;
929
+ };
930
+ /**
931
+ *
932
+ * Returns current step transaction type
933
+ *
934
+ */
935
+ var getCurrentStepTxType = function getCurrentStepTxType(currentStep) {
936
+ var _getCurrentStepTx;
937
+ return (_getCurrentStepTx = getCurrentStepTx(currentStep)) == null ? void 0 : _getCurrentStepTx.type;
938
+ };
939
+ /**
940
+ *
941
+ * Returns a boolean indicating that current step is an approval tx or not.
942
+ *
943
+ */
944
+ var isApprovalCurrentStepTx = function isApprovalCurrentStepTx(currentStep) {
945
+ var evmApprovalTransaction = currentStep.evmApprovalTransaction,
946
+ starknetApprovalTransaction = currentStep.starknetApprovalTransaction,
947
+ tronApprovalTransaction = currentStep.tronApprovalTransaction;
948
+ return !!(evmApprovalTransaction || starknetApprovalTransaction || tronApprovalTransaction);
949
+ };
870
950
  /**
871
951
  * When we are doing a swap, there are some common fields that will be updated together.
872
952
  * This function helps us to update a swap status and also it will update some more fields like `extraMessageSeverity` based on the input.
@@ -916,7 +996,12 @@ function updateSwapStatus(_ref) {
916
996
  step: currentStep
917
997
  };
918
998
  }
919
- function setStepTransactionIds(_ref2, txId, notifier, eventType, approveUrl) {
999
+ /**
1000
+ *
1001
+ * Set current step transaction hash, update pending swap status, and notify user if needed
1002
+ *
1003
+ */
1004
+ function setStepTransactionIds(_ref2, txId, notifier, eventType, explorerUrl) {
920
1005
  var getStorage = _ref2.getStorage,
921
1006
  setStorage = _ref2.setStorage;
922
1007
  var swap = getStorage().swapDetails;
@@ -925,9 +1010,9 @@ function setStepTransactionIds(_ref2, txId, notifier, eventType, approveUrl) {
925
1010
  var currentStep = getCurrentStep(swap);
926
1011
  currentStep.executedTransactionId = txId;
927
1012
  currentStep.executedTransactionTime = new Date().getTime().toString();
928
- if (!!approveUrl) currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
929
- url: approveUrl,
930
- description: "approve"
1013
+ if (!!(explorerUrl != null && explorerUrl.url)) currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
1014
+ url: explorerUrl.url,
1015
+ description: explorerUrl.description || null
931
1016
  }]);
932
1017
  if (eventType === 'check_tx_status') {
933
1018
  swap.extraMessage = 'Checking transaction status ...';
@@ -947,15 +1032,6 @@ function setStepTransactionIds(_ref2, txId, notifier, eventType, approveUrl) {
947
1032
  step: currentStep
948
1033
  });
949
1034
  }
950
- function getSwapNotitfication(eventType, updateResult) {
951
- if (updateResult.swap.hasAlreadyProceededToSign) {
952
- return _extends({
953
- eventType: 'transaction_expired'
954
- }, updateResult);
955
- } else return _extends({
956
- eventType: eventType
957
- }, updateResult);
958
- }
959
1035
  /**
960
1036
  * If a swap needs a wallet to be connected,
961
1037
  * By calling this function some related fields will be updated to show a correct message and state for notfiying the user.
@@ -1040,24 +1116,6 @@ function delay(ms) {
1040
1116
  return setTimeout(res, ms);
1041
1117
  });
1042
1118
  }
1043
- var isEvmTransaction = function isEvmTransaction(tx) {
1044
- return tx.type === rangoSdk.TransactionType.EVM;
1045
- };
1046
- var isCosmosTransaction = function isCosmosTransaction(tx) {
1047
- return tx.type === rangoSdk.TransactionType.COSMOS;
1048
- };
1049
- var isSolanaTransaction = function isSolanaTransaction(tx) {
1050
- return tx.type === rangoSdk.TransactionType.SOLANA;
1051
- };
1052
- var isTrasnferTransaction = function isTrasnferTransaction(tx) {
1053
- return tx.type === rangoSdk.TransactionType.TRANSFER;
1054
- };
1055
- var isStarknetTransaction = function isStarknetTransaction(tx) {
1056
- return tx.type === rangoSdk.TransactionType.STARKNET;
1057
- };
1058
- var isTronTransaction = function isTronTransaction(tx) {
1059
- return tx.type === rangoSdk.TransactionType.TRON;
1060
- };
1061
1119
  /**
1062
1120
  *
1063
1121
  * To execute a swap, we are keeping the user prefrences on what wallet they are going to use for a sepecific blockchain
@@ -1203,8 +1261,8 @@ function _isNetworkMatchedForTransaction() {
1203
1261
  _context2.next = 19;
1204
1262
  break;
1205
1263
  }
1206
- blockChain = walletsShared.getBlockChainNameFromId(chainId, Object.entries(meta.blockchains).map(function (_ref6) {
1207
- var blockchainMeta = _ref6[1];
1264
+ blockChain = walletsShared.getBlockChainNameFromId(chainId, Object.entries(meta.blockchains).map(function (_ref7) {
1265
+ var blockchainMeta = _ref7[1];
1208
1266
  return blockchainMeta;
1209
1267
  }));
1210
1268
  if (!(blockChain && blockChain.toLowerCase() === fromBlockChain.toLowerCase())) {
@@ -1443,6 +1501,8 @@ function isRequiredWalletConnected(swap, getState) {
1443
1501
  };
1444
1502
  }
1445
1503
  function singTransaction(actions) {
1504
+ var _useTransactionsRespo = useTransactionsResponse(),
1505
+ setTransactionResponseByHash = _useTransactionsRespo.setTransactionResponseByHash;
1446
1506
  var getStorage = actions.getStorage,
1447
1507
  setStorage = actions.setStorage,
1448
1508
  failed = actions.failed,
@@ -1456,451 +1516,99 @@ function singTransaction(actions) {
1456
1516
  var swap = getStorage().swapDetails;
1457
1517
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1458
1518
  var currentStep = getCurrentStep(swap);
1459
- var evmTransaction = currentStep.evmTransaction,
1460
- evmApprovalTransaction = currentStep.evmApprovalTransaction,
1461
- cosmosTransaction = currentStep.cosmosTransaction,
1462
- solanaTransaction = currentStep.solanaTransaction,
1463
- transferTransaction = currentStep.transferTransaction,
1464
- tronTransaction = currentStep.tronTransaction,
1465
- tronApprovalTransaction = currentStep.tronApprovalTransaction,
1466
- starknetTransaction = currentStep.starknetTransaction,
1467
- starknetApprovalTransaction = currentStep.starknetApprovalTransaction;
1468
1519
  var sourceWallet = getRelatedWallet(swap, currentStep);
1520
+ var mobileWallet = isMobileWallet(sourceWallet == null ? void 0 : sourceWallet.walletType);
1469
1521
  var walletAddress = getCurrentAddressOf(swap, currentStep);
1470
1522
  var walletSigners = getSigners(sourceWallet.walletType);
1471
- var mobileWallet = isMobileWallet(sourceWallet.walletType);
1523
+ var currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
1472
1524
  var onFinish = function onFinish() {
1473
1525
  // TODO resetClaimedBy is undefined here
1474
1526
  if (actions.context.resetClaimedBy) {
1475
1527
  actions.context.resetClaimedBy();
1476
1528
  }
1477
1529
  };
1478
- if (!!evmApprovalTransaction) {
1479
- var spenderContract = evmApprovalTransaction == null ? void 0 : evmApprovalTransaction.to;
1480
- if (!spenderContract) throw PrettyError.AssertionFailed('contract address is null for checking approval');
1481
- // Update swap status
1482
- var message = "Waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (mobileWallet ? 'on your mobile phone' : '');
1530
+ var tx = getCurrentStepTx(currentStep);
1531
+ var txType = tx == null ? void 0 : tx.type;
1532
+ var isApproval = isApprovalCurrentStepTx(currentStep);
1533
+ var isSmartContractCall = [rangoSdk.TransactionType.EVM, rangoSdk.TransactionType.STARKNET, rangoSdk.TransactionType.TRON].includes(txType);
1534
+ var hasAlreadyProceededToSign = typeof swap.hasAlreadyProceededToSign === 'boolean';
1535
+ var nextStatus, nextStepStatus, eventType, message, details;
1536
+ if (isApproval) {
1537
+ message = "Waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (mobileWallet ? 'on your mobile phone!' : '');
1538
+ details = 'Waiting for approve transaction to be mined and confirmed successfully';
1539
+ nextStepStatus = 'waitingForApproval';
1540
+ nextStatus = undefined;
1541
+ eventType = 'confirm_approve_contract';
1542
+ } else if (hasAlreadyProceededToSign) {
1543
+ message = 'Transaction is expired. Please try again.';
1544
+ nextStepStatus = 'failed';
1545
+ nextStatus = 'failed';
1546
+ details = '';
1547
+ eventType = 'transaction_expired';
1548
+ } else {
1549
+ message = 'Executing transaction ...';
1550
+ nextStepStatus = 'running';
1551
+ nextStatus = 'running';
1552
+ details = "" + (mobileWallet ? 'Check your mobile phone!' : '');
1553
+ eventType = isSmartContractCall ? 'calling_smart_contract' : 'confirm_transfer';
1554
+ }
1555
+ var updateResult = updateSwapStatus({
1556
+ getStorage: getStorage,
1557
+ setStorage: setStorage,
1558
+ nextStepStatus: nextStepStatus,
1559
+ nextStatus: nextStatus,
1560
+ message: message,
1561
+ details: details,
1562
+ hasAlreadyProceededToSign: isApproval ? undefined : hasAlreadyProceededToSign,
1563
+ errorCode: hasAlreadyProceededToSign ? 'TX_EXPIRED' : undefined
1564
+ });
1565
+ notifier(_extends({
1566
+ eventType: eventType
1567
+ }, updateResult));
1568
+ if (hasAlreadyProceededToSign) {
1569
+ failed();
1570
+ onFinish();
1571
+ return;
1572
+ }
1573
+ var signer = walletSigners.getSigner(txType);
1574
+ signer.signAndSendTx(tx, walletAddress, null).then(function (_ref6) {
1575
+ var hash = _ref6.hash,
1576
+ response = _ref6.response;
1577
+ var explorerUrl = getScannerUrl(hash, currentStepBlockchain, meta.blockchains);
1578
+ setStepTransactionIds(actions, hash, notifier, isApproval ? 'check_approve_tx_status' : 'check_tx_status', explorerUrl ? {
1579
+ url: explorerUrl,
1580
+ description: isApproval ? 'Approve' : 'Swap'
1581
+ } : undefined);
1582
+ // response used for evm transactions to get receipt and track replaced
1583
+ response && setTransactionResponseByHash(hash, response);
1584
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1585
+ next();
1586
+ onFinish();
1587
+ }, function (error) {
1588
+ var _error$root, _error$root2, _error$root3;
1589
+ if (swap.status === 'failed') return;
1590
+ var _prettifyErrorMessage = prettifyErrorMessage(error),
1591
+ extraMessage = _prettifyErrorMessage.extraMessage,
1592
+ extraMessageDetail = _prettifyErrorMessage.extraMessageDetail,
1593
+ extraMessageErrorCode = _prettifyErrorMessage.extraMessageErrorCode;
1594
+ // if it is an rpc error with details, send the log to sentry
1595
+ 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) logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1483
1596
  var updateResult = updateSwapStatus({
1484
1597
  getStorage: getStorage,
1485
1598
  setStorage: setStorage,
1486
- nextStepStatus: 'waitingForApproval',
1487
- message: message,
1488
- details: 'Waiting for approve transaction to be mined and confirmed successfully'
1599
+ nextStatus: 'failed',
1600
+ nextStepStatus: 'failed',
1601
+ message: extraMessage,
1602
+ details: extraMessageDetail,
1603
+ errorCode: extraMessageErrorCode
1489
1604
  });
1605
+ var eventType = extraMessageErrorCode === 'REJECTED_BY_USER' ? 'contract_rejected' : isSmartContractCall ? 'smart_contract_call_failed' : 'transfer_failed';
1490
1606
  notifier(_extends({
1491
- eventType: 'confirm_approve_contract'
1607
+ eventType: eventType
1492
1608
  }, updateResult));
1493
- // Execute transaction
1494
- walletSigners.getSigner(rangoSdk.TransactionType.EVM).signAndSendTx(evmApprovalTransaction, walletAddress, null).then(function (hash) {
1495
- var approveUrl = getEvmApproveUrl(hash, getCurrentBlockchainOf(swap, currentStep), meta.evmBasedChains);
1496
- setStepTransactionIds(actions, hash, notifier, 'check_approve_tx_status', approveUrl);
1497
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1498
- next();
1499
- onFinish();
1500
- }, function (error) {
1501
- var _error$root, _error$root2, _error$root3;
1502
- if (swap.status === 'failed') return;
1503
- var _prettifyErrorMessage = prettifyErrorMessage(error),
1504
- extraMessage = _prettifyErrorMessage.extraMessage,
1505
- extraMessageDetail = _prettifyErrorMessage.extraMessageDetail,
1506
- extraMessageErrorCode = _prettifyErrorMessage.extraMessageErrorCode;
1507
- 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) {
1508
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1509
- }
1510
- var updateResult = updateSwapStatus({
1511
- getStorage: getStorage,
1512
- setStorage: setStorage,
1513
- nextStatus: 'failed',
1514
- nextStepStatus: 'failed',
1515
- message: extraMessage,
1516
- details: extraMessageDetail,
1517
- errorCode: extraMessageErrorCode
1518
- });
1519
- notifier(_extends({
1520
- eventType: extraMessageErrorCode === 'REJECTED_BY_USER' ? 'contract_rejected' : 'smart_contract_call_failed'
1521
- }, updateResult));
1522
- failed();
1523
- onFinish();
1524
- });
1525
- return;
1526
- } else if (!!tronApprovalTransaction) {
1527
- // Update swap status
1528
- var _message = "Waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (mobileWallet ? 'on your mobile phone' : '');
1529
- var _updateResult = updateSwapStatus({
1530
- getStorage: getStorage,
1531
- setStorage: setStorage,
1532
- nextStepStatus: 'waitingForApproval',
1533
- message: _message,
1534
- details: 'Waiting for approve transaction to be mined and confirmed successfully'
1535
- });
1536
- notifier(_extends({
1537
- eventType: 'confirm_approve_contract'
1538
- }, _updateResult));
1539
- // Execute transaction
1540
- walletSigners.getSigner(rangoSdk.TransactionType.TRON).signAndSendTx(tronApprovalTransaction, walletAddress, null).then(function (hash) {
1541
- var approveUrl = getTronApproveUrl(hash);
1542
- setStepTransactionIds(actions, hash, notifier, 'check_approve_tx_status', approveUrl);
1543
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1544
- next();
1545
- onFinish();
1546
- }, function (error) {
1547
- var _error$root4, _error$root5, _error$root6;
1548
- if (swap.status === 'failed') return;
1549
- var _prettifyErrorMessage2 = prettifyErrorMessage(error),
1550
- extraMessage = _prettifyErrorMessage2.extraMessage,
1551
- extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail,
1552
- extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
1553
- 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) {
1554
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1555
- }
1556
- var updateResult = updateSwapStatus({
1557
- getStorage: getStorage,
1558
- setStorage: setStorage,
1559
- nextStatus: 'failed',
1560
- nextStepStatus: 'failed',
1561
- message: extraMessage,
1562
- details: extraMessageDetail,
1563
- errorCode: extraMessageErrorCode
1564
- });
1565
- notifier(_extends({
1566
- eventType: extraMessageErrorCode === 'REJECTED_BY_USER' ? 'contract_rejected' : 'smart_contract_call_failed'
1567
- }, updateResult));
1568
- failed();
1569
- onFinish();
1570
- });
1571
- return;
1572
- } else if (!!starknetApprovalTransaction) {
1573
- // Update swap status
1574
- var _message2 = "Waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (mobileWallet ? 'on your mobile phone' : '');
1575
- var _updateResult2 = updateSwapStatus({
1576
- getStorage: getStorage,
1577
- setStorage: setStorage,
1578
- nextStepStatus: 'waitingForApproval',
1579
- message: _message2,
1580
- details: 'Waiting for approve transaction to be mined and confirmed successfully'
1581
- });
1582
- notifier(_extends({
1583
- eventType: 'confirm_approve_contract'
1584
- }, _updateResult2));
1585
- // Execute transaction
1586
- walletSigners.getSigner(rangoSdk.TransactionType.STARKNET).signAndSendTx(starknetApprovalTransaction, walletAddress, null).then(function (hash) {
1587
- var approveUrl = getStarknetApproveUrl(hash);
1588
- setStepTransactionIds(actions, hash, notifier, 'check_approve_tx_status', approveUrl);
1589
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1590
- next();
1591
- onFinish();
1592
- }, function (error) {
1593
- var _error$root7, _error$root8, _error$root9;
1594
- if (swap.status === 'failed') return;
1595
- var _prettifyErrorMessage3 = prettifyErrorMessage(error),
1596
- extraMessage = _prettifyErrorMessage3.extraMessage,
1597
- extraMessageDetail = _prettifyErrorMessage3.extraMessageDetail,
1598
- extraMessageErrorCode = _prettifyErrorMessage3.extraMessageErrorCode;
1599
- if (error && error != null && error.root && error != null && (_error$root7 = error.root) != null && _error$root7.message && error != null && (_error$root8 = error.root) != null && _error$root8.code && error != null && (_error$root9 = error.root) != null && _error$root9.reason) {
1600
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1601
- }
1602
- var updateResult = updateSwapStatus({
1603
- getStorage: getStorage,
1604
- setStorage: setStorage,
1605
- nextStatus: 'failed',
1606
- nextStepStatus: 'failed',
1607
- message: extraMessage,
1608
- details: extraMessageDetail,
1609
- errorCode: extraMessageErrorCode
1610
- });
1611
- notifier(_extends({
1612
- eventType: extraMessageErrorCode === 'REJECTED_BY_USER' ? 'contract_rejected' : 'smart_contract_call_failed'
1613
- }, updateResult));
1614
- failed();
1615
- onFinish();
1616
- });
1617
- return;
1618
- }
1619
- var hasAlreadyProceededToSign = typeof swap.hasAlreadyProceededToSign === 'boolean';
1620
- var nextStepStatusBasedOnHasAlreadyProceededToSign = hasAlreadyProceededToSign ? 'failed' : 'running';
1621
- var errorCodeBasedOnHasAlreadyProceededToSign = hasAlreadyProceededToSign ? 'TX_EXPIRED' : null;
1622
- var executeMessage = hasAlreadyProceededToSign ? 'Transaction is expired. Please try again' : 'executing transaction';
1623
- var executeDetails = mobileWallet ? 'Check your mobile phone' : '';
1624
- if (!!transferTransaction) {
1625
- var _updateResult3 = updateSwapStatus({
1626
- getStorage: getStorage,
1627
- setStorage: setStorage,
1628
- nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1629
- nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1630
- message: executeMessage,
1631
- details: executeDetails,
1632
- hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1633
- errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1634
- });
1635
- var notification = getSwapNotitfication('confirm_transfer', _updateResult3);
1636
- notifier(notification);
1637
- if (notification.eventType === 'transaction_expired') {
1638
- failed();
1639
- onFinish();
1640
- } else {
1641
- walletSigners.getSigner(rangoSdk.TransactionType.TRANSFER).signAndSendTx(transferTransaction, walletAddress, null).then(function (txId) {
1642
- setStepTransactionIds(actions, txId, notifier, 'check_tx_status');
1643
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1644
- next();
1645
- onFinish();
1646
- }, function (error) {
1647
- if (swap.status === 'failed') return;
1648
- var _prettifyErrorMessage4 = prettifyErrorMessage(error),
1649
- extraMessage = _prettifyErrorMessage4.extraMessage,
1650
- extraMessageDetail = _prettifyErrorMessage4.extraMessageDetail,
1651
- extraMessageErrorCode = _prettifyErrorMessage4.extraMessageErrorCode;
1652
- var updateResult = updateSwapStatus({
1653
- getStorage: getStorage,
1654
- setStorage: setStorage,
1655
- nextStatus: 'failed',
1656
- nextStepStatus: 'failed',
1657
- message: extraMessage,
1658
- details: extraMessageDetail,
1659
- errorCode: extraMessageErrorCode
1660
- });
1661
- notifier(_extends({
1662
- eventType: extraMessageErrorCode === 'REJECTED_BY_USER' ? 'transfer_rejected' : 'transfer_failed'
1663
- }, updateResult));
1664
- failed();
1665
- onFinish();
1666
- });
1667
- }
1668
- } else if (!!evmTransaction) {
1669
- var _updateResult4 = updateSwapStatus({
1670
- getStorage: getStorage,
1671
- setStorage: setStorage,
1672
- nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1673
- nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1674
- message: executeMessage,
1675
- details: executeDetails,
1676
- hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1677
- errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1678
- });
1679
- var _notification = getSwapNotitfication('calling_smart_contract', _updateResult4);
1680
- notifier(_notification);
1681
- if (_notification.eventType === 'transaction_expired') {
1682
- failed();
1683
- onFinish();
1684
- } else {
1685
- walletSigners.getSigner(rangoSdk.TransactionType.EVM).signAndSendTx(evmTransaction, walletAddress, null).then(function (id) {
1686
- setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1687
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1688
- next();
1689
- onFinish();
1690
- }, function (error) {
1691
- var _error$root10, _error$root11, _error$root12;
1692
- if (swap.status === 'failed') return;
1693
- var _prettifyErrorMessage5 = prettifyErrorMessage(error),
1694
- extraMessage = _prettifyErrorMessage5.extraMessage,
1695
- extraMessageDetail = _prettifyErrorMessage5.extraMessageDetail,
1696
- extraMessageErrorCode = _prettifyErrorMessage5.extraMessageErrorCode;
1697
- if (error && error != null && error.root && error != null && (_error$root10 = error.root) != null && _error$root10.message && error != null && (_error$root11 = error.root) != null && _error$root11.code && error != null && (_error$root12 = error.root) != null && _error$root12.reason) {
1698
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1699
- }
1700
- var updateResult = updateSwapStatus({
1701
- getStorage: getStorage,
1702
- setStorage: setStorage,
1703
- nextStatus: 'failed',
1704
- nextStepStatus: 'failed',
1705
- message: extraMessage,
1706
- details: extraMessageDetail,
1707
- errorCode: extraMessageErrorCode
1708
- });
1709
- notifier(_extends({
1710
- eventType: extraMessageErrorCode === 'REJECTED_BY_USER' ? 'contract_rejected' : 'smart_contract_call_failed'
1711
- }, updateResult));
1712
- failed();
1713
- onFinish();
1714
- });
1715
- }
1716
- } else if (!!cosmosTransaction) {
1717
- var _updateResult5 = updateSwapStatus({
1718
- getStorage: getStorage,
1719
- setStorage: setStorage,
1720
- nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1721
- nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1722
- message: executeMessage,
1723
- details: executeDetails,
1724
- hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1725
- errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1726
- });
1727
- var _notification2 = getSwapNotitfication('calling_smart_contract', _updateResult5);
1728
- notifier(_notification2);
1729
- if (_notification2.eventType === 'transaction_expired') {
1730
- failed();
1731
- onFinish();
1732
- } else {
1733
- walletSigners.getSigner(rangoSdk.TransactionType.COSMOS).signAndSendTx(cosmosTransaction, walletAddress, null).then(
1734
- // todo
1735
- function (id) {
1736
- setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1737
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1738
- next();
1739
- onFinish();
1740
- }, function (error) {
1741
- if (swap.status === 'failed') return;
1742
- var _prettifyErrorMessage6 = prettifyErrorMessage(error),
1743
- extraMessage = _prettifyErrorMessage6.extraMessage,
1744
- extraMessageDetail = _prettifyErrorMessage6.extraMessageDetail,
1745
- extraMessageErrorCode = _prettifyErrorMessage6.extraMessageErrorCode;
1746
- var updateResult = updateSwapStatus({
1747
- getStorage: getStorage,
1748
- setStorage: setStorage,
1749
- nextStatus: 'failed',
1750
- nextStepStatus: 'failed',
1751
- message: extraMessage,
1752
- details: extraMessageDetail,
1753
- errorCode: extraMessageErrorCode
1754
- });
1755
- notifier(_extends({
1756
- eventType: 'smart_contract_call_failed'
1757
- }, updateResult));
1758
- failed();
1759
- onFinish();
1760
- });
1761
- }
1762
- } else if (!!solanaTransaction) {
1763
- var _updateResult6 = updateSwapStatus({
1764
- getStorage: getStorage,
1765
- setStorage: setStorage,
1766
- nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1767
- nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1768
- message: executeMessage,
1769
- details: executeDetails,
1770
- hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1771
- errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1772
- });
1773
- var _notification3 = getSwapNotitfication('calling_smart_contract', _updateResult6);
1774
- notifier(_notification3);
1775
- if (_notification3.eventType === 'transaction_expired') {
1776
- failed();
1777
- onFinish();
1778
- } else {
1779
- var tx = solanaTransaction;
1780
- walletSigners.getSigner(rangoSdk.TransactionType.SOLANA).signAndSendTx(tx, walletAddress, null).then(function (txId) {
1781
- setStepTransactionIds(actions, txId, notifier, 'check_tx_status');
1782
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1783
- next();
1784
- onFinish();
1785
- }, function (error) {
1786
- if (swap.status === 'failed') return;
1787
- var _prettifyErrorMessage7 = prettifyErrorMessage(error),
1788
- extraMessage = _prettifyErrorMessage7.extraMessage,
1789
- extraMessageDetail = _prettifyErrorMessage7.extraMessageDetail,
1790
- extraMessageErrorCode = _prettifyErrorMessage7.extraMessageErrorCode;
1791
- var updateResult = updateSwapStatus({
1792
- getStorage: getStorage,
1793
- setStorage: setStorage,
1794
- nextStatus: 'failed',
1795
- nextStepStatus: 'failed',
1796
- message: extraMessage,
1797
- details: extraMessageDetail,
1798
- errorCode: extraMessageErrorCode
1799
- });
1800
- notifier(_extends({
1801
- eventType: 'smart_contract_call_failed'
1802
- }, updateResult));
1803
- failed();
1804
- onFinish();
1805
- });
1806
- }
1807
- } else if (!!tronTransaction) {
1808
- var _updateResult7 = updateSwapStatus({
1809
- getStorage: getStorage,
1810
- setStorage: setStorage,
1811
- nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1812
- nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1813
- message: executeMessage,
1814
- details: executeDetails,
1815
- hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1816
- errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1817
- });
1818
- var _notification4 = getSwapNotitfication('calling_smart_contract', _updateResult7);
1819
- notifier(_notification4);
1820
- if (_notification4.eventType === 'transaction_expired') {
1821
- failed();
1822
- onFinish();
1823
- } else {
1824
- walletSigners.getSigner(rangoSdk.TransactionType.TRON).signAndSendTx(tronTransaction, walletAddress, null).then(function (id) {
1825
- setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1826
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1827
- next();
1828
- onFinish();
1829
- }, function (error) {
1830
- var _error$root13, _error$root14, _error$root15;
1831
- if (swap.status === 'failed') return;
1832
- var _prettifyErrorMessage8 = prettifyErrorMessage(error),
1833
- extraMessage = _prettifyErrorMessage8.extraMessage,
1834
- extraMessageDetail = _prettifyErrorMessage8.extraMessageDetail,
1835
- extraMessageErrorCode = _prettifyErrorMessage8.extraMessageErrorCode;
1836
- 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) {
1837
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1838
- }
1839
- var updateResult = updateSwapStatus({
1840
- getStorage: getStorage,
1841
- setStorage: setStorage,
1842
- nextStatus: 'failed',
1843
- nextStepStatus: 'failed',
1844
- message: extraMessage,
1845
- details: extraMessageDetail,
1846
- errorCode: extraMessageErrorCode
1847
- });
1848
- notifier(_extends({
1849
- eventType: 'smart_contract_call_failed'
1850
- }, updateResult));
1851
- failed();
1852
- onFinish();
1853
- });
1854
- }
1855
- } else if (!!starknetTransaction) {
1856
- var _updateResult8 = updateSwapStatus({
1857
- getStorage: getStorage,
1858
- setStorage: setStorage,
1859
- nextStepStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1860
- nextStatus: nextStepStatusBasedOnHasAlreadyProceededToSign,
1861
- message: executeMessage,
1862
- details: executeDetails,
1863
- hasAlreadyProceededToSign: hasAlreadyProceededToSign,
1864
- errorCode: errorCodeBasedOnHasAlreadyProceededToSign
1865
- });
1866
- var _notification5 = getSwapNotitfication('calling_smart_contract', _updateResult8);
1867
- notifier(_notification5);
1868
- if (_notification5.eventType === 'transaction_expired') {
1869
- failed();
1870
- onFinish();
1871
- } else {
1872
- walletSigners.getSigner(rangoSdk.TransactionType.STARKNET).signAndSendTx(starknetTransaction, walletAddress, null).then(function (id) {
1873
- setStepTransactionIds(actions, id, notifier, 'check_tx_status');
1874
- schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1875
- next();
1876
- onFinish();
1877
- }, function (error) {
1878
- var _error$root16, _error$root17, _error$root18;
1879
- if (swap.status === 'failed') return;
1880
- var _prettifyErrorMessage9 = prettifyErrorMessage(error),
1881
- extraMessage = _prettifyErrorMessage9.extraMessage,
1882
- extraMessageDetail = _prettifyErrorMessage9.extraMessageDetail,
1883
- extraMessageErrorCode = _prettifyErrorMessage9.extraMessageErrorCode;
1884
- 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) {
1885
- logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1886
- }
1887
- var updateResult = updateSwapStatus({
1888
- getStorage: getStorage,
1889
- setStorage: setStorage,
1890
- nextStatus: 'failed',
1891
- nextStepStatus: 'failed',
1892
- message: extraMessage,
1893
- details: extraMessageDetail,
1894
- errorCode: extraMessageErrorCode
1895
- });
1896
- notifier(_extends({
1897
- eventType: 'smart_contract_call_failed'
1898
- }, updateResult));
1899
- failed();
1900
- onFinish();
1901
- });
1902
- }
1903
- }
1609
+ failed();
1610
+ onFinish();
1611
+ });
1904
1612
  }
1905
1613
  function checkWaitingForConnectWalletChange(params) {
1906
1614
  var wallet_network = params.wallet_network,
@@ -2148,7 +1856,7 @@ function cancelSwap(swap, manager) {
2148
1856
  return updateResult;
2149
1857
  }
2150
1858
 
2151
- var INTERVAL_FOR_CHECK = 3000;
1859
+ var INTERVAL_FOR_CHECK = 5000;
2152
1860
  /**
2153
1861
  * Subscribe to status of swap transaction by checking from server periodically.
2154
1862
  * After getting the status, notify the user and schedule `SCHEDULE_NEXT_STEP`.
@@ -2163,42 +1871,110 @@ function checkTransactionStatus(_x) {
2163
1871
  function _checkTransactionStatus() {
2164
1872
  _checkTransactionStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
2165
1873
  var _status, _status2, _status3, _status4, _status5, _status6, _status7, _status9, _status10, _status11;
2166
- var getStorage, setStorage, next, schedule, retry, failed, context, swap, currentStep, txId, status, outputAmount, prevOutputAmount, newTransaction, nextStep, _status8;
1874
+ var getStorage, setStorage, next, schedule, retry, failed, context, swap, meta, currentStep, txId, getTxReceiptFailed, status, signer, _useTransactionsRespo, getTransactionResponseByHash, setTransactionResponseByHash, txType, sourceWallet, _signer, txResponse, _yield$signer$wait, updatedTxHash, updatedTxResponse, currentStepBlockchain, explorerUrl, _currentStep$explorer, _prettifyErrorMessage, extraMessage, extraMessageDetail, extraMessageErrorCode, updateResult, outputAmount, prevOutputAmount, newTransaction, nextStep, _status8;
2167
1875
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2168
1876
  while (1) switch (_context.prev = _context.next) {
2169
1877
  case 0:
2170
1878
  getStorage = _ref.getStorage, setStorage = _ref.setStorage, next = _ref.next, schedule = _ref.schedule, retry = _ref.retry, failed = _ref.failed, context = _ref.context;
2171
- swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1879
+ swap = getStorage().swapDetails;
1880
+ meta = context.meta; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2172
1881
  currentStep = getCurrentStep(swap);
2173
1882
  txId = currentStep.executedTransactionId;
1883
+ getTxReceiptFailed = false;
2174
1884
  status = null;
2175
- _context.prev = 5;
2176
- _context.next = 8;
1885
+ signer = null;
1886
+ _useTransactionsRespo = useTransactionsResponse(), getTransactionResponseByHash = _useTransactionsRespo.getTransactionResponseByHash, setTransactionResponseByHash = _useTransactionsRespo.setTransactionResponseByHash;
1887
+ try {
1888
+ txType = getCurrentStepTxType(currentStep);
1889
+ sourceWallet = getRelatedWallet(swap, currentStep);
1890
+ if (txType && sourceWallet) signer = context.getSigners(sourceWallet.walletType).getSigner(txType);
1891
+ } catch (error) {
1892
+ // wallet is not connected yet
1893
+ // no need to do anything
1894
+ }
1895
+ _context.prev = 10;
1896
+ if (!((_signer = signer) != null && _signer.wait)) {
1897
+ _context.next = 19;
1898
+ break;
1899
+ }
1900
+ txResponse = getTransactionResponseByHash(txId);
1901
+ _context.next = 15;
1902
+ return signer.wait(txId, txResponse);
1903
+ case 15:
1904
+ _yield$signer$wait = _context.sent;
1905
+ updatedTxHash = _yield$signer$wait.hash;
1906
+ updatedTxResponse = _yield$signer$wait.response;
1907
+ if (updatedTxHash !== txId) {
1908
+ currentStep.executedTransactionId = updatedTxHash || currentStep.executedTransactionId;
1909
+ currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
1910
+ explorerUrl = getScannerUrl(currentStep.executedTransactionId, currentStepBlockchain, meta.blockchains);
1911
+ if (explorerUrl) {
1912
+ if (currentStep.explorerUrl && ((_currentStep$explorer = currentStep.explorerUrl) == null ? void 0 : _currentStep$explorer.length) >= 1) {
1913
+ currentStep.explorerUrl[currentStep.explorerUrl.length - 1] = {
1914
+ url: explorerUrl,
1915
+ description: 'Replaced Swap'
1916
+ };
1917
+ }
1918
+ }
1919
+ txId = currentStep.executedTransactionId;
1920
+ if (updatedTxHash && updatedTxResponse) setTransactionResponseByHash(updatedTxHash, updatedTxResponse);
1921
+ }
1922
+ case 19:
1923
+ _context.next = 27;
1924
+ break;
1925
+ case 21:
1926
+ _context.prev = 21;
1927
+ _context.t0 = _context["catch"](10);
1928
+ _prettifyErrorMessage = prettifyErrorMessage(_context.t0), extraMessage = _prettifyErrorMessage.extraMessage, extraMessageDetail = _prettifyErrorMessage.extraMessageDetail, extraMessageErrorCode = _prettifyErrorMessage.extraMessageErrorCode;
1929
+ updateResult = updateSwapStatus({
1930
+ getStorage: getStorage,
1931
+ setStorage: setStorage,
1932
+ nextStatus: 'failed',
1933
+ nextStepStatus: 'failed',
1934
+ message: extraMessage,
1935
+ details: extraMessageDetail,
1936
+ errorCode: extraMessageErrorCode
1937
+ });
1938
+ context == null ? void 0 : context.notifier(_extends({
1939
+ eventType: 'task_failed'
1940
+ }, updateResult));
1941
+ getTxReceiptFailed = true;
1942
+ // We shouldn't return here, because we need to trigger check status job in backend.
1943
+ // This is not a ui requirement but the backend one.
1944
+ case 27:
1945
+ _context.prev = 27;
1946
+ _context.next = 30;
2177
1947
  return httpService().checkStatus({
2178
1948
  requestId: swap.requestId,
2179
1949
  txId: txId,
2180
1950
  step: currentStep.id
2181
1951
  });
2182
- case 8:
1952
+ case 30:
2183
1953
  status = _context.sent;
2184
- _context.next = 17;
1954
+ _context.next = 39;
2185
1955
  break;
2186
- case 11:
2187
- _context.prev = 11;
2188
- _context.t0 = _context["catch"](5);
2189
- _context.next = 15;
1956
+ case 33:
1957
+ _context.prev = 33;
1958
+ _context.t1 = _context["catch"](27);
1959
+ _context.next = 37;
2190
1960
  return delay(INTERVAL_FOR_CHECK);
2191
- case 15:
1961
+ case 37:
2192
1962
  retry();
2193
1963
  return _context.abrupt("return");
2194
- case 17:
1964
+ case 39:
1965
+ if (!getTxReceiptFailed) {
1966
+ _context.next = 41;
1967
+ break;
1968
+ }
1969
+ return _context.abrupt("return", failed());
1970
+ case 41:
2195
1971
  if (!((currentStep == null ? void 0 : currentStep.status) === 'failed')) {
2196
- _context.next = 19;
1972
+ _context.next = 43;
2197
1973
  break;
2198
1974
  }
2199
1975
  return _context.abrupt("return");
2200
- case 19:
2201
- outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? currentStep.outputAmount : null);
1976
+ case 43:
1977
+ outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (currentStep.outputAmount ? currentStep.outputAmount : null);
2202
1978
  prevOutputAmount = currentStep.outputAmount || null;
2203
1979
  swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
2204
1980
  swap.extraMessageSeverity = exports.MessageSeverity.info;
@@ -2209,32 +1985,11 @@ function _checkTransactionStatus() {
2209
1985
  currentStep.explorerUrl = ((_status5 = status) == null ? void 0 : _status5.explorerUrl) || currentStep.explorerUrl;
2210
1986
  currentStep.internalSteps = ((_status6 = status) == null ? void 0 : _status6.steps) || null;
2211
1987
  newTransaction = (_status7 = status) == null ? void 0 : _status7.newTx;
2212
- if (!!newTransaction) {
1988
+ if (newTransaction) {
2213
1989
  currentStep.status = 'created';
2214
1990
  currentStep.executedTransactionId = null;
2215
1991
  currentStep.executedTransactionTime = null;
2216
- currentStep.transferTransaction = null;
2217
- currentStep.cosmosTransaction = null;
2218
- currentStep.evmTransaction = null;
2219
- currentStep.solanaTransaction = null;
2220
- currentStep.evmApprovalTransaction = null;
2221
- currentStep.starknetApprovalTransaction = null;
2222
- currentStep.starknetTransaction = null;
2223
- currentStep.tronApprovalTransaction = null;
2224
- currentStep.tronTransaction = null;
2225
- if (isEvmTransaction(newTransaction)) {
2226
- if (newTransaction.isApprovalTx) currentStep.evmApprovalTransaction = newTransaction;else currentStep.evmTransaction = newTransaction;
2227
- } else if (isCosmosTransaction(newTransaction)) {
2228
- currentStep.cosmosTransaction = newTransaction;
2229
- } else if (isSolanaTransaction(newTransaction)) {
2230
- currentStep.solanaTransaction = newTransaction;
2231
- } else if (isTrasnferTransaction(newTransaction)) {
2232
- currentStep.transferTransaction = newTransaction;
2233
- } else if (isStarknetTransaction(newTransaction)) {
2234
- if (newTransaction.isApprovalTx) currentStep.starknetApprovalTransaction = newTransaction;else currentStep.starknetTransaction = newTransaction;
2235
- } else if (isTronTransaction(newTransaction)) {
2236
- if (newTransaction.isApprovalTx) currentStep.tronApprovalTransaction = newTransaction;else currentStep.tronTransaction = newTransaction;
2237
- }
1992
+ setCurrentStepTx(currentStep, newTransaction);
2238
1993
  }
2239
1994
  if (prevOutputAmount === null && outputAmount !== null) context.notifier({
2240
1995
  eventType: 'step_completed_with_output',
@@ -2251,7 +2006,7 @@ function _checkTransactionStatus() {
2251
2006
  if (currentStep.status === 'success') {
2252
2007
  nextStep = getNextStep(swap, currentStep);
2253
2008
  swap.extraMessageDetail = '';
2254
- swap.extraMessage = !!nextStep ? "starting next step: " + nextStep.swapperId + ": " + nextStep.fromBlockchain + " -> " + nextStep.toBlockchain : '';
2009
+ swap.extraMessage = nextStep ? "starting next step: " + nextStep.swapperId + ": " + nextStep.fromBlockchain + " -> " + nextStep.toBlockchain : '';
2255
2010
  } else if (currentStep.status === 'failed') {
2256
2011
  swap.extraMessage = 'Transaction failed in blockchain';
2257
2012
  swap.extraMessageSeverity = exports.MessageSeverity.error;
@@ -2264,31 +2019,31 @@ function _checkTransactionStatus() {
2264
2019
  swapDetails: swap
2265
2020
  }));
2266
2021
  if (!(((_status9 = status) == null ? void 0 : _status9.status) === 'failed')) {
2267
- _context.next = 38;
2022
+ _context.next = 62;
2268
2023
  break;
2269
2024
  }
2270
2025
  failed();
2271
- _context.next = 46;
2026
+ _context.next = 70;
2272
2027
  break;
2273
- case 38:
2028
+ case 62:
2274
2029
  if (!(((_status10 = status) == null ? void 0 : _status10.status) === 'success' || ((_status11 = status) == null ? void 0 : _status11.status) === 'running' && !!status.newTx)) {
2275
- _context.next = 43;
2030
+ _context.next = 67;
2276
2031
  break;
2277
2032
  }
2278
2033
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2279
2034
  next();
2280
- _context.next = 46;
2035
+ _context.next = 70;
2281
2036
  break;
2282
- case 43:
2283
- _context.next = 45;
2037
+ case 67:
2038
+ _context.next = 69;
2284
2039
  return delay(INTERVAL_FOR_CHECK);
2285
- case 45:
2040
+ case 69:
2286
2041
  retry();
2287
- case 46:
2042
+ case 70:
2288
2043
  case "end":
2289
2044
  return _context.stop();
2290
2045
  }
2291
- }, _callee, null, [[5, 11]]);
2046
+ }, _callee, null, [[10, 21], [27, 33]]);
2292
2047
  }));
2293
2048
  return _checkTransactionStatus.apply(this, arguments);
2294
2049
  }
@@ -2305,48 +2060,115 @@ function checkApprovalStatus(_x2) {
2305
2060
  */
2306
2061
  function _checkApprovalStatus() {
2307
2062
  _checkApprovalStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
2308
- var getStorage, setStorage, next, schedule, retry, failed, context, swap, currentStep, isApproved, response, message, details, updateResult;
2063
+ var getStorage, setStorage, next, schedule, retry, failed, context, swap, meta, _useTransactionsRespo2, getTransactionResponseByHash, setTransactionResponseByHash, currentStep, txId, signer, txType, sourceWallet, _signer2, txResponse, _yield$signer$wait2, updatedTxHash, updatedTxResponse, currentStepBlockchain, explorerUrl, _currentStep$explorer2, _prettifyErrorMessage2, extraMessage, extraMessageDetail, extraMessageErrorCode, updateResult, isApproved, response, message, details, _updateResult;
2309
2064
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2310
2065
  while (1) switch (_context2.prev = _context2.next) {
2311
2066
  case 0:
2312
2067
  getStorage = _ref2.getStorage, setStorage = _ref2.setStorage, next = _ref2.next, schedule = _ref2.schedule, retry = _ref2.retry, failed = _ref2.failed, context = _ref2.context;
2313
- swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2068
+ swap = getStorage().swapDetails;
2069
+ meta = context.meta;
2070
+ _useTransactionsRespo2 = useTransactionsResponse(), getTransactionResponseByHash = _useTransactionsRespo2.getTransactionResponseByHash, setTransactionResponseByHash = _useTransactionsRespo2.setTransactionResponseByHash;
2314
2071
  currentStep = getCurrentStep(swap);
2072
+ if (currentStep) {
2073
+ _context2.next = 8;
2074
+ break;
2075
+ }
2076
+ console.log('ignore check status, current step is null');
2077
+ return _context2.abrupt("return");
2078
+ case 8:
2079
+ txId = currentStep.executedTransactionId;
2080
+ signer = null;
2081
+ try {
2082
+ txType = getCurrentStepTxType(currentStep);
2083
+ sourceWallet = getRelatedWallet(swap, currentStep);
2084
+ if (txType && sourceWallet) signer = context.getSigners(sourceWallet.walletType).getSigner(txType);
2085
+ } catch (error) {
2086
+ // wallet is not connected yet
2087
+ // no need to do anything
2088
+ }
2089
+ _context2.prev = 11;
2090
+ if (!((_signer2 = signer) != null && _signer2.wait)) {
2091
+ _context2.next = 20;
2092
+ break;
2093
+ }
2094
+ txResponse = getTransactionResponseByHash(txId);
2095
+ _context2.next = 16;
2096
+ return signer.wait(txId, txResponse);
2097
+ case 16:
2098
+ _yield$signer$wait2 = _context2.sent;
2099
+ updatedTxHash = _yield$signer$wait2.hash;
2100
+ updatedTxResponse = _yield$signer$wait2.response;
2101
+ if (updatedTxHash !== txId) {
2102
+ currentStep.executedTransactionId = updatedTxHash || currentStep.executedTransactionId;
2103
+ currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
2104
+ explorerUrl = getScannerUrl(currentStep.executedTransactionId, currentStepBlockchain, meta.blockchains);
2105
+ if (explorerUrl) {
2106
+ if (currentStep.explorerUrl && ((_currentStep$explorer2 = currentStep.explorerUrl) == null ? void 0 : _currentStep$explorer2.length) >= 1) {
2107
+ currentStep.explorerUrl[currentStep.explorerUrl.length - 1] = {
2108
+ url: explorerUrl,
2109
+ description: 'Replaced Approve'
2110
+ };
2111
+ }
2112
+ }
2113
+ txId = currentStep.executedTransactionId;
2114
+ if (updatedTxHash && updatedTxResponse) setTransactionResponseByHash(updatedTxHash, updatedTxResponse);
2115
+ }
2116
+ case 20:
2117
+ _context2.next = 28;
2118
+ break;
2119
+ case 22:
2120
+ _context2.prev = 22;
2121
+ _context2.t0 = _context2["catch"](11);
2122
+ _prettifyErrorMessage2 = prettifyErrorMessage(_context2.t0), extraMessage = _prettifyErrorMessage2.extraMessage, extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail, extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
2123
+ updateResult = updateSwapStatus({
2124
+ getStorage: getStorage,
2125
+ setStorage: setStorage,
2126
+ nextStatus: 'failed',
2127
+ nextStepStatus: 'failed',
2128
+ message: extraMessage,
2129
+ details: extraMessageDetail,
2130
+ errorCode: extraMessageErrorCode
2131
+ });
2132
+ context == null ? void 0 : context.notifier(_extends({
2133
+ eventType: 'task_failed'
2134
+ }, updateResult));
2135
+ return _context2.abrupt("return", failed());
2136
+ case 28:
2315
2137
  isApproved = false;
2316
- _context2.prev = 4;
2317
- _context2.next = 7;
2138
+ _context2.prev = 29;
2139
+ _context2.next = 32;
2318
2140
  return httpService().checkApproval(swap.requestId, currentStep.executedTransactionId || '');
2319
- case 7:
2141
+ case 32:
2320
2142
  response = _context2.sent;
2321
2143
  if (!((currentStep == null ? void 0 : currentStep.status) === 'failed')) {
2322
- _context2.next = 10;
2144
+ _context2.next = 35;
2323
2145
  break;
2324
2146
  }
2325
2147
  return _context2.abrupt("return");
2326
- case 10:
2148
+ case 35:
2327
2149
  isApproved = response.isApproved;
2328
2150
  if (!isApproved && (response.txStatus === 'failed' || response.txStatus === 'success')) {
2329
2151
  if (response.txStatus === 'failed') {
2330
2152
  message = 'Approve transaction failed';
2331
- details = 'Smart contract approval failed in blockchain.';
2153
+ details = 'Smart contract approval tx failed in blockchain.';
2332
2154
  } else {
2333
2155
  message = 'Not enough approval';
2334
2156
  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.";
2335
2157
  }
2336
2158
  // approve transaction failed on
2337
2159
  // we should fail the whole swap
2338
- updateResult = updateSwapStatus({
2160
+ _updateResult = updateSwapStatus({
2339
2161
  getStorage: getStorage,
2340
2162
  setStorage: setStorage,
2341
2163
  nextStatus: 'failed',
2342
2164
  nextStepStatus: 'failed',
2343
- errorCode: 'SEND_TX_FAILED',
2165
+ errorCode: 'INSUFFICIENT_APPROVE',
2344
2166
  message: message,
2345
2167
  details: details
2346
2168
  });
2347
2169
  context.notifier(_extends({
2348
- eventType: 'smart_contract_call_failed'
2349
- }, updateResult));
2170
+ eventType: 'not_enough_approval'
2171
+ }, _updateResult));
2350
2172
  failed();
2351
2173
  } else if (!isApproved) {
2352
2174
  // it is needed to set notification after reloading the page
@@ -2356,15 +2178,15 @@ function _checkApprovalStatus() {
2356
2178
  step: currentStep
2357
2179
  });
2358
2180
  }
2359
- _context2.next = 17;
2181
+ _context2.next = 42;
2360
2182
  break;
2361
- case 14:
2362
- _context2.prev = 14;
2363
- _context2.t0 = _context2["catch"](4);
2183
+ case 39:
2184
+ _context2.prev = 39;
2185
+ _context2.t1 = _context2["catch"](29);
2364
2186
  isApproved = false;
2365
- case 17:
2187
+ case 42:
2366
2188
  if (!isApproved) {
2367
- _context2.next = 33;
2189
+ _context2.next = 58;
2368
2190
  break;
2369
2191
  }
2370
2192
  currentStep.status = 'approved';
@@ -2386,18 +2208,18 @@ function _checkApprovalStatus() {
2386
2208
  });
2387
2209
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2388
2210
  next();
2389
- _context2.next = 36;
2211
+ _context2.next = 61;
2390
2212
  break;
2391
- case 33:
2392
- _context2.next = 35;
2213
+ case 58:
2214
+ _context2.next = 60;
2393
2215
  return delay(2000);
2394
- case 35:
2216
+ case 60:
2395
2217
  retry();
2396
- case 36:
2218
+ case 61:
2397
2219
  case "end":
2398
2220
  return _context2.stop();
2399
2221
  }
2400
- }, _callee2, null, [[4, 14]]);
2222
+ }, _callee2, null, [[11, 22], [29, 39]]);
2401
2223
  }));
2402
2224
  return _checkApprovalStatus.apply(this, arguments);
2403
2225
  }
@@ -2410,27 +2232,35 @@ function _checkStatus() {
2410
2232
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2411
2233
  while (1) switch (_context3.prev = _context3.next) {
2412
2234
  case 0:
2413
- swap = actions.getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2414
- currentStep = getCurrentStep(swap); // Reset network status
2235
+ swap = actions.getStorage().swapDetails;
2236
+ currentStep = getCurrentStep(swap);
2237
+ if (currentStep) {
2238
+ _context3.next = 5;
2239
+ break;
2240
+ }
2241
+ console.log('ignore check status, current step is null', swap.requestId);
2242
+ return _context3.abrupt("return");
2243
+ case 5:
2244
+ // Reset network status
2415
2245
  // Because when check status is on `loading` or `failed` status, it shows previous message that isn't related to current state.
2416
2246
  resetNetworkStatus(actions);
2417
2247
  if (!(currentStep.status === 'running')) {
2418
- _context3.next = 8;
2248
+ _context3.next = 11;
2419
2249
  break;
2420
2250
  }
2421
- _context3.next = 6;
2251
+ _context3.next = 9;
2422
2252
  return checkTransactionStatus(actions);
2423
- case 6:
2424
- _context3.next = 11;
2253
+ case 9:
2254
+ _context3.next = 14;
2425
2255
  break;
2426
- case 8:
2256
+ case 11:
2427
2257
  if (!(currentStep.status === 'waitingForApproval')) {
2428
- _context3.next = 11;
2258
+ _context3.next = 14;
2429
2259
  break;
2430
2260
  }
2431
- _context3.next = 11;
2261
+ _context3.next = 14;
2432
2262
  return checkApprovalStatus(actions);
2433
- case 11:
2263
+ case 14:
2434
2264
  case "end":
2435
2265
  return _context3.stop();
2436
2266
  }
@@ -2451,15 +2281,15 @@ function createTransaction(_x) {
2451
2281
  }
2452
2282
  function _createTransaction() {
2453
2283
  _createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
2454
- var setStorage, getStorage, next, schedule, context, swap, currentStep, evmTransaction, cosmosTransaction, transferTransaction, evmApprovalTransaction, solanaTransaction, tronTransaction, tronApprovalTransaction, starknetTransaction, starknetApprovalTransaction, request, _yield$throwOnOK, transaction, _prettifyErrorMessage, extraMessage, extraMessageDetail, updateResult;
2284
+ var setStorage, getStorage, next, schedule, context, swap, currentStep, transaction, request, _yield$throwOnOK, _transaction, _prettifyErrorMessage, extraMessage, extraMessageDetail, updateResult;
2455
2285
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2456
2286
  while (1) switch (_context.prev = _context.next) {
2457
2287
  case 0:
2458
2288
  setStorage = actions.setStorage, getStorage = actions.getStorage, next = actions.next, schedule = actions.schedule, context = actions.context;
2459
2289
  swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2460
2290
  currentStep = getCurrentStep(swap);
2461
- evmTransaction = currentStep.evmTransaction, cosmosTransaction = currentStep.cosmosTransaction, transferTransaction = currentStep.transferTransaction, evmApprovalTransaction = currentStep.evmApprovalTransaction, solanaTransaction = currentStep.solanaTransaction, tronTransaction = currentStep.tronTransaction, tronApprovalTransaction = currentStep.tronApprovalTransaction, starknetTransaction = currentStep.starknetTransaction, starknetApprovalTransaction = currentStep.starknetApprovalTransaction;
2462
- if (!(!evmTransaction && !evmApprovalTransaction && !tronTransaction && !tronApprovalTransaction && !starknetTransaction && !starknetApprovalTransaction && !cosmosTransaction && !transferTransaction && !solanaTransaction)) {
2291
+ transaction = getCurrentStepTx(currentStep);
2292
+ if (transaction) {
2463
2293
  _context.next = 25;
2464
2294
  break;
2465
2295
  }
@@ -2480,22 +2310,8 @@ function _createTransaction() {
2480
2310
  return throwOnOK(httpService().createTransaction(request));
2481
2311
  case 9:
2482
2312
  _yield$throwOnOK = _context.sent;
2483
- transaction = _yield$throwOnOK.transaction;
2484
- if (transaction) {
2485
- if (isEvmTransaction(transaction)) {
2486
- if (transaction.isApprovalTx) currentStep.evmApprovalTransaction = transaction;else currentStep.evmTransaction = transaction;
2487
- } else if (isCosmosTransaction(transaction)) {
2488
- currentStep.cosmosTransaction = transaction;
2489
- } else if (isSolanaTransaction(transaction)) {
2490
- currentStep.solanaTransaction = transaction;
2491
- } else if (isTrasnferTransaction(transaction)) {
2492
- currentStep.transferTransaction = transaction;
2493
- } else if (isStarknetTransaction(transaction)) {
2494
- if (transaction.isApprovalTx) currentStep.starknetApprovalTransaction = transaction;else currentStep.starknetTransaction = transaction;
2495
- } else if (isTronTransaction(transaction)) {
2496
- if (transaction.isApprovalTx) currentStep.tronApprovalTransaction = transaction;else currentStep.tronTransaction = transaction;
2497
- }
2498
- }
2313
+ _transaction = _yield$throwOnOK.transaction;
2314
+ if (_transaction) setCurrentStepTx(currentStep, _transaction);
2499
2315
  setStorage(_extends({}, getStorage(), {
2500
2316
  swapDetails: swap
2501
2317
  }));