@rango-dev/queue-manager-rango-preset 0.1.10-next.78 → 0.1.10-next.81

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.
@@ -2,10 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var BigNumber = require('bignumber.js');
8
- var BigNumber__default = _interopDefault(BigNumber);
9
5
  var walletsShared = require('@rango-dev/wallets-shared');
10
6
  var walletsCore = require('@rango-dev/wallets-core');
11
7
  var rangoSdk = require('rango-sdk');
@@ -453,9 +449,7 @@ function _assertThisInitialized(self) {
453
449
  return self;
454
450
  }
455
451
 
456
- var RANGO_DAPP_ID_QUERY = process.env.REACT_APP_RANGO_DAPP_ID_QUERY;
457
- var BASE_URL = process.env.REACT_APP_BASE_URL;
458
- var RANGO_COOKIE_HEADER = 'X-Rango-Id';
452
+ var RANGO_DAPP_API_KEY = process.env.REACT_API_KEY;
459
453
  var ERROR_MESSAGE_WAIT_FOR_WALLET = 'Waiting for connecting wallet';
460
454
  var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address) {
461
455
  return "Please change your " + (type || 'wallet') + " account to " + (address || 'proper address');
@@ -495,9 +489,6 @@ var TransactionName;
495
489
  TransactionName["Approval"] = "approve transaction";
496
490
  })(TransactionName || (TransactionName = {}));
497
491
  var ERROR_ASSERTION_FAILED = 'Assertion failed (Unexpected behaviour)';
498
- var ERROR_COMMUNICATING_WITH_API = function ERROR_COMMUNICATING_WITH_API(apiMethodName) {
499
- return "Unexpected response from API (" + apiMethodName + ")";
500
- };
501
492
  var ERROR_CREATE_TRANSACTION = 'Create transaction failed in Rango Server';
502
493
  var ERROR_INPUT_WALLET_NOT_FOUND = 'Input wallet not found';
503
494
  var PrettyError = /*#__PURE__*/function (_Error) {
@@ -538,6 +529,24 @@ var PrettyError = /*#__PURE__*/function (_Error) {
538
529
  };
539
530
  return PrettyError;
540
531
  }( /*#__PURE__*/_wrapNativeSuper(Error));
532
+ function isAPIErrorCode(value) {
533
+ return Object.values(APIErrorCode).includes(value);
534
+ }
535
+ function mapAppErrorCodesToAPIErrorCode(errorCode) {
536
+ var defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
537
+ try {
538
+ if (!errorCode) return defaultErrorCode;
539
+ if (isAPIErrorCode(errorCode)) return errorCode;
540
+ if (rangoTypes.isSignerErrorCode(errorCode)) {
541
+ var _t;
542
+ var t = (_t = {}, _t[rangoTypes.SignerErrorCode.REJECTED_BY_USER] = APIErrorCode.USER_REJECT, _t[rangoTypes.SignerErrorCode.SIGN_TX_ERROR] = APIErrorCode.CALL_WALLET_FAILED, _t[rangoTypes.SignerErrorCode.SEND_TX_ERROR] = APIErrorCode.SEND_TX_FAILED, _t[rangoTypes.SignerErrorCode.NOT_IMPLEMENTED] = defaultErrorCode, _t[rangoTypes.SignerErrorCode.OPERATION_UNSUPPORTED] = defaultErrorCode, _t[rangoTypes.SignerErrorCode.UNEXPECTED_BEHAVIOUR] = defaultErrorCode, _t);
543
+ return t[errorCode];
544
+ }
545
+ return defaultErrorCode;
546
+ } catch (err) {
547
+ return defaultErrorCode;
548
+ }
549
+ }
541
550
 
542
551
  var PendingSwapNetworkStatus;
