@rango-dev/queue-manager-rango-preset 0.1.10-next.78 → 0.1.10-next.80
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.
- package/dist/actions/checkStatus.d.ts.map +1 -1
- package/dist/actions/createTransaction.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.development.js +335 -282
- package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -1
- package/dist/queue-manager-rango-preset.esm.js +338 -282
- package/dist/queue-manager-rango-preset.esm.js.map +1 -1
- package/dist/services/httpService.d.ts +3 -0
- package/dist/services/httpService.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/shared-errors.d.ts +1 -0
- package/dist/shared-errors.d.ts.map +1 -1
- package/dist/shared.d.ts +10 -15
- package/dist/shared.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/actions/checkStatus.ts +14 -12
- package/src/actions/createTransaction.ts +21 -3
- package/src/constants.ts +1 -3
- package/src/helpers.ts +318 -11
- package/src/index.ts +3 -0
- package/src/services/httpService.ts +4 -0
- package/src/services/index.ts +1 -0
- package/src/shared-errors.ts +28 -1
- package/src/shared.ts +58 -28
- package/dist/shared-api.d.ts +0 -10
- package/dist/shared-api.d.ts.map +0 -1
- package/src/shared-api.ts +0 -172
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getBlockChainNameFromId, WalletType, Network } from '@rango-dev/wallets-shared';
|
|
1
|
+
import { WalletType, getBlockChainNameFromId, Network } from '@rango-dev/wallets-shared';
|
|
3
2
|
import { readAccountAddress } from '@rango-dev/wallets-core';
|
|
4
|
-
import { TransactionType } from 'rango-sdk';
|
|
3
|
+
import { RangoClient, TransactionType } from 'rango-sdk';
|
|
5
4
|
import { Status } from '@rango-dev/queue-manager-core';
|
|
6
|
-
import {
|
|
5
|
+
import { isSignerErrorCode, SignerErrorCode, SignerError } from 'rango-types';
|
|
7
6
|
import { captureException } from '@sentry/browser';
|
|
8
7
|
|
|
9
8
|
var SwapActionTypes;
|
|
@@ -446,9 +445,7 @@ function _assertThisInitialized(self) {
|
|
|
446
445
|
return self;
|
|
447
446
|
}
|
|
448
447
|
|
|
449
|
-
var
|
|
450
|
-
var BASE_URL = process.env.REACT_APP_BASE_URL;
|
|
451
|
-
var RANGO_COOKIE_HEADER = 'X-Rango-Id';
|
|
448
|
+
var RANGO_DAPP_API_KEY = process.env.REACT_API_KEY;
|
|
452
449
|
var ERROR_MESSAGE_WAIT_FOR_WALLET = 'Waiting for connecting wallet';
|
|
453
450
|
var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address) {
|
|
454
451
|
return "Please change your " + (type || 'wallet') + " account to " + (address || 'proper address');
|
|
@@ -488,9 +485,6 @@ var TransactionName;
|
|
|
488
485
|
TransactionName["Approval"] = "approve transaction";
|
|
489
486
|
})(TransactionName || (TransactionName = {}));
|
|
490
487
|
var ERROR_ASSERTION_FAILED = 'Assertion failed (Unexpected behaviour)';
|
|
491
|
-
var ERROR_COMMUNICATING_WITH_API = function ERROR_COMMUNICATING_WITH_API(apiMethodName) {
|
|
492
|
-
return "Unexpected response from API (" + apiMethodName + ")";
|
|
493
|
-
};
|
|
494
488
|
var ERROR_CREATE_TRANSACTION = 'Create transaction failed in Rango Server';
|
|
495
489
|
var ERROR_INPUT_WALLET_NOT_FOUND = 'Input wallet not found';
|
|
496
490
|
var PrettyError = /*#__PURE__*/function (_Error) {
|
|
@@ -531,6 +525,24 @@ var PrettyError = /*#__PURE__*/function (_Error) {
|
|
|
531
525
|
};
|
|
532
526
|
return PrettyError;
|
|
533
527
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
528
|
+
function isAPIErrorCode(value) {
|
|
529
|
+
return Object.values(APIErrorCode).includes(value);
|
|
530
|
+
}
|
|
531
|
+
function mapAppErrorCodesToAPIErrorCode(errorCode) {
|
|
532
|
+
var defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
|
|
533
|
+
try {
|
|
534
|
+
if (!errorCode) return defaultErrorCode;
|
|
535
|
+
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
536
|
+
if (isSignerErrorCode(errorCode)) {
|
|
537
|
+
var _t;
|
|
538
|
+
var t = (_t = {}, _t[SignerErrorCode.REJECTED_BY_USER] = APIErrorCode.USER_REJECT, _t[SignerErrorCode.SIGN_TX_ERROR] = APIErrorCode.CALL_WALLET_FAILED, _t[SignerErrorCode.SEND_TX_ERROR] = APIErrorCode.SEND_TX_FAILED, _t[SignerErrorCode.NOT_IMPLEMENTED] = defaultErrorCode, _t[SignerErrorCode.OPERATION_UNSUPPORTED] = defaultErrorCode, _t[SignerErrorCode.UNEXPECTED_BEHAVIOUR] = defaultErrorCode, _t);
|
|
539
|
+
return t[errorCode];
|
|
540
|
+
}
|
|
541
|
+
return defaultErrorCode;
|
|
542
|
+
} catch (err) {
|
|
543
|
+
return defaultErrorCode;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
534
546
|
|
|
535
547
|
var PendingSwapNetworkStatus;
|
|
536
548
|
(function (PendingSwapNetworkStatus) {
|
|
@@ -577,6 +589,12 @@ var getEvmApproveUrl = function getEvmApproveUrl(tx, network, evmBasedBlockchain
|
|
|
577
589
|
if (evmBlochain.info.transactionUrl) return evmBlochain.info.transactionUrl.replace('{txHash}', tx.toLowerCase());
|
|
578
590
|
throw Error("Explorer url for " + network + " is not implemented");
|
|
579
591
|
};
|
|
592
|
+
var getStarknetApproveUrl = function getStarknetApproveUrl(tx) {
|
|
593
|
+
return 'https://starkscan.co/tx/{txHash}'.replace('{txHash}', tx.toLowerCase());
|
|
594
|
+
};
|
|
595
|
+
var getTronApproveUrl = function getTronApproveUrl(tx) {
|
|
596
|
+
return 'https://tronscan.org/#/transaction/{txHash}'.replace('{txHash}', tx.toLowerCase());
|
|
597
|
+
};
|
|
580
598
|
var prettifyErrorMessage = function prettifyErrorMessage(obj) {
|
|
581
599
|
if (!obj) return {
|
|
582
600
|
extraMessage: '',
|
|
@@ -604,21 +622,38 @@ var prettifyErrorMessage = function prettifyErrorMessage(obj) {
|
|
|
604
622
|
extraMessageErrorCode: null
|
|
605
623
|
};
|
|
606
624
|
};
|
|
607
|
-
function getCookieId() {
|
|
608
|
-
var key = 'X-Rango-Id';
|
|
609
|
-
var cookieId = window.localStorage.getItem(key);
|
|
610
|
-
if (cookieId) {
|
|
611
|
-
return cookieId;
|
|
612
|
-
}
|
|
613
|
-
var value = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
614
|
-
window.localStorage.setItem(key, value);
|
|
615
|
-
return value;
|
|
616
|
-
}
|
|
617
625
|
function getNextStep(swap, currentStep) {
|
|
618
626
|
return swap.steps.find(function (step) {
|
|
619
627
|
return step.status !== 'failed' && step.status !== 'success' && step.id !== currentStep.id;
|
|
620
628
|
}) || null;
|
|
621
629
|
}
|
|
630
|
+
// TODO: we have samething in `helpers`, for fixing circular dependency, we copied and should be removed eventually.
|
|
631
|
+
var getCurrentAddressOf = function getCurrentAddressOf(swap, step) {
|
|
632
|
+
var _step$evmTransaction2, _step$evmApprovalTran2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac2, _step$transferTransac3;
|
|
633
|
+
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 ? {
|
|
634
|
+
address: (_step$transferTransac3 = step.transferTransaction) == null ? void 0 : _step$transferTransac3.fromWalletAddress
|
|
635
|
+
} : null) || null;
|
|
636
|
+
if (result == null) throw PrettyError.WalletMissing();
|
|
637
|
+
return result.address;
|
|
638
|
+
};
|
|
639
|
+
// TODO: we have samething in `helpers`, for fixing circular dependency, we copied and should be removed eventually.
|
|
640
|
+
function getRelatedWallet(swap, currentStep) {
|
|
641
|
+
var walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
642
|
+
var walletKV = Object.keys(swap.wallets).map(function (k) {
|
|
643
|
+
return {
|
|
644
|
+
k: k,
|
|
645
|
+
v: swap.wallets[k]
|
|
646
|
+
};
|
|
647
|
+
}).find(function (_ref) {
|
|
648
|
+
var v = _ref.v;
|
|
649
|
+
return v.address === walletAddress;
|
|
650
|
+
}) || null;
|
|
651
|
+
var blockchain = (walletKV == null ? void 0 : walletKV.k) || null;
|
|
652
|
+
var wallet = (walletKV == null ? void 0 : walletKV.v) || null;
|
|
653
|
+
var walletType = wallet == null ? void 0 : wallet.walletType;
|
|
654
|
+
if (walletType === WalletType.UNKNOWN || wallet === null) throw PrettyError.AssertionFailed("Wallet for source " + blockchain + " not passed: walletType: " + walletType);
|
|
655
|
+
return wallet;
|
|
656
|
+
}
|
|
622
657
|
function getRelatedWalletOrNull(swap, currentStep) {
|
|
623
658
|
try {
|
|
624
659
|
return getRelatedWallet(swap, currentStep);
|
|
@@ -645,200 +680,7 @@ function logRPCError(error, swap, currentStep, walletType) {
|
|
|
645
680
|
}
|
|
646
681
|
}
|
|
647
682
|
|
|
648
|
-
|
|
649
|
-
return _checkSwapStatus.apply(this, arguments);
|
|
650
|
-
}
|
|
651
|
-
function _checkSwapStatus() {
|
|
652
|
-
_checkSwapStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestId, txId, step) {
|
|
653
|
-
var _headers;
|
|
654
|
-
var url, body, response, apiError, res;
|
|
655
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
656
|
-
while (1) switch (_context.prev = _context.next) {
|
|
657
|
-
case 0:
|
|
658
|
-
url = BASE_URL + "/tx/check-status?" + RANGO_DAPP_ID_QUERY;
|
|
659
|
-
body = {
|
|
660
|
-
step: step,
|
|
661
|
-
txId: txId,
|
|
662
|
-
requestId: requestId
|
|
663
|
-
};
|
|
664
|
-
_context.next = 4;
|
|
665
|
-
return fetch(url, {
|
|
666
|
-
method: 'POST',
|
|
667
|
-
headers: (_headers = {}, _headers[RANGO_COOKIE_HEADER] = getCookieId(), _headers['content-type'] = 'application/json;charset=UTF-8', _headers),
|
|
668
|
-
body: JSON.stringify(body)
|
|
669
|
-
});
|
|
670
|
-
case 4:
|
|
671
|
-
response = _context.sent;
|
|
672
|
-
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
673
|
-
_context.next = 8;
|
|
674
|
-
break;
|
|
675
|
-
}
|
|
676
|
-
apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckingTransactionStatus);
|
|
677
|
-
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
678
|
-
case 8:
|
|
679
|
-
_context.next = 10;
|
|
680
|
-
return response.json();
|
|
681
|
-
case 10:
|
|
682
|
-
res = _context.sent;
|
|
683
|
-
return _context.abrupt("return", _extends({}, res, {
|
|
684
|
-
outputAmount: res.outputAmount ? new BigNumber(res.outputAmount) : null
|
|
685
|
-
}));
|
|
686
|
-
case 12:
|
|
687
|
-
case "end":
|
|
688
|
-
return _context.stop();
|
|
689
|
-
}
|
|
690
|
-
}, _callee);
|
|
691
|
-
}));
|
|
692
|
-
return _checkSwapStatus.apply(this, arguments);
|
|
693
|
-
}
|
|
694
|
-
function createTransaction(_x4) {
|
|
695
|
-
return _createTransaction.apply(this, arguments);
|
|
696
|
-
}
|
|
697
|
-
function _createTransaction() {
|
|
698
|
-
_createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(request) {
|
|
699
|
-
var url, _headers2, response, result;
|
|
700
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
701
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
702
|
-
case 0:
|
|
703
|
-
url = BASE_URL + "/tx/create?" + RANGO_DAPP_ID_QUERY;
|
|
704
|
-
_context2.prev = 1;
|
|
705
|
-
_context2.next = 4;
|
|
706
|
-
return fetch(url, {
|
|
707
|
-
method: 'POST',
|
|
708
|
-
headers: (_headers2 = {
|
|
709
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
710
|
-
}, _headers2[RANGO_COOKIE_HEADER] = getCookieId(), _headers2),
|
|
711
|
-
body: JSON.stringify(request)
|
|
712
|
-
});
|
|
713
|
-
case 4:
|
|
714
|
-
response = _context2.sent;
|
|
715
|
-
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
716
|
-
_context2.next = 7;
|
|
717
|
-
break;
|
|
718
|
-
}
|
|
719
|
-
throw PrettyError.CreateTransaction("Error creating the transaction, status code: " + response.status);
|
|
720
|
-
case 7:
|
|
721
|
-
_context2.next = 9;
|
|
722
|
-
return response.json();
|
|
723
|
-
case 9:
|
|
724
|
-
result = _context2.sent;
|
|
725
|
-
if (!(!result.ok || !result.transaction)) {
|
|
726
|
-
_context2.next = 12;
|
|
727
|
-
break;
|
|
728
|
-
}
|
|
729
|
-
throw PrettyError.CreateTransaction(result.error || 'bad response from create tx endpoint');
|
|
730
|
-
case 12:
|
|
731
|
-
return _context2.abrupt("return", result);
|
|
732
|
-
case 15:
|
|
733
|
-
_context2.prev = 15;
|
|
734
|
-
_context2.t0 = _context2["catch"](1);
|
|
735
|
-
if (!(_context2.t0 instanceof Error)) {
|
|
736
|
-
_context2.next = 19;
|
|
737
|
-
break;
|
|
738
|
-
}
|
|
739
|
-
throw PrettyError.CreateTransaction(_context2.t0.message);
|
|
740
|
-
case 19:
|
|
741
|
-
throw _context2.t0;
|
|
742
|
-
case 20:
|
|
743
|
-
case "end":
|
|
744
|
-
return _context2.stop();
|
|
745
|
-
}
|
|
746
|
-
}, _callee2, null, [[1, 15]]);
|
|
747
|
-
}));
|
|
748
|
-
return _createTransaction.apply(this, arguments);
|
|
749
|
-
}
|
|
750
|
-
function checkApproved(_x5) {
|
|
751
|
-
return _checkApproved.apply(this, arguments);
|
|
752
|
-
}
|
|
753
|
-
function _checkApproved() {
|
|
754
|
-
_checkApproved = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(requestId) {
|
|
755
|
-
var _headers3;
|
|
756
|
-
var url, response, apiError;
|
|
757
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
758
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
759
|
-
case 0:
|
|
760
|
-
url = BASE_URL + "/tx/" + requestId + "/check-approval?" + RANGO_DAPP_ID_QUERY;
|
|
761
|
-
_context3.next = 3;
|
|
762
|
-
return fetch(url, {
|
|
763
|
-
method: 'GET',
|
|
764
|
-
headers: (_headers3 = {
|
|
765
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
766
|
-
}, _headers3[RANGO_COOKIE_HEADER] = getCookieId(), _headers3)
|
|
767
|
-
});
|
|
768
|
-
case 3:
|
|
769
|
-
response = _context3.sent;
|
|
770
|
-
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
771
|
-
_context3.next = 7;
|
|
772
|
-
break;
|
|
773
|
-
}
|
|
774
|
-
apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckApproval);
|
|
775
|
-
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
776
|
-
case 7:
|
|
777
|
-
_context3.next = 9;
|
|
778
|
-
return response.json();
|
|
779
|
-
case 9:
|
|
780
|
-
return _context3.abrupt("return", _context3.sent);
|
|
781
|
-
case 10:
|
|
782
|
-
case "end":
|
|
783
|
-
return _context3.stop();
|
|
784
|
-
}
|
|
785
|
-
}, _callee3);
|
|
786
|
-
}));
|
|
787
|
-
return _checkApproved.apply(this, arguments);
|
|
788
|
-
}
|
|
789
|
-
function isAPIErrorCode(value) {
|
|
790
|
-
return Object.values(APIErrorCode).includes(value);
|
|
791
|
-
}
|
|
792
|
-
function mapAppErrorCodesToAPIErrorCode(errorCode) {
|
|
793
|
-
var defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
|
|
794
|
-
try {
|
|
795
|
-
if (!errorCode) return defaultErrorCode;
|
|
796
|
-
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
797
|
-
if (isSignerErrorCode(errorCode)) {
|
|
798
|
-
var _t;
|
|
799
|
-
var t = (_t = {}, _t[SignerErrorCode.REJECTED_BY_USER] = APIErrorCode.USER_REJECT, _t[SignerErrorCode.SIGN_TX_ERROR] = APIErrorCode.CALL_WALLET_FAILED, _t[SignerErrorCode.SEND_TX_ERROR] = APIErrorCode.SEND_TX_FAILED, _t[SignerErrorCode.NOT_IMPLEMENTED] = defaultErrorCode, _t[SignerErrorCode.OPERATION_UNSUPPORTED] = defaultErrorCode, _t[SignerErrorCode.UNEXPECTED_BEHAVIOUR] = defaultErrorCode, _t);
|
|
800
|
-
return t[errorCode];
|
|
801
|
-
}
|
|
802
|
-
return defaultErrorCode;
|
|
803
|
-
} catch (err) {
|
|
804
|
-
return defaultErrorCode;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
function reportFailed(_x6, _x7, _x8, _x9, _x10) {
|
|
808
|
-
return _reportFailed.apply(this, arguments);
|
|
809
|
-
}
|
|
810
|
-
function _reportFailed() {
|
|
811
|
-
_reportFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(requestId, step, eventType, reason, walletType) {
|
|
812
|
-
var _headers4;
|
|
813
|
-
var url;
|
|
814
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
815
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
816
|
-
case 0:
|
|
817
|
-
url = BASE_URL + "/tx/report-tx?" + RANGO_DAPP_ID_QUERY;
|
|
818
|
-
_context4.next = 3;
|
|
819
|
-
return fetch(url, {
|
|
820
|
-
method: 'POST',
|
|
821
|
-
headers: (_headers4 = {
|
|
822
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
823
|
-
}, _headers4[RANGO_COOKIE_HEADER] = getCookieId(), _headers4),
|
|
824
|
-
body: JSON.stringify({
|
|
825
|
-
requestId: requestId,
|
|
826
|
-
step: step,
|
|
827
|
-
eventType: eventType,
|
|
828
|
-
reason: reason,
|
|
829
|
-
tags: {
|
|
830
|
-
wallet: walletType
|
|
831
|
-
}
|
|
832
|
-
})
|
|
833
|
-
});
|
|
834
|
-
case 3:
|
|
835
|
-
case "end":
|
|
836
|
-
return _context4.stop();
|
|
837
|
-
}
|
|
838
|
-
}, _callee4);
|
|
839
|
-
}));
|
|
840
|
-
return _reportFailed.apply(this, arguments);
|
|
841
|
-
}
|
|
683
|
+
var httpService = /*#__PURE__*/new RangoClient(RANGO_DAPP_API_KEY || '');
|
|
842
684
|
|
|
843
685
|
var swapClaimedBy = null;
|
|
844
686
|
/**
|
|
@@ -897,8 +739,17 @@ function updateSwapStatus(_ref) {
|
|
|
897
739
|
var _getRelatedWalletOrNu;
|
|
898
740
|
//if user cancel the swap, we should pass relevant reason to the server.
|
|
899
741
|
var errorReason = details && details.includes('Warning') ? 'Swap canceled by user.' : details;
|
|
742
|
+
var walletType = (_getRelatedWalletOrNu = getRelatedWalletOrNull(swap, currentStep)) == null ? void 0 : _getRelatedWalletOrNu.walletType;
|
|
900
743
|
swap.extraMessageSeverity = MessageSeverity.error;
|
|
901
|
-
|
|
744
|
+
httpService.reportFailure({
|
|
745
|
+
requestId: swap.requestId,
|
|
746
|
+
step: (currentStep == null ? void 0 : currentStep.id) || 1,
|
|
747
|
+
eventType: mapAppErrorCodesToAPIErrorCode(errorCode),
|
|
748
|
+
reason: errorReason || '',
|
|
749
|
+
data: walletType ? {
|
|
750
|
+
wallet: walletType
|
|
751
|
+
} : undefined
|
|
752
|
+
}).then()["catch"]();
|
|
902
753
|
} 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;
|
|
903
754
|
if (nextStepStatus === 'running' && currentStep) currentStep.startTransactionTime = new Date().getTime();
|
|
904
755
|
setStorage(_extends({}, getStorage(), {
|
|
@@ -1158,7 +1009,7 @@ function _isNetworkMatchedForTransaction() {
|
|
|
1158
1009
|
_context2.next = 24;
|
|
1159
1010
|
break;
|
|
1160
1011
|
}
|
|
1161
|
-
if (![WalletType.META_MASK, WalletType.BINANCE_CHAIN, WalletType.XDEFI, WalletType.WALLET_CONNECT, WalletType.TRUST_WALLET, WalletType.COIN98, WalletType.EXODUS, WalletType.OKX, WalletType.COINBASE, WalletType.TOKEN_POCKET, WalletType.MATH, WalletType.SAFEPAL, WalletType.COSMOSTATION, WalletType.CLOVER, WalletType.BRAVE].includes(sourceWallet.walletType)) {
|
|
1012
|
+
if (![WalletType.META_MASK, WalletType.BINANCE_CHAIN, WalletType.XDEFI, WalletType.WALLET_CONNECT, WalletType.TRUST_WALLET, WalletType.COIN98, WalletType.EXODUS, WalletType.OKX, WalletType.COINBASE, WalletType.TOKEN_POCKET, WalletType.MATH, WalletType.SAFEPAL, WalletType.COSMOSTATION, WalletType.CLOVER, WalletType.BRAVE, WalletType.FRONTIER, WalletType.KUCOIN].includes(sourceWallet.walletType)) {
|
|
1162
1013
|
_context2.next = 23;
|
|
1163
1014
|
break;
|
|
1164
1015
|
}
|
|
@@ -1210,17 +1061,17 @@ function _isNetworkMatchedForTransaction() {
|
|
|
1210
1061
|
}));
|
|
1211
1062
|
return _isNetworkMatchedForTransaction.apply(this, arguments);
|
|
1212
1063
|
}
|
|
1213
|
-
var getCurrentAddressOf = function getCurrentAddressOf(swap, step) {
|
|
1214
|
-
var _step$evmTransaction, _step$evmApprovalTran, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac, _step$transferTransac2;
|
|
1215
|
-
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 ? {
|
|
1064
|
+
var getCurrentAddressOf$1 = function getCurrentAddressOf(swap, step) {
|
|
1065
|
+
var _step$evmTransaction, _step$evmApprovalTran, _step$tronTransaction, _step$tronApprovalTra, _step$starknetTransac, _step$starknetApprova, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac, _step$transferTransac2;
|
|
1066
|
+
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 ? {
|
|
1216
1067
|
address: (_step$transferTransac2 = step.transferTransaction) == null ? void 0 : _step$transferTransac2.fromWalletAddress
|
|
1217
1068
|
} : null) || null;
|
|
1218
1069
|
if (result == null) throw PrettyError.WalletMissing();
|
|
1219
1070
|
return result.address;
|
|
1220
1071
|
};
|
|
1221
1072
|
// Todo: Is it same with `getRequiredWallet`?
|
|
1222
|
-
function getRelatedWallet(swap, currentStep) {
|
|
1223
|
-
var walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
1073
|
+
function getRelatedWallet$1(swap, currentStep) {
|
|
1074
|
+
var walletAddress = getCurrentAddressOf$1(swap, currentStep);
|
|
1224
1075
|
var walletKV = Object.keys(swap.wallets).map(function (k) {
|
|
1225
1076
|
return {
|
|
1226
1077
|
k: k,
|
|
@@ -1237,8 +1088,8 @@ function getRelatedWallet(swap, currentStep) {
|
|
|
1237
1088
|
return wallet;
|
|
1238
1089
|
}
|
|
1239
1090
|
var isTxAlreadyCreated = function isTxAlreadyCreated(swap, step) {
|
|
1240
|
-
var _step$evmTransaction2, _step$evmApprovalTran2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac3;
|
|
1241
|
-
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;
|
|
1091
|
+
var _step$evmTransaction2, _step$evmApprovalTran2, _step$tronTransaction2, _step$tronApprovalTra2, _step$starknetTransac2, _step$starknetApprova2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac3;
|
|
1092
|
+
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;
|
|
1242
1093
|
return result !== null;
|
|
1243
1094
|
};
|
|
1244
1095
|
function resetNetworkStatus(actions) {
|
|
@@ -1435,9 +1286,13 @@ function singTransaction(actions) {
|
|
|
1435
1286
|
evmApprovalTransaction = currentStep.evmApprovalTransaction,
|
|
1436
1287
|
cosmosTransaction = currentStep.cosmosTransaction,
|
|
1437
1288
|
solanaTransaction = currentStep.solanaTransaction,
|
|
1438
|
-
transferTransaction = currentStep.transferTransaction
|
|
1439
|
-
|
|
1440
|
-
|
|
1289
|
+
transferTransaction = currentStep.transferTransaction,
|
|
1290
|
+
tronTransaction = currentStep.tronTransaction,
|
|
1291
|
+
tronApprovalTransaction = currentStep.tronApprovalTransaction,
|
|
1292
|
+
starknetTransaction = currentStep.starknetTransaction,
|
|
1293
|
+
starknetApprovalTransaction = currentStep.starknetApprovalTransaction;
|
|
1294
|
+
var sourceWallet = getRelatedWallet$1(swap, currentStep);
|
|
1295
|
+
var walletAddress = getCurrentAddressOf$1(swap, currentStep);
|
|
1441
1296
|
var walletSigners = getSigners(sourceWallet.walletType);
|
|
1442
1297
|
var onFinish = function onFinish() {
|
|
1443
1298
|
if (actions.context.resetClaimedBy) {
|
|
@@ -1501,11 +1356,121 @@ function singTransaction(actions) {
|
|
|
1501
1356
|
onFinish();
|
|
1502
1357
|
});
|
|
1503
1358
|
return;
|
|
1359
|
+
} else if (!!tronApprovalTransaction) {
|
|
1360
|
+
// Update swap status
|
|
1361
|
+
var _message = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
|
|
1362
|
+
var _updateResult = updateSwapStatus({
|
|
1363
|
+
getStorage: getStorage,
|
|
1364
|
+
setStorage: setStorage,
|
|
1365
|
+
nextStepStatus: 'waitingForApproval',
|
|
1366
|
+
message: _message,
|
|
1367
|
+
details: 'Waiting for approve transaction to be mined and confirmed successfully'
|
|
1368
|
+
});
|
|
1369
|
+
notifier(_extends({
|
|
1370
|
+
eventType: 'confirm_contract'
|
|
1371
|
+
}, _updateResult));
|
|
1372
|
+
// Execute transaction
|
|
1373
|
+
walletSigners.getSigner(TransactionType.TRON).signAndSendTx(tronApprovalTransaction, walletAddress, null).then(function (hash) {
|
|
1374
|
+
console.debug('transaction of approval minted successfully', hash);
|
|
1375
|
+
var approveUrl = getTronApproveUrl(hash);
|
|
1376
|
+
currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
|
|
1377
|
+
url: approveUrl,
|
|
1378
|
+
description: "approve"
|
|
1379
|
+
}]);
|
|
1380
|
+
// `currentStep` has been mutated, let's update storage.
|
|
1381
|
+
setStorage(_extends({}, getStorage(), {
|
|
1382
|
+
swapDetails: swap
|
|
1383
|
+
}));
|
|
1384
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1385
|
+
next();
|
|
1386
|
+
onFinish();
|
|
1387
|
+
}, function (error) {
|
|
1388
|
+
var _error$root4, _error$root5, _error$root6;
|
|
1389
|
+
if (swap.status === 'failed') return;
|
|
1390
|
+
console.debug('error in approving', error);
|
|
1391
|
+
var _prettifyErrorMessage2 = prettifyErrorMessage(error),
|
|
1392
|
+
extraMessage = _prettifyErrorMessage2.extraMessage,
|
|
1393
|
+
extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail,
|
|
1394
|
+
extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
|
|
1395
|
+
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) {
|
|
1396
|
+
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1397
|
+
}
|
|
1398
|
+
var updateResult = updateSwapStatus({
|
|
1399
|
+
getStorage: getStorage,
|
|
1400
|
+
setStorage: setStorage,
|
|
1401
|
+
nextStatus: 'failed',
|
|
1402
|
+
nextStepStatus: 'failed',
|
|
1403
|
+
message: extraMessage,
|
|
1404
|
+
details: extraMessageDetail,
|
|
1405
|
+
errorCode: extraMessageErrorCode
|
|
1406
|
+
});
|
|
1407
|
+
notifier(_extends({
|
|
1408
|
+
eventType: 'contract_rejected'
|
|
1409
|
+
}, updateResult));
|
|
1410
|
+
failed();
|
|
1411
|
+
onFinish();
|
|
1412
|
+
});
|
|
1413
|
+
return;
|
|
1414
|
+
} else if (!!starknetApprovalTransaction) {
|
|
1415
|
+
// Update swap status
|
|
1416
|
+
var _message2 = "waiting for approval of " + (currentStep == null ? void 0 : currentStep.fromSymbol) + " coin " + (sourceWallet.walletType === WalletType.WALLET_CONNECT ? 'on your mobile phone' : '');
|
|
1417
|
+
var _updateResult2 = updateSwapStatus({
|
|
1418
|
+
getStorage: getStorage,
|
|
1419
|
+
setStorage: setStorage,
|
|
1420
|
+
nextStepStatus: 'waitingForApproval',
|
|
1421
|
+
message: _message2,
|
|
1422
|
+
details: 'Waiting for approve transaction to be mined and confirmed successfully'
|
|
1423
|
+
});
|
|
1424
|
+
notifier(_extends({
|
|
1425
|
+
eventType: 'confirm_contract'
|
|
1426
|
+
}, _updateResult2));
|
|
1427
|
+
// Execute transaction
|
|
1428
|
+
walletSigners.getSigner(TransactionType.STARKNET).signAndSendTx(starknetApprovalTransaction, walletAddress, null).then(function (hash) {
|
|
1429
|
+
console.debug('transaction of approval minted successfully', hash);
|
|
1430
|
+
var approveUrl = getStarknetApproveUrl(hash);
|
|
1431
|
+
currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
|
|
1432
|
+
url: approveUrl,
|
|
1433
|
+
description: "approve"
|
|
1434
|
+
}]);
|
|
1435
|
+
// `currentStep` has been mutated, let's update storage.
|
|
1436
|
+
setStorage(_extends({}, getStorage(), {
|
|
1437
|
+
swapDetails: swap
|
|
1438
|
+
}));
|
|
1439
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1440
|
+
next();
|
|
1441
|
+
onFinish();
|
|
1442
|
+
}, function (error) {
|
|
1443
|
+
var _error$root7, _error$root8, _error$root9;
|
|
1444
|
+
if (swap.status === 'failed') return;
|
|
1445
|
+
console.debug('error in approving', error);
|
|
1446
|
+
var _prettifyErrorMessage3 = prettifyErrorMessage(error),
|
|
1447
|
+
extraMessage = _prettifyErrorMessage3.extraMessage,
|
|
1448
|
+
extraMessageDetail = _prettifyErrorMessage3.extraMessageDetail,
|
|
1449
|
+
extraMessageErrorCode = _prettifyErrorMessage3.extraMessageErrorCode;
|
|
1450
|
+
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) {
|
|
1451
|
+
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1452
|
+
}
|
|
1453
|
+
var updateResult = updateSwapStatus({
|
|
1454
|
+
getStorage: getStorage,
|
|
1455
|
+
setStorage: setStorage,
|
|
1456
|
+
nextStatus: 'failed',
|
|
1457
|
+
nextStepStatus: 'failed',
|
|
1458
|
+
message: extraMessage,
|
|
1459
|
+
details: extraMessageDetail,
|
|
1460
|
+
errorCode: extraMessageErrorCode
|
|
1461
|
+
});
|
|
1462
|
+
notifier(_extends({
|
|
1463
|
+
eventType: 'contract_rejected'
|
|
1464
|
+
}, updateResult));
|
|
1465
|
+
failed();
|
|
1466
|
+
onFinish();
|
|
1467
|
+
});
|
|
1468
|
+
return;
|
|
1504
1469
|
}
|
|
1505
1470
|
var executeMessage = 'executing transaction';
|
|
1506
1471
|
var executeDetails = "" + (sourceWallet.walletType === WalletType.WALLET_CONNECT ? 'Check your mobile phone' : '');
|
|
1507
1472
|
if (!!transferTransaction) {
|
|
1508
|
-
var
|
|
1473
|
+
var _updateResult3 = updateSwapStatus({
|
|
1509
1474
|
getStorage: getStorage,
|
|
1510
1475
|
setStorage: setStorage,
|
|
1511
1476
|
nextStepStatus: 'running',
|
|
@@ -1514,7 +1479,7 @@ function singTransaction(actions) {
|
|
|
1514
1479
|
});
|
|
1515
1480
|
notifier(_extends({
|
|
1516
1481
|
eventType: 'confirm_transfer'
|
|
1517
|
-
},
|
|
1482
|
+
}, _updateResult3));
|
|
1518
1483
|
walletSigners.getSigner(TransactionType.TRANSFER).signAndSendTx(transferTransaction, walletAddress, null).then(function (txId) {
|
|
1519
1484
|
setStepTransactionIds(actions, txId, 'transfer_confirmed', notifier);
|
|
1520
1485
|
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
@@ -1522,10 +1487,10 @@ function singTransaction(actions) {
|
|
|
1522
1487
|
onFinish();
|
|
1523
1488
|
}, function (error) {
|
|
1524
1489
|
if (swap.status === 'failed') return;
|
|
1525
|
-
var
|
|
1526
|
-
extraMessage =
|
|
1527
|
-
extraMessageDetail =
|
|
1528
|
-
extraMessageErrorCode =
|
|
1490
|
+
var _prettifyErrorMessage4 = prettifyErrorMessage(error),
|
|
1491
|
+
extraMessage = _prettifyErrorMessage4.extraMessage,
|
|
1492
|
+
extraMessageDetail = _prettifyErrorMessage4.extraMessageDetail,
|
|
1493
|
+
extraMessageErrorCode = _prettifyErrorMessage4.extraMessageErrorCode;
|
|
1529
1494
|
var updateResult = updateSwapStatus({
|
|
1530
1495
|
getStorage: getStorage,
|
|
1531
1496
|
setStorage: setStorage,
|
|
@@ -1542,7 +1507,7 @@ function singTransaction(actions) {
|
|
|
1542
1507
|
onFinish();
|
|
1543
1508
|
});
|
|
1544
1509
|
} else if (!!evmTransaction) {
|
|
1545
|
-
var
|
|
1510
|
+
var _updateResult4 = updateSwapStatus({
|
|
1546
1511
|
getStorage: getStorage,
|
|
1547
1512
|
setStorage: setStorage,
|
|
1548
1513
|
nextStepStatus: 'running',
|
|
@@ -1551,20 +1516,20 @@ function singTransaction(actions) {
|
|
|
1551
1516
|
});
|
|
1552
1517
|
notifier(_extends({
|
|
1553
1518
|
eventType: 'calling_smart_contract'
|
|
1554
|
-
},
|
|
1519
|
+
}, _updateResult4));
|
|
1555
1520
|
walletSigners.getSigner(TransactionType.EVM).signAndSendTx(evmTransaction, walletAddress, null).then(function (id) {
|
|
1556
1521
|
setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
|
|
1557
1522
|
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1558
1523
|
next();
|
|
1559
1524
|
onFinish();
|
|
1560
1525
|
}, function (error) {
|
|
1561
|
-
var _error$
|
|
1526
|
+
var _error$root10, _error$root11, _error$root12;
|
|
1562
1527
|
if (swap.status === 'failed') return;
|
|
1563
|
-
var
|
|
1564
|
-
extraMessage =
|
|
1565
|
-
extraMessageDetail =
|
|
1566
|
-
extraMessageErrorCode =
|
|
1567
|
-
if (error && error != null && error.root && error != null && (_error$
|
|
1528
|
+
var _prettifyErrorMessage5 = prettifyErrorMessage(error),
|
|
1529
|
+
extraMessage = _prettifyErrorMessage5.extraMessage,
|
|
1530
|
+
extraMessageDetail = _prettifyErrorMessage5.extraMessageDetail,
|
|
1531
|
+
extraMessageErrorCode = _prettifyErrorMessage5.extraMessageErrorCode;
|
|
1532
|
+
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) {
|
|
1568
1533
|
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1569
1534
|
}
|
|
1570
1535
|
var updateResult = updateSwapStatus({
|
|
@@ -1583,7 +1548,7 @@ function singTransaction(actions) {
|
|
|
1583
1548
|
onFinish();
|
|
1584
1549
|
});
|
|
1585
1550
|
} else if (!!cosmosTransaction) {
|
|
1586
|
-
var
|
|
1551
|
+
var _updateResult5 = updateSwapStatus({
|
|
1587
1552
|
getStorage: getStorage,
|
|
1588
1553
|
setStorage: setStorage,
|
|
1589
1554
|
nextStepStatus: 'running',
|
|
@@ -1592,16 +1557,16 @@ function singTransaction(actions) {
|
|
|
1592
1557
|
});
|
|
1593
1558
|
notifier(_extends({
|
|
1594
1559
|
eventType: 'calling_smart_contract'
|
|
1595
|
-
},
|
|
1560
|
+
}, _updateResult5));
|
|
1596
1561
|
// If keplr wallet is executing contracts on terra, throw error. keplr doesn't support transfer or execute contracts. only IBC messages are supported
|
|
1597
1562
|
if (((currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'TerraSwap' || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'ThorChain' && (currentStep == null ? void 0 : currentStep.fromBlockchain) === Network.TERRA || (currentStep == null ? void 0 : currentStep.swapperId.toString()) === 'Terra Bridge' && currentStep.fromBlockchain === Network.TERRA) &&
|
|
1598
1563
|
// here we must allow ibc on terrastatus
|
|
1599
1564
|
sourceWallet.walletType === WalletType.KEPLR) {
|
|
1600
|
-
var
|
|
1601
|
-
extraMessage =
|
|
1602
|
-
extraMessageDetail =
|
|
1603
|
-
extraMessageErrorCode =
|
|
1604
|
-
var
|
|
1565
|
+
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'),
|
|
1566
|
+
extraMessage = _prettifyErrorMessage6.extraMessage,
|
|
1567
|
+
extraMessageDetail = _prettifyErrorMessage6.extraMessageDetail,
|
|
1568
|
+
extraMessageErrorCode = _prettifyErrorMessage6.extraMessageErrorCode;
|
|
1569
|
+
var _updateResult6 = updateSwapStatus({
|
|
1605
1570
|
getStorage: getStorage,
|
|
1606
1571
|
setStorage: setStorage,
|
|
1607
1572
|
nextStatus: 'failed',
|
|
@@ -1612,7 +1577,7 @@ function singTransaction(actions) {
|
|
|
1612
1577
|
});
|
|
1613
1578
|
notifier(_extends({
|
|
1614
1579
|
eventType: 'smart_contract_call_failed'
|
|
1615
|
-
},
|
|
1580
|
+
}, _updateResult6));
|
|
1616
1581
|
failed();
|
|
1617
1582
|
onFinish();
|
|
1618
1583
|
return;
|
|
@@ -1626,10 +1591,10 @@ function singTransaction(actions) {
|
|
|
1626
1591
|
onFinish();
|
|
1627
1592
|
}, function (error) {
|
|
1628
1593
|
if (swap.status === 'failed') return;
|
|
1629
|
-
var
|
|
1630
|
-
extraMessage =
|
|
1631
|
-
extraMessageDetail =
|
|
1632
|
-
extraMessageErrorCode =
|
|
1594
|
+
var _prettifyErrorMessage7 = prettifyErrorMessage(error),
|
|
1595
|
+
extraMessage = _prettifyErrorMessage7.extraMessage,
|
|
1596
|
+
extraMessageDetail = _prettifyErrorMessage7.extraMessageDetail,
|
|
1597
|
+
extraMessageErrorCode = _prettifyErrorMessage7.extraMessageErrorCode;
|
|
1633
1598
|
var updateResult = updateSwapStatus({
|
|
1634
1599
|
getStorage: getStorage,
|
|
1635
1600
|
setStorage: setStorage,
|
|
@@ -1646,7 +1611,7 @@ function singTransaction(actions) {
|
|
|
1646
1611
|
onFinish();
|
|
1647
1612
|
});
|
|
1648
1613
|
} else if (!!solanaTransaction) {
|
|
1649
|
-
var
|
|
1614
|
+
var _updateResult7 = updateSwapStatus({
|
|
1650
1615
|
getStorage: getStorage,
|
|
1651
1616
|
setStorage: setStorage,
|
|
1652
1617
|
nextStepStatus: 'running',
|
|
@@ -1655,7 +1620,7 @@ function singTransaction(actions) {
|
|
|
1655
1620
|
});
|
|
1656
1621
|
notifier(_extends({
|
|
1657
1622
|
eventType: 'calling_smart_contract'
|
|
1658
|
-
},
|
|
1623
|
+
}, _updateResult7));
|
|
1659
1624
|
var tx = solanaTransaction;
|
|
1660
1625
|
walletSigners.getSigner(TransactionType.SOLANA).signAndSendTx(tx, walletAddress, null).then(function (txId) {
|
|
1661
1626
|
setStepTransactionIds(actions, txId, 'smart_contract_called', notifier);
|
|
@@ -1664,10 +1629,92 @@ function singTransaction(actions) {
|
|
|
1664
1629
|
onFinish();
|
|
1665
1630
|
}, function (error) {
|
|
1666
1631
|
if (swap.status === 'failed') return;
|
|
1667
|
-
var
|
|
1668
|
-
extraMessage =
|
|
1669
|
-
extraMessageDetail =
|
|
1670
|
-
extraMessageErrorCode =
|
|
1632
|
+
var _prettifyErrorMessage8 = prettifyErrorMessage(error),
|
|
1633
|
+
extraMessage = _prettifyErrorMessage8.extraMessage,
|
|
1634
|
+
extraMessageDetail = _prettifyErrorMessage8.extraMessageDetail,
|
|
1635
|
+
extraMessageErrorCode = _prettifyErrorMessage8.extraMessageErrorCode;
|
|
1636
|
+
var updateResult = updateSwapStatus({
|
|
1637
|
+
getStorage: getStorage,
|
|
1638
|
+
setStorage: setStorage,
|
|
1639
|
+
nextStatus: 'failed',
|
|
1640
|
+
nextStepStatus: 'failed',
|
|
1641
|
+
message: extraMessage,
|
|
1642
|
+
details: extraMessageDetail,
|
|
1643
|
+
errorCode: extraMessageErrorCode
|
|
1644
|
+
});
|
|
1645
|
+
notifier(_extends({
|
|
1646
|
+
eventType: 'smart_contract_call_failed'
|
|
1647
|
+
}, updateResult));
|
|
1648
|
+
failed();
|
|
1649
|
+
onFinish();
|
|
1650
|
+
});
|
|
1651
|
+
} else if (!!tronTransaction) {
|
|
1652
|
+
var _updateResult8 = updateSwapStatus({
|
|
1653
|
+
getStorage: getStorage,
|
|
1654
|
+
setStorage: setStorage,
|
|
1655
|
+
nextStepStatus: 'running',
|
|
1656
|
+
message: executeMessage,
|
|
1657
|
+
details: executeDetails
|
|
1658
|
+
});
|
|
1659
|
+
notifier(_extends({
|
|
1660
|
+
eventType: 'calling_smart_contract'
|
|
1661
|
+
}, _updateResult8));
|
|
1662
|
+
walletSigners.getSigner(TransactionType.TRON).signAndSendTx(tronTransaction, walletAddress, null).then(function (id) {
|
|
1663
|
+
setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
|
|
1664
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1665
|
+
next();
|
|
1666
|
+
onFinish();
|
|
1667
|
+
}, function (error) {
|
|
1668
|
+
var _error$root13, _error$root14, _error$root15;
|
|
1669
|
+
if (swap.status === 'failed') return;
|
|
1670
|
+
var _prettifyErrorMessage9 = prettifyErrorMessage(error),
|
|
1671
|
+
extraMessage = _prettifyErrorMessage9.extraMessage,
|
|
1672
|
+
extraMessageDetail = _prettifyErrorMessage9.extraMessageDetail,
|
|
1673
|
+
extraMessageErrorCode = _prettifyErrorMessage9.extraMessageErrorCode;
|
|
1674
|
+
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) {
|
|
1675
|
+
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1676
|
+
}
|
|
1677
|
+
var updateResult = updateSwapStatus({
|
|
1678
|
+
getStorage: getStorage,
|
|
1679
|
+
setStorage: setStorage,
|
|
1680
|
+
nextStatus: 'failed',
|
|
1681
|
+
nextStepStatus: 'failed',
|
|
1682
|
+
message: extraMessage,
|
|
1683
|
+
details: extraMessageDetail,
|
|
1684
|
+
errorCode: extraMessageErrorCode
|
|
1685
|
+
});
|
|
1686
|
+
notifier(_extends({
|
|
1687
|
+
eventType: 'smart_contract_call_failed'
|
|
1688
|
+
}, updateResult));
|
|
1689
|
+
failed();
|
|
1690
|
+
onFinish();
|
|
1691
|
+
});
|
|
1692
|
+
} else if (!!starknetTransaction) {
|
|
1693
|
+
var _updateResult9 = updateSwapStatus({
|
|
1694
|
+
getStorage: getStorage,
|
|
1695
|
+
setStorage: setStorage,
|
|
1696
|
+
nextStepStatus: 'running',
|
|
1697
|
+
message: executeMessage,
|
|
1698
|
+
details: executeDetails
|
|
1699
|
+
});
|
|
1700
|
+
notifier(_extends({
|
|
1701
|
+
eventType: 'calling_smart_contract'
|
|
1702
|
+
}, _updateResult9));
|
|
1703
|
+
walletSigners.getSigner(TransactionType.STARKNET).signAndSendTx(starknetTransaction, walletAddress, null).then(function (id) {
|
|
1704
|
+
setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
|
|
1705
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1706
|
+
next();
|
|
1707
|
+
onFinish();
|
|
1708
|
+
}, function (error) {
|
|
1709
|
+
var _error$root16, _error$root17, _error$root18;
|
|
1710
|
+
if (swap.status === 'failed') return;
|
|
1711
|
+
var _prettifyErrorMessage10 = prettifyErrorMessage(error),
|
|
1712
|
+
extraMessage = _prettifyErrorMessage10.extraMessage,
|
|
1713
|
+
extraMessageDetail = _prettifyErrorMessage10.extraMessageDetail,
|
|
1714
|
+
extraMessageErrorCode = _prettifyErrorMessage10.extraMessageErrorCode;
|
|
1715
|
+
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) {
|
|
1716
|
+
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1717
|
+
}
|
|
1671
1718
|
var updateResult = updateSwapStatus({
|
|
1672
1719
|
getStorage: getStorage,
|
|
1673
1720
|
setStorage: setStorage,
|
|
@@ -1781,7 +1828,11 @@ function _checkTransactionStatus() {
|
|
|
1781
1828
|
status = null;
|
|
1782
1829
|
_context.prev = 5;
|
|
1783
1830
|
_context.next = 8;
|
|
1784
|
-
return
|
|
1831
|
+
return httpService.checkStatus({
|
|
1832
|
+
requestId: swap.requestId,
|
|
1833
|
+
txId: txId,
|
|
1834
|
+
step: currentStep.id
|
|
1835
|
+
});
|
|
1785
1836
|
case 8:
|
|
1786
1837
|
status = _context.sent;
|
|
1787
1838
|
_context.next = 17;
|
|
@@ -1795,14 +1846,14 @@ function _checkTransactionStatus() {
|
|
|
1795
1846
|
retry();
|
|
1796
1847
|
return _context.abrupt("return");
|
|
1797
1848
|
case 17:
|
|
1798
|
-
outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ?
|
|
1849
|
+
outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? currentStep.outputAmount : null);
|
|
1799
1850
|
prevOutputAmount = currentStep.outputAmount;
|
|
1800
1851
|
swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
|
|
1801
1852
|
swap.extraMessageSeverity = MessageSeverity.info;
|
|
1802
1853
|
swap.extraMessageDetail = '';
|
|
1803
1854
|
currentStep.status = ((_status3 = status) == null ? void 0 : _status3.status) || currentStep.status;
|
|
1804
1855
|
currentStep.diagnosisUrl = ((_status4 = status) == null ? void 0 : _status4.diagnosisUrl) || currentStep.diagnosisUrl || null;
|
|
1805
|
-
currentStep.outputAmount =
|
|
1856
|
+
currentStep.outputAmount = outputAmount || currentStep.outputAmount;
|
|
1806
1857
|
currentStep.explorerUrl = ((_status5 = status) == null ? void 0 : _status5.explorerUrl) || currentStep.explorerUrl;
|
|
1807
1858
|
currentStep.internalSteps = ((_status6 = status) == null ? void 0 : _status6.steps) || null;
|
|
1808
1859
|
newTransaction = (_status7 = status) == null ? void 0 : _status7.newTx;
|
|
@@ -1890,19 +1941,20 @@ function _checkApprovalStatus() {
|
|
|
1890
1941
|
isApproved = false;
|
|
1891
1942
|
_context2.prev = 4;
|
|
1892
1943
|
_context2.next = 7;
|
|
1893
|
-
return
|
|
1944
|
+
return httpService.checkApproval(swap.requestId);
|
|
1894
1945
|
case 7:
|
|
1895
1946
|
response = _context2.sent;
|
|
1896
1947
|
isApproved = response.isApproved;
|
|
1897
|
-
_context2.next =
|
|
1948
|
+
_context2.next = 15;
|
|
1898
1949
|
break;
|
|
1899
1950
|
case 11:
|
|
1900
1951
|
_context2.prev = 11;
|
|
1901
1952
|
_context2.t0 = _context2["catch"](4);
|
|
1902
1953
|
console.error('Failed to check getApprovedAmount', _context2.t0);
|
|
1903
|
-
|
|
1954
|
+
isApproved = false;
|
|
1955
|
+
case 15:
|
|
1904
1956
|
if (!isApproved) {
|
|
1905
|
-
_context2.next =
|
|
1957
|
+
_context2.next = 28;
|
|
1906
1958
|
break;
|
|
1907
1959
|
}
|
|
1908
1960
|
currentStep.status = 'approved';
|
|
@@ -1921,14 +1973,14 @@ function _checkApprovalStatus() {
|
|
|
1921
1973
|
});
|
|
1922
1974
|
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
1923
1975
|
next();
|
|
1924
|
-
_context2.next =
|
|
1976
|
+
_context2.next = 31;
|
|
1925
1977
|
break;
|
|
1926
|
-
case
|
|
1927
|
-
_context2.next =
|
|
1978
|
+
case 28:
|
|
1979
|
+
_context2.next = 30;
|
|
1928
1980
|
return delay(2000);
|
|
1929
|
-
case 29:
|
|
1930
|
-
retry();
|
|
1931
1981
|
case 30:
|
|
1982
|
+
retry();
|
|
1983
|
+
case 31:
|
|
1932
1984
|
case "end":
|
|
1933
1985
|
return _context2.stop();
|
|
1934
1986
|
}
|
|
@@ -1981,20 +2033,20 @@ function _checkStatus() {
|
|
|
1981
2033
|
* It can be failed if server goes through an error, If not, we will schedule the `EXECTUTE_TRANSACTION`.
|
|
1982
2034
|
*
|
|
1983
2035
|
*/
|
|
1984
|
-
function createTransaction
|
|
1985
|
-
return _createTransaction
|
|
2036
|
+
function createTransaction(_x) {
|
|
2037
|
+
return _createTransaction.apply(this, arguments);
|
|
1986
2038
|
}
|
|
1987
|
-
function _createTransaction
|
|
1988
|
-
_createTransaction
|
|
1989
|
-
var setStorage, getStorage, next, schedule, context, swap, currentStep, evmTransaction, cosmosTransaction, transferTransaction, evmApprovalTransaction, solanaTransaction, request, _yield$
|
|
2039
|
+
function _createTransaction() {
|
|
2040
|
+
_createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(actions) {
|
|
2041
|
+
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;
|
|
1990
2042
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1991
2043
|
while (1) switch (_context.prev = _context.next) {
|
|
1992
2044
|
case 0:
|
|
1993
2045
|
setStorage = actions.setStorage, getStorage = actions.getStorage, next = actions.next, schedule = actions.schedule, context = actions.context;
|
|
1994
2046
|
swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1995
2047
|
currentStep = getCurrentStep(swap);
|
|
1996
|
-
evmTransaction = currentStep.evmTransaction, cosmosTransaction = currentStep.cosmosTransaction, transferTransaction = currentStep.transferTransaction, evmApprovalTransaction = currentStep.evmApprovalTransaction, solanaTransaction = currentStep.solanaTransaction;
|
|
1997
|
-
if (!(!evmTransaction && !
|
|
2048
|
+
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;
|
|
2049
|
+
if (!(!evmTransaction && !evmApprovalTransaction && !tronTransaction && !tronApprovalTransaction && !starknetTransaction && !starknetApprovalTransaction && !cosmosTransaction && !transferTransaction && !solanaTransaction)) {
|
|
1998
2050
|
_context.next = 25;
|
|
1999
2051
|
break;
|
|
2000
2052
|
}
|
|
@@ -2012,10 +2064,10 @@ function _createTransaction$1() {
|
|
|
2012
2064
|
};
|
|
2013
2065
|
_context.prev = 6;
|
|
2014
2066
|
_context.next = 9;
|
|
2015
|
-
return createTransaction(request);
|
|
2067
|
+
return httpService.createTransaction(request);
|
|
2016
2068
|
case 9:
|
|
2017
|
-
_yield$
|
|
2018
|
-
transaction = _yield$
|
|
2069
|
+
_yield$httpService$cr = _context.sent;
|
|
2070
|
+
transaction = _yield$httpService$cr.transaction;
|
|
2019
2071
|
if (transaction) {
|
|
2020
2072
|
if (isEvmTransaction(transaction)) {
|
|
2021
2073
|
if (transaction.isApprovalTx) currentStep.evmApprovalTransaction = transaction;else currentStep.evmTransaction = transaction;
|
|
@@ -2025,6 +2077,10 @@ function _createTransaction$1() {
|
|
|
2025
2077
|
currentStep.solanaTransaction = transaction;
|
|
2026
2078
|
} else if (isTrasnferTransaction(transaction)) {
|
|
2027
2079
|
currentStep.transferTransaction = transaction;
|
|
2080
|
+
} else if (isStarknetTransaction(transaction)) {
|
|
2081
|
+
if (transaction.isApprovalTx) currentStep.starknetApprovalTransaction = transaction;else currentStep.starknetTransaction = transaction;
|
|
2082
|
+
} else if (isTronTransaction(transaction)) {
|
|
2083
|
+
if (transaction.isApprovalTx) currentStep.tronApprovalTransaction = transaction;else currentStep.tronTransaction = transaction;
|
|
2028
2084
|
}
|
|
2029
2085
|
}
|
|
2030
2086
|
setStorage(_extends({}, getStorage(), {
|
|
@@ -2059,7 +2115,7 @@ function _createTransaction$1() {
|
|
|
2059
2115
|
}
|
|
2060
2116
|
}, _callee, null, [[6, 17]]);
|
|
2061
2117
|
}));
|
|
2062
|
-
return _createTransaction
|
|
2118
|
+
return _createTransaction.apply(this, arguments);
|
|
2063
2119
|
}
|
|
2064
2120
|
|
|
2065
2121
|
/**
|
|
@@ -2228,7 +2284,7 @@ var _actions;
|
|
|
2228
2284
|
*/
|
|
2229
2285
|
var swapQueueDef = {
|
|
2230
2286
|
name: 'swap',
|
|
2231
|
-
actions: (_actions = {}, _actions[SwapActionTypes.START] = start, _actions[SwapActionTypes.SCHEDULE_NEXT_STEP] = scheduleNextStep, _actions[SwapActionTypes.CREATE_TRANSACTION] = createTransaction
|
|
2287
|
+
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),
|
|
2232
2288
|
run: [SwapActionTypes.START],
|
|
2233
2289
|
whenTaskBlocked: function whenTaskBlocked(event, meta) {
|
|
2234
2290
|
if (event.reason.reason === BlockReason.WAIT_FOR_CONNECT_WALLET) {
|