543
552
  (function (PendingSwapNetworkStatus) {
@@ -584,6 +593,12 @@ var getEvmApproveUrl = function getEvmApproveUrl(tx, network, evmBasedBlockchain
584
593
  if (evmBlochain.info.transactionUrl) return evmBlochain.info.transactionUrl.replace('{txHash}', tx.toLowerCase());
585
594
  throw Error("Explorer url for " + network + " is not implemented");
586
595
  };
596
+ var getStarknetApproveUrl = function getStarknetApproveUrl(tx) {
597
+ return 'https://starkscan.co/tx/{txHash}'.replace('{txHash}', tx.toLowerCase());
598
+ };
599
+ var getTronApproveUrl = function getTronApproveUrl(tx) {
600
+ return 'https://tronscan.org/#/transaction/{txHash}'.replace('{txHash}', tx.toLowerCase());
601
+ };
587
602
  var prettifyErrorMessage = function prettifyErrorMessage(obj) {
588
603
  if (!obj) return {
589
604
  extraMessage: '',
@@ -611,21 +626,38 @@ var prettifyErrorMessage = function prettifyErrorMessage(obj) {
611
626
  extraMessageErrorCode: null
612
627
  };
613
628
  };
614
- function getCookieId() {
615
- var key = 'X-Rango-Id';
616
- var cookieId = window.localStorage.getItem(key);
617
- if (cookieId) {
618
- return cookieId;
619
- }
620
- var value = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
621
- window.localStorage.setItem(key, value);
622
- return value;
623
- }
624
629
  function getNextStep(swap, currentStep) {
625
630
  return swap.steps.find(function (step) {
626
631
  return step.status !== 'failed' && step.status !== 'success' && step.id !== currentStep.id;
627
632
  }) || null;
628
633
  }
634
+ // TODO: we have samething in `helpers`, for fixing circular dependency, we copied and should be removed eventually.
635
+ var getCurrentAddressOf = function getCurrentAddressOf(swap, step) {
636
+ var _step$evmTransaction2, _step$evmApprovalTran2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac2, _step$transferTransac3;
637
+ var result = swap.wallets[((_step$evmTransaction2 = step.evmTransaction) == null ? void 0 : _step$evmTransaction2.blockChain) || ''] || swap.wallets[((_step$evmApprovalTran2 = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran2.blockChain) || ''] || swap.wallets[((_step$cosmosTransacti2 = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti2.blockChain) || ''] || swap.wallets[((_step$solanaTransacti2 = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti2.blockChain) || ''] || ((_step$transferTransac2 = step.transferTransaction) != null && _step$transferTransac2.fromWalletAddress ? {
638
+ address: (_step$transferTransac3 = step.transferTransaction) == null ? void 0 : _step$transferTransac3.fromWalletAddress
639
+ } : null) || null;
640
+ if (result == null) throw PrettyError.WalletMissing();
641
+ return result.address;
642
+ };
643
+ // TODO: we have samething in `helpers`, for fixing circular dependency, we copied and should be removed eventually.
644
+ function getRelatedWallet(swap, currentStep) {
645
+ var walletAddress = getCurrentAddressOf(swap, currentStep);
646
+ var walletKV = Object.keys(swap.wallets).map(function (k) {
647
+ return {
648
+ k: k,
649
+ v: swap.wallets[k]
650
+ };
651
+ }).find(function (_ref) {
652
+ var v = _ref.v;
653
+ return v.address === walletAddress;
654
+ }) || null;
655
+ var blockchain = (walletKV == null ? void 0 : walletKV.k) || null;
656
+ var wallet = (walletKV == null ? void 0 : walletKV.v) || null;
657
+ var walletType = wallet == null ? void 0 : wallet.walletType;
658
+ if (walletType === walletsShared.WalletType.UNKNOWN || wallet === null) throw PrettyError.AssertionFailed("Wallet for source " + blockchain + " not passed: walletType: " + walletType);
659
+ return wallet;
660
+ }
629
661
  function getRelatedWalletOrNull(swap, currentStep) {
630
662
  try {
631
663
  return getRelatedWallet(swap, currentStep);
@@ -652,200 +684,7 @@ function logRPCError(error, swap, currentStep, walletType) {
652
684
  }
653
685
  }
654
686
 
655
- function checkSwapStatus(_x, _x2, _x3) {
656
- return _checkSwapStatus.apply(this, arguments);
657
- }
658
- function _checkSwapStatus() {
659
- _checkSwapStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestId, txId, step) {
660
- var _headers;
661
- var url, body, response, apiError, res;
662
- return _regeneratorRuntime().wrap(function _callee$(_context) {
663
- while (1) switch (_context.prev = _context.next) {
664
- case 0:
665
- url = BASE_URL + "/tx/check-status?" + RANGO_DAPP_ID_QUERY;
666
- body = {
667
- step: step,
668
- txId: txId,
669
- requestId: requestId
670
- };
671
- _context.next = 4;
672
- return fetch(url, {
673
- method: 'POST',
674
- headers: (_headers = {}, _headers[RANGO_COOKIE_HEADER] = getCookieId(), _headers['content-type'] = 'application/json;charset=UTF-8', _headers),
675
- body: JSON.stringify(body)
676
- });
677
- case 4:
678
- response = _context.sent;
679
- if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
680
- _context.next = 8;
681
- break;
682
- }
683
- apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckingTransactionStatus);
684
- throw PrettyError.BadStatusCode(apiError, response.status);
685
- case 8:
686
- _context.next = 10;
687
- return response.json();
688
- case 10:
689
- res = _context.sent;
690
- return _context.abrupt("return", _extends({}, res, {
691
- outputAmount: res.outputAmount ? new BigNumber.BigNumber(res.outputAmount) : null
692
- }));
693
- case 12:
694
- case "end":
695
- return _context.stop();
696
- }
697
- }, _callee);
698
- }));
699
- return _checkSwapStatus.apply(this, arguments);
700
- }
701
- function createTransaction(_x4) {
702
- return _createTransaction.apply(this, arguments);
703
- }
704
- function _createTransaction() {
705
- _createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(request) {
706
- var url, _headers2, response, result;
707
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
708
- while (1) switch (_context2.prev = _context2.next) {
709
- case 0:
710
- url = BASE_URL + "/tx/create?" + RANGO_DAPP_ID_QUERY;
711
- _context2.prev = 1;
712
- _context2.next = 4;
713
- return fetch(url, {
714
- method: 'POST',
715
- headers: (_headers2 = {
716
- 'content-type': 'application/json;charset=UTF-8'
717
- }, _headers2[RANGO_COOKIE_HEADER] = getCookieId(), _headers2),
718
- body: JSON.stringify(request)
719
- });
720
- case 4:
721
- response = _context2.sent;
722
- if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
723
- _context2.next = 7;
724
- break;
725
- }
726
- throw PrettyError.CreateTransaction("Error creating the transaction, status code: " + response.status);
727
- case 7:
728
- _context2.next = 9;
729
- return response.json();
730
- case 9:
731
- result = _context2.sent;
732
- if (!(!result.ok || !result.transaction)) {
733
- _context2.next = 12;
734
- break;
735
- }
736
- throw PrettyError.CreateTransaction(result.error || 'bad response from create tx endpoint');
737
- case 12:
738
- return _context2.abrupt("return", result);
739
- case 15:
740
- _context2.prev = 15;
741
- _context2.t0 = _context2["catch"](1);
742
- if (!(_context2.t0 instanceof Error)) {
743
- _context2.next = 19;
744
- break;
745
- }
746
- throw PrettyError.CreateTransaction(_context2.t0.message);
747
- case 19:
748
- throw _context2.t0;
749
- case 20:
750
- case "end":
751
- return _context2.stop();
752
- }
753
- }, _callee2, null, [[1, 15]]);
754
- }));
755
- return _createTransaction.apply(this, arguments);
756
- }
757
- function checkApproved(_x5) {
758
- return _checkApproved.apply(this, arguments);
759
- }
760
- function _checkApproved() {
761
- _checkApproved = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(requestId) {
762
- var _headers3;
763
- var url, response, apiError;
764
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
765
- while (1) switch (_context3.prev = _context3.next) {
766
- case 0:
767
- url = BASE_URL + "/tx/" + requestId + "/check-approval?" + RANGO_DAPP_ID_QUERY;
768
- _context3.next = 3;
769
- return fetch(url, {
770
- method: 'GET',
771
- headers: (_headers3 = {
772
- 'content-type': 'application/json;charset=UTF-8'
773
- }, _headers3[RANGO_COOKIE_HEADER] = getCookieId(), _headers3)
774
- });
775
- case 3:
776
- response = _context3.sent;
777
- if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
778
- _context3.next = 7;
779
- break;
780
- }
781
- apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckApproval);
782
- throw PrettyError.BadStatusCode(apiError, response.status);
783
- case 7:
784
- _context3.next = 9;
785
- return response.json();
786
- case 9:
787
- return _context3.abrupt("return", _context3.sent);
788
- case 10:
789
- case "end":
790
- return _context3.stop();
791
- }
792
- }, _callee3);
793
- }));
794
- return _checkApproved.apply(this, arguments);
795
- }
796
- function isAPIErrorCode(value) {
797
- return Object.values(APIErrorCode).includes(value);
798
- }
799
- function mapAppErrorCodesToAPIErrorCode(errorCode) {
800
- var defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
801
- try {
802
- if (!errorCode) return defaultErrorCode;
803
- if (isAPIErrorCode(errorCode)) return errorCode;
804
- if (rangoTypes.isSignerErrorCode(errorCode)) {
805
- var _t;
806
- var t = (_t = {}, _t[rangoTypes.SignerErrorCode.REJECTED_BY_USER] = APIErrorCode.USER_REJECT, _t[rangoTypes.SignerErrorCode.SIGN_TX_ERROR] = APIErrorCode.CALL_WALLET_FAILED, _t[rangoTypes.SignerErrorCode.SEND_TX_ERROR] = APIErrorCode.SEND_TX_FAILED, _t[rangoTypes.SignerErrorCode.NOT_IMPLEMENTED] = defaultErrorCode, _t[rangoTypes.SignerErrorCode.OPERATION_UNSUPPORTED] = defaultErrorCode, _t[rangoTypes.SignerErrorCode.UNEXPECTED_BEHAVIOUR] = defaultErrorCode, _t);
807
- return t[errorCode];
808
- }
809
- return defaultErrorCode;
810
- } catch (err) {
811
- return defaultErrorCode;
812
- }
813
- }
814
- function reportFailed(_x6, _x7, _x8, _x9, _x10) {
815
- return _reportFailed.apply(this, arguments);
816
- }
817
- function _reportFailed() {
818
- _reportFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(requestId, step, eventType, reason, walletType) {
819
- var _headers4;
820
- var url;
821
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
822
- while (1) switch (_context4.prev = _context4.next) {
823
- case 0:
824
- url = BASE_URL + "/tx/report-tx?" + RANGO_DAPP_ID_QUERY;
825
- _context4.next = 3;
826
- return fetch(url, {
827
- method: 'POST',
828
- headers: (_headers4 = {
829
- 'content-type': 'application/json;charset=UTF-8'
830
- }, _headers4[RANGO_COOKIE_HEADER] = getCookieId(), _headers4),
831
- body: JSON.stringify({
832
- requestId: requestId,
833
- step: step,
834
- eventType: eventType,
835
- reason: reason,
836
- tags: {
837
- wallet: walletType
838
- }
839
- })
840
- });
841
- case 3:
842
- case "end":
843
- return _context4.stop();
844
- }
845
- }, _callee4);
846
- }));
847
- return _reportFailed.apply(this, arguments);
848
- }
687
+ var httpService = /*#__PURE__*/new rangoSdk.RangoClient(RANGO_DAPP_API_KEY || '');
849
688
 
850
689
  var swapClaimedBy = null;
851
690
  /**
@@ -904,8 +743,17 @@ function updateSwapStatus(_ref) {
904
743
  var _getRelatedWalletOrNu;
905
744
  //if user cancel the swap, we should pass relevant reason to the server.
906
745
  var errorReason = details && details.includes('Warning') ? 'Swap canceled by user.' : details;
746
+ var walletType = (_getRelatedWalletOrNu = getRelatedWalletOrNull(swap, currentStep)) == null ? void 0 : _getRelatedWalletOrNu.walletType;
907
747
  swap.extraMessageSeverity = MessageSeverity.error;
908
- reportFailed(swap.requestId, (currentStep == null ? void 0 : currentStep.id) || 1, mapAppErrorCodesToAPIErrorCode(errorCode), errorReason || '', (currentStep ? (_getRelatedWalletOrNu = getRelatedWalletOrNull(swap, currentStep)) == null ? void 0 : _getRelatedWalletOrNu.walletType : null) || null).then();
748
+ httpService.reportFailure({
749
+ requestId: swap.requestId,
750
+ step: (currentStep == null ? void 0 : currentStep.id) || 1,
751
+ eventType: mapAppErrorCodesToAPIErrorCode(errorCode),
752
+ reason: errorReason || '',
753
+ data: walletType ? {
754
+ wallet: walletType
755
+ } : undefined
756
+ }).then()["catch"]();
909
757
  } else if (!!nextStepStatus && ['running'].includes(nextStepStatus)) swap.extraMessageSeverity = MessageSeverity.info;else if (!!nextStepStatus && ['success', 'approved'].includes(nextStepStatus)) swap.extraMessageSeverity = MessageSeverity.success;else if (nextStepStatus && ['waitingForApproval'].includes(nextStepStatus)) swap.extraMessageSeverity = MessageSeverity.warning;
910
758
  if (nextStepStatus === 'running' && currentStep) currentStep.startTransactionTime = new Date().getTime();
911
759
  setStorage(_extends({}, getStorage(), {
@@ -1165,7 +1013,7 @@ function _isNetworkMatchedForTransaction() {
1165
1013
  _context2.next = 24;
1166
1014
  break;
1167
1015
  }
1168
- if (![walletsShared.WalletType.META_MASK, walletsShared.WalletType.BINANCE_CHAIN, walletsShared.WalletType.XDEFI, walletsShared.WalletType.WALLET_CONNECT, walletsShared.WalletType.TRUST_WALLET, walletsShared.WalletType.COIN98, walletsShared.WalletType.EXODUS, walletsShared.WalletType.OKX, walletsShared.WalletType.COINBASE, walletsShared.WalletType.TOKEN_POCKET, walletsShared.WalletType.MATH, walletsShared.WalletType.SAFEPAL, walletsShared.WalletType.COSMOSTATION, walletsShared.WalletType.CLOVER, walletsShared.WalletType.BRAVE].includes(sourceWallet.walletType)) {
1016
+ if (![walletsShared.WalletType.META_MASK, walletsShared.WalletType.BINANCE_CHAIN, walletsShared.WalletType.XDEFI, walletsShared.WalletType.WALLET_CONNECT, walletsShared.WalletType.TRUST_WALLET, walletsShared.WalletType.COIN98, walletsShared.WalletType.EXODUS, walletsShared.WalletType.OKX, walletsShared.WalletType.COINBASE, walletsShared.WalletType.TOKEN_POCKET, walletsShared.WalletType.MATH, walletsShared.WalletType.SAFEPAL, walletsShared.WalletType.COSMOSTATION, walletsShared.WalletType.CLOVER, walletsShared.WalletType.BRAVE, walletsShared.WalletType.FRONTIER, walletsShared.WalletType.KUCOIN].includes(sourceWallet.walletType)) {
1169
1017
  _context2.next = 23;
1170
1018
  break;
1171
1019
  }
@@ -1217,17 +1065,17 @@ function _isNetworkMatchedForTransaction() {
1217
1065
  }));
1218
1066
  return _isNetworkMatchedForTransaction.apply(this, arguments);
1219
1067
  }
1220
- var getCurrentAddressOf = function getCurrentAddressOf(swap, step) {
1221
- var _step$evmTransaction, _step$evmApprovalTran, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac, _step$transferTransac2;
1222
- var result = swap.wallets[((_step$evmTransaction = step.evmTransaction) == null ? void 0 : _step$evmTransaction.blockChain) || ''] || swap.wallets[((_step$evmApprovalTran = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran.blockChain) || ''] || swap.wallets[((_step$cosmosTransacti = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti.blockChain) || ''] || swap.wallets[((_step$solanaTransacti = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti.blockChain) || ''] || ((_step$transferTransac = step.transferTransaction) != null && _step$transferTransac.fromWalletAddress ? {
1068
+ var getCurrentAddressOf$1 = function getCurrentAddressOf(swap, step) {
1069
+ var _step$evmTransaction, _step$evmApprovalTran, _step$tronTransaction, _step$tronApprovalTra, _step$starknetTransac, _step$starknetApprova, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac, _step$transferTransac2;
1070
+ var result = swap.wallets[((_step$evmTransaction = step.evmTransaction) == null ? void 0 : _step$evmTransaction.blockChain) || ''] || swap.wallets[((_step$evmApprovalTran = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran.blockChain) || ''] || swap.wallets[((_step$tronTransaction = step.tronTransaction) == null ? void 0 : _step$tronTransaction.blockChain) || ''] || swap.wallets[((_step$tronApprovalTra = step.tronApprovalTransaction) == null ? void 0 : _step$tronApprovalTra.blockChain) || ''] || swap.wallets[((_step$starknetTransac = step.starknetTransaction) == null ? void 0 : _step$starknetTransac.blockChain) || ''] || swap.wallets[((_step$starknetApprova = step.starknetApprovalTransaction) == null ? void 0 : _step$starknetApprova.blockChain) || ''] || swap.wallets[((_step$cosmosTransacti = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti.blockChain) || ''] || swap.wallets[((_step$solanaTransacti = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti.blockChain) || ''] || ((_step$transferTransac = step.transferTransaction) != null && _step$transferTransac.fromWalletAddress ? {
1223
1071
  address: (_step$transferTransac2 = step.transferTransaction) == null ? void 0 : _step$transferTransac2.fromWalletAddress
1224
1072
  } : null) || null;
1225
1073
  if (result == null) throw PrettyError.WalletMissing();
1226
1074
  return result.address;
1227
1075
  };
1228
1076
  // Todo: Is it same with `getRequiredWallet`?
1229
- function getRelatedWallet(swap, currentStep) {
1230
- var walletAddress = getCurrentAddressOf(swap, currentStep);
1077
+ function getRelatedWallet$1(swap, currentStep) {
1078
+ var walletAddress = getCurrentAddressOf$1(swap, currentStep);
1231
1079
  var walletKV = Object.keys(swap.wallets).map(function (k) {
1232
1080
  return {
1233
1081
  k: k,
@@ -1244,8 +1092,8 @@ function getRelatedWallet(swap, currentStep) {
1244
1092
  return wallet;
1245
1093
  }
1246
1094
  var isTxAlreadyCreated = function isTxAlreadyCreated(swap, step) {
1247
- var _step$evmTransaction2, _step$evmApprovalTran2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac3;
1248
- var result = swap.wallets[((_step$evmTransaction2 = step.evmTransaction) == null ? void 0 : _step$evmTransaction2.blockChain) || ''] || swap.wallets[((_step$evmApprovalTran2 = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran2.blockChain) || ''] || swap.wallets[((_step$cosmosTransacti2 = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti2.blockChain) || ''] || swap.wallets[((_step$solanaTransacti2 = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti2.blockChain) || ''] || ((_step$transferTransac3 = step.transferTransaction) == null ? void 0 : _step$transferTransac3.fromWalletAddress) || null;
1095
+ var _step$evmTransaction2, _step$evmApprovalTran2, _step$tronTransaction2, _step$tronApprovalTra2, _step$starknetTransac2, _step$starknetApprova2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac3;
1096
+ var result = swap.wallets[((_step$evmTransaction2 = step.evmTransaction) == null ? void 0 : _step$evmTransaction2.blockChain) || ''] || swap.wallets[((_step$evmApprovalTran2 = step.evmApprovalTransaction) == null ? void 0 : _step$evmApprovalTran2.blockChain) || ''] || swap.wallets[((_step$tronTransaction2 = step.tronTransaction) == null ? void 0 : _step$tronTransaction2.blockChain) || ''] || swap.wallets[((_step$tronApprovalTra2 = step.tronApprovalTransaction) == null ? void 0 : _step$tronApprovalTra2.blockChain) || ''] || swap.wallets[((_step$starknetTransac2 = step.starknetTransaction) == null ? void 0 : _step$starknetTransac2.blockChain) || ''] || swap.wallets[((_step$starknetApprova2 = step.starknetApprovalTransaction) == null ? void 0 : _step$starknetApprova2.blockChain) || ''] || swap.wallets[((_step$cosmosTransacti2 = step.cosmosTransaction) == null ? void 0 : _step$cosmosTransacti2.blockChain) || ''] || swap.wallets[((_step$solanaTransacti2 = step.solanaTransaction) == null ? void 0 : _step$solanaTransacti2.blockChain) || ''] || ((_step$transferTransac3 = step.transferTransaction) == null ? void 0 : _step$transferTransac3.fromWalletAddress) || null;
1249
1097
  return result !== null;
1250
1098
  };
1251
1099
  function resetNetworkStatus(actions) {
@@ -1442,9 +1290,13 @@ function singTransaction(actions) {
1442
1290
  evmApprovalTransaction = currentStep.evmApprovalTransaction,
1443
1291
  cosmosTransaction = currentStep.cosmosTransaction,
1444
1292
  solanaTransaction = currentStep.solanaTransaction,
1445
- transferTransaction = currentStep.transferTransaction;
1446
- var sourceWallet = getRelatedWallet(swap, currentStep);
1447
- var walletAddress = getCurrentAddressOf(swap, currentStep);
1293
+ transferTransaction = currentStep.transferTransaction,
1294
+ tronTransaction = currentStep.tronTransaction,
1295
+ tronApprovalTransaction = currentStep.tronApprovalTransaction,
1296
+ starknetTransaction = currentStep.starknetTransaction,
1297
+ starknetApprovalTransaction = currentStep.starknetApprovalTransaction;
1298
+ var sourceWallet = getRelatedWallet$1(swap, currentStep);
1299
+ var walletAddress = getCurrentAddressOf$1(swap, currentStep);
1448
1300
  var walletSigners = getSigners(sourceWallet.walletType);
1449
1301
  var onFinish = function onFinish() {
1450
1302
  if (actions.context.resetClaimedBy) {
@@ -1508,11 +1360,121 @@ function singTransaction(actions) {
1508
1360
  onFinish();
1509
1361
  });
1510
1362
  return;
1363
+ } else if (!!tronApprovalTransaction) {
1364
+ // Update swap status
1365
+ var _message = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
1366
+ var _updateResult = updateSwapStatus({
1367
+ getStorage: getStorage,
1368
+ setStorage: setStorage,
1369
+ nextStepStatus: 'waitingForApproval',
1370
+ message: _message,
1371
+ details: 'Waiting for approve transaction to be mined and confirmed successfully'
1372
+ });
1373
+ notifier(_extends({
1374
+ eventType: 'confirm_contract'
1375
+ }, _updateResult));
1376
+ // Execute transaction
1377
+ walletSigners.getSigner(rangoSdk.TransactionType.TRON).signAndSendTx(tronApprovalTransaction, walletAddress, null).then(function (hash) {
1378
+ console.debug('transaction of approval minted successfully', hash);
1379
+ var approveUrl = getTronApproveUrl(hash);
1380
+ currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
1381
+ url: approveUrl,
1382
+ description: "approve"
1383
+ }]);
1384
+ // `currentStep` has been mutated, let's update storage.
1385
+ setStorage(_extends({}, getStorage(), {
1386
+ swapDetails: swap
1387
+ }));
1388
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1389
+ next();
1390
+ onFinish();
1391
+ }, function (error) {
1392
+ var _error$root4, _error$root5, _error$root6;
1393
+ if (swap.status === 'failed') return;
1394
+ console.debug('error in approving', error);
1395
+ var _prettifyErrorMessage2 = prettifyErrorMessage(error),
1396
+ extraMessage = _prettifyErrorMessage2.extraMessage,
1397
+ extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail,
1398
+ extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
1399
+ 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) {
1400
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1401
+ }
1402
+ var updateResult = updateSwapStatus({
1403
+ getStorage: getStorage,
1404
+ setStorage: setStorage,
1405
+ nextStatus: 'failed',
1406
+ nextStepStatus: 'failed',
1407
+ message: extraMessage,
1408
+ details: extraMessageDetail,
1409
+ errorCode: extraMessageErrorCode
1410
+ });
1411
+ notifier(_extends({
1412
+ eventType: 'contract_rejected'
1413
+ }, updateResult));
1414
+ failed();
1415
+ onFinish();
1416
+ });
1417
+ return;
1418
+ } else if (!!starknetApprovalTransaction) {
1419
+ // Update swap status
1420
+ var _message2 = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
1421
+ var _updateResult2 = updateSwapStatus({
1422
+ getStorage: getStorage,
1423
+ setStorage: setStorage,
1424
+ nextStepStatus: 'waitingForApproval',
1425
+ message: _message2,
1426
+ details: 'Waiting for approve transaction to be mined and confirmed successfully'
1427
+ });
1428
+ notifier(_extends({
1429
+ eventType: 'confirm_contract'
1430
+ }, _updateResult2));
1431
+ // Execute transaction
1432
+ walletSigners.getSigner(rangoSdk.TransactionType.STARKNET).signAndSendTx(starknetApprovalTransaction, walletAddress, null).then(function (hash) {
1433
+ console.debug('transaction of approval minted successfully', hash);
1434
+ var approveUrl = getStarknetApproveUrl(hash);
1435
+ currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
1436
+ url: approveUrl,
1437
+ description: "approve"
1438
+ }]);
1439
+ // `currentStep` has been mutated, let's update storage.
1440
+ setStorage(_extends({}, getStorage(), {
1441
+ swapDetails: swap
1442
+ }));
1443
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1444
+ next();
1445
+ onFinish();
1446
+ }, function (error) {
1447
+ var _error$root7, _error$root8, _error$root9;
1448
+ if (swap.status === 'failed') return;
1449
+ console.debug('error in approving', error);
1450
+ var _prettifyErrorMessage3 = prettifyErrorMessage(error),
1451
+ extraMessage = _prettifyErrorMessage3.extraMessage,
1452
+ extraMessageDetail = _prettifyErrorMessage3.extraMessageDetail,
1453
+ extraMessageErrorCode = _prettifyErrorMessage3.extraMessageErrorCode;
1454
+ 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) {
1455
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1456
+ }
1457
+ var updateResult = updateSwapStatus({
1458
+ getStorage: getStorage,
1459
+ setStorage: setStorage,
1460
+ nextStatus: 'failed',
1461
+ nextStepStatus: 'failed',
1462
+ message: extraMessage,
1463
+ details: extraMessageDetail,
1464
+ errorCode: extraMessageErrorCode
1465
+ });
1466
+ notifier(_extends({
1467
+ eventType: 'contract_rejected'
1468
+ }, updateResult));
1469
+ failed();
1470
+ onFinish();
1471
+ });
1472
+ return;
1511
1473
  }
1512
1474
  var executeMessage = 'executing transaction';
1513
1475
  var executeDetails = "" + (sourceWallet.walletType === walletsShared.WalletType.WALLET_CONNECT ? 'Check your mobile phone' : '');
1514
1476
  if (!!transferTransaction) {
1515
- var _updateResult = updateSwapStatus({
1477
+ var _updateResult3 = updateSwapStatus({
1516
1478
  getStorage: getStorage,
1517
1479
  setStorage: setStorage,
1518
1480
  nextStepStatus: 'running',
@@ -1521,7 +1483,7 @@ function singTransaction(actions) {
1521
1483
  });
1522
1484
  notifier(_extends({
1523
1485
  eventType: 'confirm_transfer'
1524
- }, _updateResult));
1486
+ }, _updateResult3));
1525
1487
  walletSigners.getSigner(rangoSdk.TransactionType.TRANSFER).signAndSendTx(transferTransaction, walletAddress, null).then(function (txId) {
1526
1488
  setStepTransactionIds(actions, txId, 'transfer_confirmed', notifier);
1527
1489
  schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
@@ -1529,10 +1491,10 @@ function singTransaction(actions) {
1529
1491
  onFinish();
1530
1492
  }, function (error) {
1531
1493
  if (swap.status === 'failed') return;
1532
- var _prettifyErrorMessage2 = prettifyErrorMessage(error),
1533
- extraMessage = _prettifyErrorMessage2.extraMessage,
1534
- extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail,
1535
- extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
1494
+ var _prettifyErrorMessage4 = prettifyErrorMessage(error),
1495
+ extraMessage = _prettifyErrorMessage4.extraMessage,
1496
+ extraMessageDetail = _prettifyErrorMessage4.extraMessageDetail,
1497
+ extraMessageErrorCode = _prettifyErrorMessage4.extraMessageErrorCode;
1536
1498
  var updateResult = updateSwapStatus({
1537
1499
  getStorage: getStorage,
1538
1500
  setStorage: setStorage,
@@ -1549,7 +1511,7 @@ function singTransaction(actions) {
1549
1511
  onFinish();
1550
1512
  });
1551
1513
  } else if (!!evmTransaction) {
1552
- var _updateResult2 = updateSwapStatus({
1514
+ var _updateResult4 = updateSwapStatus({
1553
1515
  getStorage: getStorage,
1554
1516
  setStorage: setStorage,
1555
1517
  nextStepStatus: 'running',
@@ -1558,20 +1520,20 @@ function singTransaction(actions) {
1558
1520
  });
1559
1521
  notifier(_extends({
1560
1522
  eventType: 'calling_smart_contract'
1561
- }, _updateResult2));
1523
+ }, _updateResult4));
1562
1524
  walletSigners.getSigner(rangoSdk.TransactionType.EVM).signAndSendTx(evmTransaction, walletAddress, null).then(function (id) {
1563
1525
  setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1564
1526
  schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1565
1527
  next();
1566
1528
  onFinish();
1567
1529
  }, function (error) {
1568
- var _error$root4, _error$root5, _error$root6;
1530
+ var _error$root10, _error$root11, _error$root12;
1569
1531
  if (swap.status === 'failed') return;
1570
- var _prettifyErrorMessage3 = prettifyErrorMessage(error),
1571
- extraMessage = _prettifyErrorMessage3.extraMessage,
1572
- extraMessageDetail = _prettifyErrorMessage3.extraMessageDetail,
1573
- extraMessageErrorCode = _prettifyErrorMessage3.extraMessageErrorCode;
1574
- 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) {
1532
+ var _prettifyErrorMessage5 = prettifyErrorMessage(error),
1533
+ extraMessage = _prettifyErrorMessage5.extraMessage,
1534
+ extraMessageDetail = _prettifyErrorMessage5.extraMessageDetail,
1535
+ extraMessageErrorCode = _prettifyErrorMessage5.extraMessageErrorCode;
1536
+ 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) {
1575
1537
  logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1576
1538
  }
1577
1539
  var updateResult = updateSwapStatus({
@@ -1590,7 +1552,7 @@ function singTransaction(actions) {
1590
1552
  onFinish();
1591
1553
  });
1592
1554
  } else if (!!cosmosTransaction) {
1593
- var _updateResult3 = updateSwapStatus({
1555
+ var _updateResult5 = updateSwapStatus({
1594
1556
  getStorage: getStorage,
1595
1557
  setStorage: setStorage,
1596
1558
  nextStepStatus: 'running',
@@ -1599,16 +1561,16 @@ function singTransaction(actions) {
1599
1561
  });
1600
1562
  notifier(_extends({
1601
1563
  eventType: 'calling_smart_contract'
1602
- }, _updateResult3));
1564
+ }, _updateResult5));
1603
1565
  // If keplr wallet is executing contracts on terra, throw error. keplr doesn't support transfer or execute contracts. only IBC messages are supported
1604
1566
  if (((currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'TerraSwap' || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'ThorChain' && (currentStep == null ? void 0 : currentStep.fromBlockchain) === walletsShared.Network.TERRA || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'Terra Bridge' && currentStep.fromBlockchain === walletsShared.Network.TERRA) &&
1605
1567
  // here we must allow ibc on terrastatus
1606
1568
  sourceWallet.walletType === walletsShared.WalletType.KEPLR) {
1607
- var _prettifyErrorMessage4 = prettifyErrorMessage('Keplr only supports IBC Transactions on Terra. ' + 'Using Terra Bridge, TerraSwap and THORChain is not possible with Keplr. Please use TerraStation or Leap wallet'),
1608
- extraMessage = _prettifyErrorMessage4.extraMessage,
1609
- extraMessageDetail = _prettifyErrorMessage4.extraMessageDetail,
1610
- extraMessageErrorCode = _prettifyErrorMessage4.extraMessageErrorCode;
1611
- var _updateResult4 = updateSwapStatus({
1569
+ var _prettifyErrorMessage6 = prettifyErrorMessage('Keplr only supports IBC Transactions on Terra. ' + 'Using Terra Bridge, TerraSwap and THORChain is not possible with Keplr. Please use TerraStation or Leap wallet'),
1570
+ extraMessage = _prettifyErrorMessage6.extraMessage,
1571
+ extraMessageDetail = _prettifyErrorMessage6.extraMessageDetail,
1572
+ extraMessageErrorCode = _prettifyErrorMessage6.extraMessageErrorCode;
1573
+ var _updateResult6 = updateSwapStatus({
1612
1574
  getStorage: getStorage,
1613
1575
  setStorage: setStorage,
1614
1576
  nextStatus: 'failed',
@@ -1619,7 +1581,7 @@ function singTransaction(actions) {
1619
1581
  });
1620
1582
  notifier(_extends({
1621
1583
  eventType: 'smart_contract_call_failed'
1622
- }, _updateResult4));
1584
+ }, _updateResult6));
1623
1585
  failed();
1624
1586
  onFinish();
1625
1587
  return;
@@ -1633,10 +1595,10 @@ function singTransaction(actions) {
1633
1595
  onFinish();
1634
1596
  }, function (error) {
1635
1597
  if (swap.status === 'failed') return;
1636
- var _prettifyErrorMessage5 = prettifyErrorMessage(error),
1637
- extraMessage = _prettifyErrorMessage5.extraMessage,
1638
- extraMessageDetail = _prettifyErrorMessage5.extraMessageDetail,
1639
- extraMessageErrorCode = _prettifyErrorMessage5.extraMessageErrorCode;
1598
+ var _prettifyErrorMessage7 = prettifyErrorMessage(error),
1599
+ extraMessage = _prettifyErrorMessage7.extraMessage,
1600
+ extraMessageDetail = _prettifyErrorMessage7.extraMessageDetail,
1601
+ extraMessageErrorCode = _prettifyErrorMessage7.extraMessageErrorCode;
1640
1602
  var updateResult = updateSwapStatus({
1641
1603
  getStorage: getStorage,
1642
1604
  setStorage: setStorage,
@@ -1653,7 +1615,7 @@ function singTransaction(actions) {
1653
1615
  onFinish();
1654
1616
  });
1655
1617
  } else if (!!solanaTransaction) {
1656
- var _updateResult5 = updateSwapStatus({
1618
+ var _updateResult7 = updateSwapStatus({
1657
1619
  getStorage: getStorage,
1658
1620
  setStorage: setStorage,
1659
1621
  nextStepStatus: 'running',
@@ -1662,7 +1624,7 @@ function singTransaction(actions) {
1662
1624
  });
1663
1625
  notifier(_extends({
1664
1626
  eventType: 'calling_smart_contract'
1665
- }, _updateResult5));
1627
+ }, _updateResult7));
1666
1628
  var tx = solanaTransaction;
1667
1629
  walletSigners.getSigner(rangoSdk.TransactionType.SOLANA).signAndSendTx(tx, walletAddress, null).then(function (txId) {
1668
1630
  setStepTransactionIds(actions, txId, 'smart_contract_called', notifier);
@@ -1671,10 +1633,92 @@ function singTransaction(actions) {
1671
1633
  onFinish();
1672
1634
  }, function (error) {
1673
1635
  if (swap.status === 'failed') return;
1674
- var _prettifyErrorMessage6 = prettifyErrorMessage(error),
1675
- extraMessage = _prettifyErrorMessage6.extraMessage,
1676
- extraMessageDetail = _prettifyErrorMessage6.extraMessageDetail,
1677
- extraMessageErrorCode = _prettifyErrorMessage6.extraMessageErrorCode;
1636
+ var _prettifyErrorMessage8 = prettifyErrorMessage(error),
1637
+ extraMessage = _prettifyErrorMessage8.extraMessage,
1638
+ extraMessageDetail = _prettifyErrorMessage8.extraMessageDetail,
1639
+ extraMessageErrorCode = _prettifyErrorMessage8.extraMessageErrorCode;
1640
+ var updateResult = updateSwapStatus({
1641
+ getStorage: getStorage,
1642
+ setStorage: setStorage,
1643
+ nextStatus: 'failed',
1644
+ nextStepStatus: 'failed',
1645
+ message: extraMessage,
1646
+ details: extraMessageDetail,
1647
+ errorCode: extraMessageErrorCode
1648
+ });
1649
+ notifier(_extends({
1650
+ eventType: 'smart_contract_call_failed'
1651
+ }, updateResult));
1652
+ failed();
1653
+ onFinish();
1654
+ });
1655
+ } else if (!!tronTransaction) {
1656
+ var _updateResult8 = updateSwapStatus({
1657
+ getStorage: getStorage,
1658
+ setStorage: setStorage,
1659
+ nextStepStatus: 'running',
1660
+ message: executeMessage,
1661
+ details: executeDetails
1662
+ });
1663
+ notifier(_extends({
1664
+ eventType: 'calling_smart_contract'
1665
+ }, _updateResult8));
1666
+ walletSigners.getSigner(rangoSdk.TransactionType.TRON).signAndSendTx(tronTransaction, walletAddress, null).then(function (id) {
1667
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1668
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1669
+ next();
1670
+ onFinish();
1671
+ }, function (error) {
1672
+ var _error$root13, _error$root14, _error$root15;
1673
+ if (swap.status === 'failed') return;
1674
+ var _prettifyErrorMessage9 = prettifyErrorMessage(error),
1675
+ extraMessage = _prettifyErrorMessage9.extraMessage,
1676
+ extraMessageDetail = _prettifyErrorMessage9.extraMessageDetail,
1677
+ extraMessageErrorCode = _prettifyErrorMessage9.extraMessageErrorCode;
1678
+ 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) {
1679
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1680
+ }
1681
+ var updateResult = updateSwapStatus({
1682
+ getStorage: getStorage,
1683
+ setStorage: setStorage,
1684
+ nextStatus: 'failed',
1685
+ nextStepStatus: 'failed',
1686
+ message: extraMessage,
1687
+ details: extraMessageDetail,
1688
+ errorCode: extraMessageErrorCode
1689
+ });
1690
+ notifier(_extends({
1691
+ eventType: 'smart_contract_call_failed'
1692
+ }, updateResult));
1693
+ failed();
1694
+ onFinish();
1695
+ });
1696
+ } else if (!!starknetTransaction) {
1697
+ var _updateResult9 = updateSwapStatus({
1698
+ getStorage: getStorage,
1699
+ setStorage: setStorage,
1700
+ nextStepStatus: 'running',
1701
+ message: executeMessage,
1702
+ details: executeDetails
1703
+ });
1704
+ notifier(_extends({
1705
+ eventType: 'calling_smart_contract'
1706
+ }, _updateResult9));
1707
+ walletSigners.getSigner(rangoSdk.TransactionType.STARKNET).signAndSendTx(starknetTransaction, walletAddress, null).then(function (id) {
1708
+ setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
1709
+ schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1710
+ next();
1711
+ onFinish();
1712
+ }, function (error) {
1713
+ var _error$root16, _error$root17, _error$root18;
1714
+ if (swap.status === 'failed') return;
1715
+ var _prettifyErrorMessage10 = prettifyErrorMessage(error),
1716
+ extraMessage = _prettifyErrorMessage10.extraMessage,
1717
+ extraMessageDetail = _prettifyErrorMessage10.extraMessageDetail,
1718
+ extraMessageErrorCode = _prettifyErrorMessage10.extraMessageErrorCode;
1719
+ 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) {
1720
+ logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
1721
+ }
1678
1722
  var updateResult = updateSwapStatus({
1679
1723
  getStorage: getStorage,
1680
1724
  setStorage: setStorage,
@@ -1788,7 +1832,11 @@ function _checkTransactionStatus() {
1788
1832
  status = null;
1789
1833
  _context.prev = 5;
1790
1834
  _context.next = 8;
1791
- return checkSwapStatus(swap.requestId, txId, currentStep.id);
1835
+ return httpService.checkStatus({
1836
+ requestId: swap.requestId,
1837
+ txId: txId,
1838
+ step: currentStep.id
1839
+ });
1792
1840
  case 8:
1793
1841
  status = _context.sent;
1794
1842
  _context.next = 17;
@@ -1802,14 +1850,14 @@ function _checkTransactionStatus() {
1802
1850
  retry();
1803
1851
  return _context.abrupt("return");
1804
1852
  case 17:
1805
- outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? new BigNumber__default(currentStep.outputAmount) : null);
1853
+ outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? currentStep.outputAmount : null);
1806
1854
  prevOutputAmount = currentStep.outputAmount;
1807
1855
  swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
1808
1856
  swap.extraMessageSeverity = MessageSeverity.info;
1809
1857
  swap.extraMessageDetail = '';
1810
1858
  currentStep.status = ((_status3 = status) == null ? void 0 : _status3.status) || currentStep.status;
1811
1859
  currentStep.diagnosisUrl = ((_status4 = status) == null ? void 0 : _status4.diagnosisUrl) || currentStep.diagnosisUrl || null;
1812
- currentStep.outputAmount = (outputAmount == null ? void 0 : outputAmount.toFixed()) || currentStep.outputAmount;
1860
+ currentStep.outputAmount = outputAmount || currentStep.outputAmount;
1813
1861
  currentStep.explorerUrl = ((_status5 = status) == null ? void 0 : _status5.explorerUrl) || currentStep.explorerUrl;
1814
1862
  currentStep.internalSteps = ((_status6 = status) == null ? void 0 : _status6.steps) || null;
1815
1863
  newTransaction = (_status7 = status) == null ? void 0 : _status7.newTx;
@@ -1897,19 +1945,20 @@ function _checkApprovalStatus() {
1897
1945
  isApproved = false;
1898
1946
  _context2.prev = 4;
1899
1947
  _context2.next = 7;
1900
- return checkApproved(swap.requestId);
1948
+ return httpService.checkApproval(swap.requestId);
1901
1949
  case 7:
1902
1950
  response = _context2.sent;
1903
1951
  isApproved = response.isApproved;
1904
- _context2.next = 14;
1952
+ _context2.next = 15;
1905
1953
  break;
1906
1954
  case 11:
1907
1955
  _context2.prev = 11;
1908
1956
  _context2.t0 = _context2["catch"](4);
1909
1957
  console.error('Failed to check getApprovedAmount', _context2.t0);
1910
- case 14:
1958
+ isApproved = false;
1959
+ case 15:
1911
1960
  if (!isApproved) {
1912
- _context2.next = 27;
1961
+ _context2.next = 30;
1913
1962
  break;
1914
1963
  }
1915
1964
  currentStep.status = 'approved';
@@ -1918,6 +1967,8 @@ function _checkApprovalStatus() {
1918
1967
  swap.extraMessageSeverity = MessageSeverity.success;
1919
1968
  currentStep.evmApprovalTransaction = null;
1920
1969
  currentStep.executedTransactionId = null;
1970
+ currentStep.starknetApprovalTransaction = null;
1971
+ currentStep.tronApprovalTransaction = null;
1921
1972
  setStorage(_extends({}, getStorage(), {
1922
1973
  swapDetails: swap
1923
1974
  }));
@@ -1928,14 +1979,14 @@ function _checkApprovalStatus() {
1928
1979
  });
1929
1980
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
1930
1981
  next();
1931
- _context2.next = 30;
1982
+ _context2.next = 33;
1932
1983
  break;
1933
- case 27:
1934
- _context2.next = 29;
1984
+ case 30:
1985
+ _context2.next = 32;
1935
1986
  return delay(2000);
1936
- case 29:
1987
+ case 32:
1937
1988
  retry();
1938
- case 30:
1989
+ case 33:
1939
1990
  case "end":
1940
1991
  return _context2.stop();
1941
1992
  }
@@ -1988,20 +2039,20 @@ function _checkStatus() {
1988
2039
  * It can be failed if server goes through an error, If not, we will schedule the `EXECTUTE_TRANSACTION`.
1989
2040
  *
1990
2041
  */
1991
- function createTransaction$1(_x) {
1992
- return _createTransaction$1.apply(this, arguments);
2042
+ function createTransaction(_x) {
2043
+ return _createTransaction.apply(this, arguments);
1993
2044
  }
1994
- function _createTransaction$1() {
1995
- _createTransaction$1 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
1996
- var setStorage, getStorage, next, schedule, context, swap, currentStep, evmTransaction, cosmosTransaction, transferTransaction, evmApprovalTransaction, solanaTransaction, request, _yield$requestTransac, transaction, _prettifyErrorMessage, extraMessage, extraMessageDetail, updateResult;
2045
+ function _createTransaction() {
2046
+ _createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
2047
+ var setStorage, getStorage, next, schedule, context, swap, currentStep, evmTransaction, cosmosTransaction, transferTransaction, evmApprovalTransaction, solanaTransaction, tronTransaction, tronApprovalTransaction, starknetTransaction, starknetApprovalTransaction, request, _yield$httpService$cr, transaction, _prettifyErrorMessage, extraMessage, extraMessageDetail, updateResult;
1997
2048
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1998
2049
  while (1) switch (_context.prev = _context.next) {
1999
2050
  case 0:
2000
2051
  setStorage = actions.setStorage, getStorage = actions.getStorage, next = actions.next, schedule = actions.schedule, context = actions.context;
2001
2052
  swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2002
2053
  currentStep = getCurrentStep(swap);
2003
- evmTransaction = currentStep.evmTransaction, cosmosTransaction = currentStep.cosmosTransaction, transferTransaction = currentStep.transferTransaction, evmApprovalTransaction = currentStep.evmApprovalTransaction, solanaTransaction = currentStep.solanaTransaction;
2004
- if (!(!evmTransaction && !cosmosTransaction && !transferTransaction && !evmApprovalTransaction && !solanaTransaction)) {
2054
+ 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;
2055
+ if (!(!evmTransaction && !evmApprovalTransaction && !tronTransaction && !tronApprovalTransaction && !starknetTransaction && !starknetApprovalTransaction && !cosmosTransaction && !transferTransaction && !solanaTransaction)) {
2005
2056
  _context.next = 25;
2006
2057
  break;
2007
2058
  }
@@ -2019,10 +2070,10 @@ function _createTransaction$1() {
2019
2070
  };
2020
2071
  _context.prev = 6;
2021
2072
  _context.next = 9;
2022
- return createTransaction(request);
2073
+ return httpService.createTransaction(request);
2023
2074
  case 9:
2024
- _yield$requestTransac = _context.sent;
2025
- transaction = _yield$requestTransac.transaction;
2075
+ _yield$httpService$cr = _context.sent;
2076
+ transaction = _yield$httpService$cr.transaction;
2026
2077
  if (transaction) {
2027
2078
  if (isEvmTransaction(transaction)) {
2028
2079
  if (transaction.isApprovalTx) currentStep.evmApprovalTransaction = transaction;else currentStep.evmTransaction = transaction;
@@ -2032,6 +2083,10 @@ function _createTransaction$1() {
2032
2083
  currentStep.solanaTransaction = transaction;
2033
2084
  } else if (isTrasnferTransaction(transaction)) {
2034
2085
  currentStep.transferTransaction = transaction;
2086
+ } else if (isStarknetTransaction(transaction)) {
2087
+ if (transaction.isApprovalTx) currentStep.starknetApprovalTransaction = transaction;else currentStep.starknetTransaction = transaction;
2088
+ } else if (isTronTransaction(transaction)) {
2089
+ if (transaction.isApprovalTx) currentStep.tronApprovalTransaction = transaction;else currentStep.tronTransaction = transaction;
2035
2090
  }
2036
2091
  }
2037
2092
  setStorage(_extends({}, getStorage(), {
@@ -2066,7 +2121,7 @@ function _createTransaction$1() {
2066
2121
  }
2067
2122
  }, _callee, null, [[6, 17]]);
2068
2123
  }));
2069
- return _createTransaction$1.apply(this, arguments);
2124
+ return _createTransaction.apply(this, arguments);
2070
2125
  }
2071
2126
 
2072
2127
  /**
@@ -2235,7 +2290,7 @@ var _actions;
2235
2290
  */
2236
2291
  var swapQueueDef = {
2237
2292
  name: 'swap',
2238
- actions: (_actions = {}, _actions[SwapActionTypes.START] = start, _actions[SwapActionTypes.SCHEDULE_NEXT_STEP] = scheduleNextStep, _actions[SwapActionTypes.CREATE_TRANSACTION] = createTransaction$1, _actions[SwapActionTypes.EXECUTE_TRANSACTION] = executeTransaction, _actions[SwapActionTypes.CHECK_TRANSACTION_STATUS] = checkStatus, _actions),
2293
+ actions: (_actions = {}, _actions[SwapActionTypes.START] = start, _actions[SwapActionTypes.SCHEDULE_NEXT_STEP] = scheduleNextStep, _actions[SwapActionTypes.CREATE_TRANSACTION] = createTransaction, _actions[SwapActionTypes.EXECUTE_TRANSACTION] = executeTransaction, _actions[SwapActionTypes.CHECK_TRANSACTION_STATUS] = checkStatus, _actions),
2239
2294
  run: [SwapActionTypes.START],
2240
2295
  whenTaskBlocked: function whenTaskBlocked(event, meta) {
2241
2296
  if (event.reason.reason === BlockReason.WAIT_FOR_CONNECT_WALLET) {