@rango-dev/queue-manager-rango-preset 0.1.10-next.77 → 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 +2 -2
- 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 +350 -294
- 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 +345 -286
- 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 +11 -16
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -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 +530 -192
- 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-sentry.ts +1 -1
- package/src/shared.ts +62 -35
- package/src/types.ts +2 -3
- package/dist/shared-api.d.ts +0 -10
- package/dist/shared-api.d.ts.map +0 -1
- package/src/shared-api.ts +0 -175
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { WalletError, isWalletErrorCode, WalletErrorCode, TransactionType, 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';
|
|
3
|
+
import { RangoClient, TransactionType } from 'rango-sdk';
|
|
4
4
|
import { Status } from '@rango-dev/queue-manager-core';
|
|
5
|
+
import { isSignerErrorCode, SignerErrorCode, SignerError } from 'rango-types';
|
|
5
6
|
import { captureException } from '@sentry/browser';
|
|
6
7
|
|
|
7
8
|
var SwapActionTypes;
|
|
@@ -444,9 +445,7 @@ function _assertThisInitialized(self) {
|
|
|
444
445
|
return self;
|
|
445
446
|
}
|
|
446
447
|
|
|
447
|
-
var
|
|
448
|
-
var BASE_URL = process.env.REACT_APP_BASE_URL;
|
|
449
|
-
var RANGO_COOKIE_HEADER = 'X-Rango-Id';
|
|
448
|
+
var RANGO_DAPP_API_KEY = process.env.REACT_API_KEY;
|
|
450
449
|
var ERROR_MESSAGE_WAIT_FOR_WALLET = 'Waiting for connecting wallet';
|
|
451
450
|
var ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET = function ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET(type, address) {
|
|
452
451
|
return "Please change your " + (type || 'wallet') + " account to " + (address || 'proper address');
|
|
@@ -486,9 +485,6 @@ var TransactionName;
|
|
|
486
485
|
TransactionName["Approval"] = "approve transaction";
|
|
487
486
|
})(TransactionName || (TransactionName = {}));
|
|
488
487
|
var ERROR_ASSERTION_FAILED = 'Assertion failed (Unexpected behaviour)';
|
|
489
|
-
var ERROR_COMMUNICATING_WITH_API = function ERROR_COMMUNICATING_WITH_API(apiMethodName) {
|
|
490
|
-
return "Unexpected response from API (" + apiMethodName + ")";
|
|
491
|
-
};
|
|
492
488
|
var ERROR_CREATE_TRANSACTION = 'Create transaction failed in Rango Server';
|
|
493
489
|
var ERROR_INPUT_WALLET_NOT_FOUND = 'Input wallet not found';
|
|
494
490
|
var PrettyError = /*#__PURE__*/function (_Error) {
|
|
@@ -529,6 +525,24 @@ var PrettyError = /*#__PURE__*/function (_Error) {
|
|
|
529
525
|
};
|
|
530
526
|
return PrettyError;
|
|
531
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
|
+
}
|
|
532
546
|
|
|
533
547
|
var PendingSwapNetworkStatus;
|
|
534
548
|
(function (PendingSwapNetworkStatus) {
|
|
@@ -575,13 +589,19 @@ var getEvmApproveUrl = function getEvmApproveUrl(tx, network, evmBasedBlockchain
|
|
|
575
589
|
if (evmBlochain.info.transactionUrl) return evmBlochain.info.transactionUrl.replace('{txHash}', tx.toLowerCase());
|
|
576
590
|
throw Error("Explorer url for " + network + " is not implemented");
|
|
577
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
|
+
};
|
|
578
598
|
var prettifyErrorMessage = function prettifyErrorMessage(obj) {
|
|
579
599
|
if (!obj) return {
|
|
580
600
|
extraMessage: '',
|
|
581
601
|
extraMessageErrorCode: null
|
|
582
602
|
};
|
|
583
603
|
if (obj instanceof PrettyError) return obj.getErrorDetail();
|
|
584
|
-
if (obj instanceof
|
|
604
|
+
if (obj instanceof SignerError) {
|
|
585
605
|
var t = obj.getErrorDetail();
|
|
586
606
|
return {
|
|
587
607
|
extraMessage: t.message,
|
|
@@ -602,21 +622,38 @@ var prettifyErrorMessage = function prettifyErrorMessage(obj) {
|
|
|
602
622
|
extraMessageErrorCode: null
|
|
603
623
|
};
|
|
604
624
|
};
|
|
605
|
-
function getCookieId() {
|
|
606
|
-
var key = 'X-Rango-Id';
|
|
607
|
-
var cookieId = window.localStorage.getItem(key);
|
|
608
|
-
if (cookieId) {
|
|
609
|
-
return cookieId;
|
|
610
|
-
}
|
|
611
|
-
var value = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
612
|
-
window.localStorage.setItem(key, value);
|
|
613
|
-
return value;
|
|
614
|
-
}
|
|
615
625
|
function getNextStep(swap, currentStep) {
|
|
616
626
|
return swap.steps.find(function (step) {
|
|
617
627
|
return step.status !== 'failed' && step.status !== 'success' && step.id !== currentStep.id;
|
|
618
628
|
}) || null;
|
|
619
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
|
+
}
|
|
620
657
|
function getRelatedWalletOrNull(swap, currentStep) {
|
|
621
658
|
try {
|
|
622
659
|
return getRelatedWallet(swap, currentStep);
|
|
@@ -643,200 +680,7 @@ function logRPCError(error, swap, currentStep, walletType) {
|
|
|
643
680
|
}
|
|
644
681
|
}
|
|
645
682
|
|
|
646
|
-
|
|
647
|
-
return _checkSwapStatus.apply(this, arguments);
|
|
648
|
-
}
|
|
649
|
-
function _checkSwapStatus() {
|
|
650
|
-
_checkSwapStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestId, txId, step) {
|
|
651
|
-
var _headers;
|
|
652
|
-
var url, body, response, apiError, res;
|
|
653
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
654
|
-
while (1) switch (_context.prev = _context.next) {
|
|
655
|
-
case 0:
|
|
656
|
-
url = BASE_URL + "/tx/check-status?" + RANGO_DAPP_ID_QUERY;
|
|
657
|
-
body = {
|
|
658
|
-
step: step,
|
|
659
|
-
txId: txId,
|
|
660
|
-
requestId: requestId
|
|
661
|
-
};
|
|
662
|
-
_context.next = 4;
|
|
663
|
-
return fetch(url, {
|
|
664
|
-
method: 'POST',
|
|
665
|
-
headers: (_headers = {}, _headers[RANGO_COOKIE_HEADER] = getCookieId(), _headers['content-type'] = 'application/json;charset=UTF-8', _headers),
|
|
666
|
-
body: JSON.stringify(body)
|
|
667
|
-
});
|
|
668
|
-
case 4:
|
|
669
|
-
response = _context.sent;
|
|
670
|
-
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
671
|
-
_context.next = 8;
|
|
672
|
-
break;
|
|
673
|
-
}
|
|
674
|
-
apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckingTransactionStatus);
|
|
675
|
-
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
676
|
-
case 8:
|
|
677
|
-
_context.next = 10;
|
|
678
|
-
return response.json();
|
|
679
|
-
case 10:
|
|
680
|
-
res = _context.sent;
|
|
681
|
-
return _context.abrupt("return", _extends({}, res, {
|
|
682
|
-
outputAmount: res.outputAmount ? new BigNumber(res.outputAmount) : null
|
|
683
|
-
}));
|
|
684
|
-
case 12:
|
|
685
|
-
case "end":
|
|
686
|
-
return _context.stop();
|
|
687
|
-
}
|
|
688
|
-
}, _callee);
|
|
689
|
-
}));
|
|
690
|
-
return _checkSwapStatus.apply(this, arguments);
|
|
691
|
-
}
|
|
692
|
-
function createTransaction(_x4) {
|
|
693
|
-
return _createTransaction.apply(this, arguments);
|
|
694
|
-
}
|
|
695
|
-
function _createTransaction() {
|
|
696
|
-
_createTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(request) {
|
|
697
|
-
var url, _headers2, response, result;
|
|
698
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
699
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
700
|
-
case 0:
|
|
701
|
-
url = BASE_URL + "/tx/create?" + RANGO_DAPP_ID_QUERY;
|
|
702
|
-
_context2.prev = 1;
|
|
703
|
-
_context2.next = 4;
|
|
704
|
-
return fetch(url, {
|
|
705
|
-
method: 'POST',
|
|
706
|
-
headers: (_headers2 = {
|
|
707
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
708
|
-
}, _headers2[RANGO_COOKIE_HEADER] = getCookieId(), _headers2),
|
|
709
|
-
body: JSON.stringify(request)
|
|
710
|
-
});
|
|
711
|
-
case 4:
|
|
712
|
-
response = _context2.sent;
|
|
713
|
-
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
714
|
-
_context2.next = 7;
|
|
715
|
-
break;
|
|
716
|
-
}
|
|
717
|
-
throw PrettyError.CreateTransaction("Error creating the transaction, status code: " + response.status);
|
|
718
|
-
case 7:
|
|
719
|
-
_context2.next = 9;
|
|
720
|
-
return response.json();
|
|
721
|
-
case 9:
|
|
722
|
-
result = _context2.sent;
|
|
723
|
-
if (!(!result.ok || !result.transaction)) {
|
|
724
|
-
_context2.next = 12;
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
throw PrettyError.CreateTransaction(result.error || 'bad response from create tx endpoint');
|
|
728
|
-
case 12:
|
|
729
|
-
return _context2.abrupt("return", result);
|
|
730
|
-
case 15:
|
|
731
|
-
_context2.prev = 15;
|
|
732
|
-
_context2.t0 = _context2["catch"](1);
|
|
733
|
-
if (!(_context2.t0 instanceof Error)) {
|
|
734
|
-
_context2.next = 19;
|
|
735
|
-
break;
|
|
736
|
-
}
|
|
737
|
-
throw PrettyError.CreateTransaction(_context2.t0.message);
|
|
738
|
-
case 19:
|
|
739
|
-
throw _context2.t0;
|
|
740
|
-
case 20:
|
|
741
|
-
case "end":
|
|
742
|
-
return _context2.stop();
|
|
743
|
-
}
|
|
744
|
-
}, _callee2, null, [[1, 15]]);
|
|
745
|
-
}));
|
|
746
|
-
return _createTransaction.apply(this, arguments);
|
|
747
|
-
}
|
|
748
|
-
function checkApproved(_x5) {
|
|
749
|
-
return _checkApproved.apply(this, arguments);
|
|
750
|
-
}
|
|
751
|
-
function _checkApproved() {
|
|
752
|
-
_checkApproved = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(requestId) {
|
|
753
|
-
var _headers3;
|
|
754
|
-
var url, response, apiError;
|
|
755
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
756
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
757
|
-
case 0:
|
|
758
|
-
url = BASE_URL + "/tx/" + requestId + "/check-approval?" + RANGO_DAPP_ID_QUERY;
|
|
759
|
-
_context3.next = 3;
|
|
760
|
-
return fetch(url, {
|
|
761
|
-
method: 'GET',
|
|
762
|
-
headers: (_headers3 = {
|
|
763
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
764
|
-
}, _headers3[RANGO_COOKIE_HEADER] = getCookieId(), _headers3)
|
|
765
|
-
});
|
|
766
|
-
case 3:
|
|
767
|
-
response = _context3.sent;
|
|
768
|
-
if (!(!!response.status && (response.status < 200 || response.status >= 400) || !response.ok)) {
|
|
769
|
-
_context3.next = 7;
|
|
770
|
-
break;
|
|
771
|
-
}
|
|
772
|
-
apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckApproval);
|
|
773
|
-
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
774
|
-
case 7:
|
|
775
|
-
_context3.next = 9;
|
|
776
|
-
return response.json();
|
|
777
|
-
case 9:
|
|
778
|
-
return _context3.abrupt("return", _context3.sent);
|
|
779
|
-
case 10:
|
|
780
|
-
case "end":
|
|
781
|
-
return _context3.stop();
|
|
782
|
-
}
|
|
783
|
-
}, _callee3);
|
|
784
|
-
}));
|
|
785
|
-
return _checkApproved.apply(this, arguments);
|
|
786
|
-
}
|
|
787
|
-
function isAPIErrorCode(value) {
|
|
788
|
-
return Object.values(APIErrorCode).includes(value);
|
|
789
|
-
}
|
|
790
|
-
function mapAppErrorCodesToAPIErrorCode(errorCode) {
|
|
791
|
-
var defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
|
|
792
|
-
try {
|
|
793
|
-
if (!errorCode) return defaultErrorCode;
|
|
794
|
-
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
795
|
-
if (isWalletErrorCode(errorCode)) {
|
|
796
|
-
var _t;
|
|
797
|
-
var t = (_t = {}, _t[WalletErrorCode.REJECTED_BY_USER] = APIErrorCode.USER_REJECT, _t[WalletErrorCode.SIGN_TX_ERROR] = APIErrorCode.CALL_WALLET_FAILED, _t[WalletErrorCode.SEND_TX_ERROR] = APIErrorCode.SEND_TX_FAILED, _t[WalletErrorCode.NOT_IMPLEMENTED] = defaultErrorCode, _t[WalletErrorCode.OPERATION_UNSUPPORTED] = defaultErrorCode, _t[WalletErrorCode.UNEXPECTED_BEHAVIOUR] = defaultErrorCode, _t);
|
|
798
|
-
return t[errorCode];
|
|
799
|
-
}
|
|
800
|
-
return defaultErrorCode;
|
|
801
|
-
} catch (err) {
|
|
802
|
-
return defaultErrorCode;
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
function reportFailed(_x6, _x7, _x8, _x9, _x10) {
|
|
806
|
-
return _reportFailed.apply(this, arguments);
|
|
807
|
-
}
|
|
808
|
-
function _reportFailed() {
|
|
809
|
-
_reportFailed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(requestId, step, eventType, reason, walletType) {
|
|
810
|
-
var _headers4;
|
|
811
|
-
var url;
|
|
812
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
813
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
814
|
-
case 0:
|
|
815
|
-
url = BASE_URL + "/tx/report-tx?" + RANGO_DAPP_ID_QUERY;
|
|
816
|
-
_context4.next = 3;
|
|
817
|
-
return fetch(url, {
|
|
818
|
-
method: 'POST',
|
|
819
|
-
headers: (_headers4 = {
|
|
820
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
821
|
-
}, _headers4[RANGO_COOKIE_HEADER] = getCookieId(), _headers4),
|
|
822
|
-
body: JSON.stringify({
|
|
823
|
-
requestId: requestId,
|
|
824
|
-
step: step,
|
|
825
|
-
eventType: eventType,
|
|
826
|
-
reason: reason,
|
|
827
|
-
tags: {
|
|
828
|
-
wallet: walletType
|
|
829
|
-
}
|
|
830
|
-
})
|
|
831
|
-
});
|
|
832
|
-
case 3:
|
|
833
|
-
case "end":
|
|
834
|
-
return _context4.stop();
|
|
835
|
-
}
|
|
836
|
-
}, _callee4);
|
|
837
|
-
}));
|
|
838
|
-
return _reportFailed.apply(this, arguments);
|
|
839
|
-
}
|
|
683
|
+
var httpService = /*#__PURE__*/new RangoClient(RANGO_DAPP_API_KEY || '');
|
|
840
684
|
|
|
841
685
|
var swapClaimedBy = null;
|
|
842
686
|
/**
|
|
@@ -895,8 +739,17 @@ function updateSwapStatus(_ref) {
|
|
|
895
739
|
var _getRelatedWalletOrNu;
|
|
896
740
|
//if user cancel the swap, we should pass relevant reason to the server.
|
|
897
741
|
var errorReason = details && details.includes('Warning') ? 'Swap canceled by user.' : details;
|
|
742
|
+
var walletType = (_getRelatedWalletOrNu = getRelatedWalletOrNull(swap, currentStep)) == null ? void 0 : _getRelatedWalletOrNu.walletType;
|
|
898
743
|
swap.extraMessageSeverity = MessageSeverity.error;
|
|
899
|
-
|
|
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"]();
|
|
900
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;
|
|
901
754
|
if (nextStepStatus === 'running' && currentStep) currentStep.startTransactionTime = new Date().getTime();
|
|
902
755
|
setStorage(_extends({}, getStorage(), {
|
|
@@ -1156,7 +1009,7 @@ function _isNetworkMatchedForTransaction() {
|
|
|
1156
1009
|
_context2.next = 24;
|
|
1157
1010
|
break;
|
|
1158
1011
|
}
|
|
1159
|
-
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)) {
|
|
1160
1013
|
_context2.next = 23;
|
|
1161
1014
|
break;
|
|
1162
1015
|
}
|
|
@@ -1208,17 +1061,17 @@ function _isNetworkMatchedForTransaction() {
|
|
|
1208
1061
|
}));
|
|
1209
1062
|
return _isNetworkMatchedForTransaction.apply(this, arguments);
|
|
1210
1063
|
}
|
|
1211
|
-
var getCurrentAddressOf = function getCurrentAddressOf(swap, step) {
|
|
1212
|
-
var _step$evmTransaction, _step$evmApprovalTran, _step$cosmosTransacti, _step$solanaTransacti, _step$transferTransac, _step$transferTransac2;
|
|
1213
|
-
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 ? {
|
|
1214
1067
|
address: (_step$transferTransac2 = step.transferTransaction) == null ? void 0 : _step$transferTransac2.fromWalletAddress
|
|
1215
1068
|
} : null) || null;
|
|
1216
1069
|
if (result == null) throw PrettyError.WalletMissing();
|
|
1217
1070
|
return result.address;
|
|
1218
1071
|
};
|
|
1219
1072
|
// Todo: Is it same with `getRequiredWallet`?
|
|
1220
|
-
function getRelatedWallet(swap, currentStep) {
|
|
1221
|
-
var walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
1073
|
+
function getRelatedWallet$1(swap, currentStep) {
|
|
1074
|
+
var walletAddress = getCurrentAddressOf$1(swap, currentStep);
|
|
1222
1075
|
var walletKV = Object.keys(swap.wallets).map(function (k) {
|
|
1223
1076
|
return {
|
|
1224
1077
|
k: k,
|
|
@@ -1231,12 +1084,12 @@ function getRelatedWallet(swap, currentStep) {
|
|
|
1231
1084
|
var blockchain = (walletKV == null ? void 0 : walletKV.k) || null;
|
|
1232
1085
|
var wallet = (walletKV == null ? void 0 : walletKV.v) || null;
|
|
1233
1086
|
var walletType = wallet == null ? void 0 : wallet.walletType;
|
|
1234
|
-
if (walletType === WalletType.UNKNOWN || wallet === null) throw PrettyError.AssertionFailed("Wallet for source " + blockchain + " not passed
|
|
1087
|
+
if (walletType === WalletType.UNKNOWN || wallet === null) throw PrettyError.AssertionFailed("Wallet for source " + blockchain + " not passed: walletType: " + walletType);
|
|
1235
1088
|
return wallet;
|
|
1236
1089
|
}
|
|
1237
1090
|
var isTxAlreadyCreated = function isTxAlreadyCreated(swap, step) {
|
|
1238
|
-
var _step$evmTransaction2, _step$evmApprovalTran2, _step$cosmosTransacti2, _step$solanaTransacti2, _step$transferTransac3;
|
|
1239
|
-
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;
|
|
1240
1093
|
return result !== null;
|
|
1241
1094
|
};
|
|
1242
1095
|
function resetNetworkStatus(actions) {
|
|
@@ -1433,8 +1286,13 @@ function singTransaction(actions) {
|
|
|
1433
1286
|
evmApprovalTransaction = currentStep.evmApprovalTransaction,
|
|
1434
1287
|
cosmosTransaction = currentStep.cosmosTransaction,
|
|
1435
1288
|
solanaTransaction = currentStep.solanaTransaction,
|
|
1436
|
-
transferTransaction = currentStep.transferTransaction
|
|
1437
|
-
|
|
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);
|
|
1438
1296
|
var walletSigners = getSigners(sourceWallet.walletType);
|
|
1439
1297
|
var onFinish = function onFinish() {
|
|
1440
1298
|
if (actions.context.resetClaimedBy) {
|
|
@@ -1457,7 +1315,7 @@ function singTransaction(actions) {
|
|
|
1457
1315
|
eventType: 'confirm_contract'
|
|
1458
1316
|
}, updateResult));
|
|
1459
1317
|
// Execute transaction
|
|
1460
|
-
walletSigners.
|
|
1318
|
+
walletSigners.getSigner(TransactionType.EVM).signAndSendTx(evmApprovalTransaction, walletAddress, null).then(function (hash) {
|
|
1461
1319
|
console.debug('transaction of approval minted successfully', hash);
|
|
1462
1320
|
var approveUrl = getEvmApproveUrl(hash, getCurrentBlockchainOf(swap, currentStep), meta.evmBasedChains);
|
|
1463
1321
|
currentStep.explorerUrl = [].concat(currentStep.explorerUrl || [], [{
|
|
@@ -1498,11 +1356,121 @@ function singTransaction(actions) {
|
|
|
1498
1356
|
onFinish();
|
|
1499
1357
|
});
|
|
1500
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;
|
|
1501
1469
|
}
|
|
1502
1470
|
var executeMessage = 'executing transaction';
|
|
1503
1471
|
var executeDetails = "" + (sourceWallet.walletType === WalletType.WALLET_CONNECT ? 'Check your mobile phone' : '');
|
|
1504
1472
|
if (!!transferTransaction) {
|
|
1505
|
-
var
|
|
1473
|
+
var _updateResult3 = updateSwapStatus({
|
|
1506
1474
|
getStorage: getStorage,
|
|
1507
1475
|
setStorage: setStorage,
|
|
1508
1476
|
nextStepStatus: 'running',
|
|
@@ -1511,18 +1479,18 @@ function singTransaction(actions) {
|
|
|
1511
1479
|
});
|
|
1512
1480
|
notifier(_extends({
|
|
1513
1481
|
eventType: 'confirm_transfer'
|
|
1514
|
-
},
|
|
1515
|
-
walletSigners.
|
|
1482
|
+
}, _updateResult3));
|
|
1483
|
+
walletSigners.getSigner(TransactionType.TRANSFER).signAndSendTx(transferTransaction, walletAddress, null).then(function (txId) {
|
|
1516
1484
|
setStepTransactionIds(actions, txId, 'transfer_confirmed', notifier);
|
|
1517
1485
|
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1518
1486
|
next();
|
|
1519
1487
|
onFinish();
|
|
1520
1488
|
}, function (error) {
|
|
1521
1489
|
if (swap.status === 'failed') return;
|
|
1522
|
-
var
|
|
1523
|
-
extraMessage =
|
|
1524
|
-
extraMessageDetail =
|
|
1525
|
-
extraMessageErrorCode =
|
|
1490
|
+
var _prettifyErrorMessage4 = prettifyErrorMessage(error),
|
|
1491
|
+
extraMessage = _prettifyErrorMessage4.extraMessage,
|
|
1492
|
+
extraMessageDetail = _prettifyErrorMessage4.extraMessageDetail,
|
|
1493
|
+
extraMessageErrorCode = _prettifyErrorMessage4.extraMessageErrorCode;
|
|
1526
1494
|
var updateResult = updateSwapStatus({
|
|
1527
1495
|
getStorage: getStorage,
|
|
1528
1496
|
setStorage: setStorage,
|
|
@@ -1539,7 +1507,7 @@ function singTransaction(actions) {
|
|
|
1539
1507
|
onFinish();
|
|
1540
1508
|
});
|
|
1541
1509
|
} else if (!!evmTransaction) {
|
|
1542
|
-
var
|
|
1510
|
+
var _updateResult4 = updateSwapStatus({
|
|
1543
1511
|
getStorage: getStorage,
|
|
1544
1512
|
setStorage: setStorage,
|
|
1545
1513
|
nextStepStatus: 'running',
|
|
@@ -1548,20 +1516,20 @@ function singTransaction(actions) {
|
|
|
1548
1516
|
});
|
|
1549
1517
|
notifier(_extends({
|
|
1550
1518
|
eventType: 'calling_smart_contract'
|
|
1551
|
-
},
|
|
1552
|
-
walletSigners.
|
|
1519
|
+
}, _updateResult4));
|
|
1520
|
+
walletSigners.getSigner(TransactionType.EVM).signAndSendTx(evmTransaction, walletAddress, null).then(function (id) {
|
|
1553
1521
|
setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
|
|
1554
1522
|
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1555
1523
|
next();
|
|
1556
1524
|
onFinish();
|
|
1557
1525
|
}, function (error) {
|
|
1558
|
-
var _error$
|
|
1526
|
+
var _error$root10, _error$root11, _error$root12;
|
|
1559
1527
|
if (swap.status === 'failed') return;
|
|
1560
|
-
var
|
|
1561
|
-
extraMessage =
|
|
1562
|
-
extraMessageDetail =
|
|
1563
|
-
extraMessageErrorCode =
|
|
1564
|
-
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) {
|
|
1565
1533
|
logRPCError(error.root, swap, currentStep, sourceWallet == null ? void 0 : sourceWallet.walletType);
|
|
1566
1534
|
}
|
|
1567
1535
|
var updateResult = updateSwapStatus({
|
|
@@ -1580,7 +1548,7 @@ function singTransaction(actions) {
|
|
|
1580
1548
|
onFinish();
|
|
1581
1549
|
});
|
|
1582
1550
|
} else if (!!cosmosTransaction) {
|
|
1583
|
-
var
|
|
1551
|
+
var _updateResult5 = updateSwapStatus({
|
|
1584
1552
|
getStorage: getStorage,
|
|
1585
1553
|
setStorage: setStorage,
|
|
1586
1554
|
nextStepStatus: 'running',
|
|
@@ -1589,16 +1557,16 @@ function singTransaction(actions) {
|
|
|
1589
1557
|
});
|
|
1590
1558
|
notifier(_extends({
|
|
1591
1559
|
eventType: 'calling_smart_contract'
|
|
1592
|
-
},
|
|
1560
|
+
}, _updateResult5));
|
|
1593
1561
|
// If keplr wallet is executing contracts on terra, throw error. keplr doesn't support transfer or execute contracts. only IBC messages are supported
|
|
1594
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) &&
|
|
1595
1563
|
// here we must allow ibc on terrastatus
|
|
1596
1564
|
sourceWallet.walletType === WalletType.KEPLR) {
|
|
1597
|
-
var
|
|
1598
|
-
extraMessage =
|
|
1599
|
-
extraMessageDetail =
|
|
1600
|
-
extraMessageErrorCode =
|
|
1601
|
-
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({
|
|
1602
1570
|
getStorage: getStorage,
|
|
1603
1571
|
setStorage: setStorage,
|
|
1604
1572
|
nextStatus: 'failed',
|
|
@@ -1609,12 +1577,12 @@ function singTransaction(actions) {
|
|
|
1609
1577
|
});
|
|
1610
1578
|
notifier(_extends({
|
|
1611
1579
|
eventType: 'smart_contract_call_failed'
|
|
1612
|
-
},
|
|
1580
|
+
}, _updateResult6));
|
|
1613
1581
|
failed();
|
|
1614
1582
|
onFinish();
|
|
1615
1583
|
return;
|
|
1616
1584
|
}
|
|
1617
|
-
walletSigners.
|
|
1585
|
+
walletSigners.getSigner(TransactionType.COSMOS).signAndSendTx(cosmosTransaction, walletAddress, null).then(
|
|
1618
1586
|
// todo
|
|
1619
1587
|
function (id) {
|
|
1620
1588
|
setStepTransactionIds(actions, id, 'smart_contract_called', notifier);
|
|
@@ -1623,10 +1591,10 @@ function singTransaction(actions) {
|
|
|
1623
1591
|
onFinish();
|
|
1624
1592
|
}, function (error) {
|
|
1625
1593
|
if (swap.status === 'failed') return;
|
|
1626
|
-
var
|
|
1627
|
-
extraMessage =
|
|
1628
|
-
extraMessageDetail =
|
|
1629
|
-
extraMessageErrorCode =
|
|
1594
|
+
var _prettifyErrorMessage7 = prettifyErrorMessage(error),
|
|
1595
|
+
extraMessage = _prettifyErrorMessage7.extraMessage,
|
|
1596
|
+
extraMessageDetail = _prettifyErrorMessage7.extraMessageDetail,
|
|
1597
|
+
extraMessageErrorCode = _prettifyErrorMessage7.extraMessageErrorCode;
|
|
1630
1598
|
var updateResult = updateSwapStatus({
|
|
1631
1599
|
getStorage: getStorage,
|
|
1632
1600
|
setStorage: setStorage,
|
|
@@ -1643,7 +1611,7 @@ function singTransaction(actions) {
|
|
|
1643
1611
|
onFinish();
|
|
1644
1612
|
});
|
|
1645
1613
|
} else if (!!solanaTransaction) {
|
|
1646
|
-
var
|
|
1614
|
+
var _updateResult7 = updateSwapStatus({
|
|
1647
1615
|
getStorage: getStorage,
|
|
1648
1616
|
setStorage: setStorage,
|
|
1649
1617
|
nextStepStatus: 'running',
|
|
@@ -1652,19 +1620,101 @@ function singTransaction(actions) {
|
|
|
1652
1620
|
});
|
|
1653
1621
|
notifier(_extends({
|
|
1654
1622
|
eventType: 'calling_smart_contract'
|
|
1655
|
-
},
|
|
1623
|
+
}, _updateResult7));
|
|
1656
1624
|
var tx = solanaTransaction;
|
|
1657
|
-
walletSigners.
|
|
1625
|
+
walletSigners.getSigner(TransactionType.SOLANA).signAndSendTx(tx, walletAddress, null).then(function (txId) {
|
|
1658
1626
|
setStepTransactionIds(actions, txId, 'smart_contract_called', notifier);
|
|
1659
1627
|
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1660
1628
|
next();
|
|
1661
1629
|
onFinish();
|
|
1662
1630
|
}, function (error) {
|
|
1663
1631
|
if (swap.status === 'failed') return;
|
|
1664
|
-
var
|
|
1665
|
-
extraMessage =
|
|
1666
|
-
extraMessageDetail =
|
|
1667
|
-
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
|
+
}
|
|
1668
1718
|
var updateResult = updateSwapStatus({
|
|
1669
1719
|
getStorage: getStorage,
|
|
1670
1720
|
setStorage: setStorage,
|
|
@@ -1778,7 +1828,11 @@ function _checkTransactionStatus() {
|
|
|
1778
1828
|
status = null;
|
|
1779
1829
|
_context.prev = 5;
|
|
1780
1830
|
_context.next = 8;
|
|
1781
|
-
return
|
|
1831
|
+
return httpService.checkStatus({
|
|
1832
|
+
requestId: swap.requestId,
|
|
1833
|
+
txId: txId,
|
|
1834
|
+
step: currentStep.id
|
|
1835
|
+
});
|
|
1782
1836
|
case 8:
|
|
1783
1837
|
status = _context.sent;
|
|
1784
1838
|
_context.next = 17;
|
|
@@ -1792,14 +1846,14 @@ function _checkTransactionStatus() {
|
|
|
1792
1846
|
retry();
|
|
1793
1847
|
return _context.abrupt("return");
|
|
1794
1848
|
case 17:
|
|
1795
|
-
outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ?
|
|
1849
|
+
outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (!!currentStep.outputAmount ? currentStep.outputAmount : null);
|
|
1796
1850
|
prevOutputAmount = currentStep.outputAmount;
|
|
1797
1851
|
swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
|
|
1798
1852
|
swap.extraMessageSeverity = MessageSeverity.info;
|
|
1799
1853
|
swap.extraMessageDetail = '';
|
|
1800
1854
|
currentStep.status = ((_status3 = status) == null ? void 0 : _status3.status) || currentStep.status;
|
|
1801
1855
|
currentStep.diagnosisUrl = ((_status4 = status) == null ? void 0 : _status4.diagnosisUrl) || currentStep.diagnosisUrl || null;
|
|
1802
|
-
currentStep.outputAmount =
|
|
1856
|
+
currentStep.outputAmount = outputAmount || currentStep.outputAmount;
|
|
1803
1857
|
currentStep.explorerUrl = ((_status5 = status) == null ? void 0 : _status5.explorerUrl) || currentStep.explorerUrl;
|
|
1804
1858
|
currentStep.internalSteps = ((_status6 = status) == null ? void 0 : _status6.steps) || null;
|
|
1805
1859
|
newTransaction = (_status7 = status) == null ? void 0 : _status7.newTx;
|
|
@@ -1887,19 +1941,20 @@ function _checkApprovalStatus() {
|
|
|
1887
1941
|
isApproved = false;
|
|
1888
1942
|
_context2.prev = 4;
|
|
1889
1943
|
_context2.next = 7;
|
|
1890
|
-
return
|
|
1944
|
+
return httpService.checkApproval(swap.requestId);
|
|
1891
1945
|
case 7:
|
|
1892
1946
|
response = _context2.sent;
|
|
1893
1947
|
isApproved = response.isApproved;
|
|
1894
|
-
_context2.next =
|
|
1948
|
+
_context2.next = 15;
|
|
1895
1949
|
break;
|
|
1896
1950
|
case 11:
|
|
1897
1951
|
_context2.prev = 11;
|
|
1898
1952
|
_context2.t0 = _context2["catch"](4);
|
|
1899
1953
|
console.error('Failed to check getApprovedAmount', _context2.t0);
|
|
1900
|
-
|
|
1954
|
+
isApproved = false;
|
|
1955
|
+
case 15:
|
|
1901
1956
|
if (!isApproved) {
|
|
1902
|
-
_context2.next =
|
|
1957
|
+
_context2.next = 28;
|
|
1903
1958
|
break;
|
|
1904
1959
|
}
|
|
1905
1960
|
currentStep.status = 'approved';
|
|
@@ -1918,14 +1973,14 @@ function _checkApprovalStatus() {
|
|
|
1918
1973
|
});
|
|
1919
1974
|
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
1920
1975
|
next();
|
|
1921
|
-
_context2.next =
|
|
1976
|
+
_context2.next = 31;
|
|
1922
1977
|
break;
|
|
1923
|
-
case
|
|
1924
|
-
_context2.next =
|
|
1978
|
+
case 28:
|
|
1979
|
+
_context2.next = 30;
|
|
1925
1980
|
return delay(2000);
|
|
1926
|
-
case 29:
|
|
1927
|
-
retry();
|
|
1928
1981
|
case 30:
|
|
1982
|
+
retry();
|
|
1983
|
+
case 31:
|
|
1929
1984
|
case "end":
|
|
1930
1985
|
return _context2.stop();
|
|
1931
1986
|
}
|
|
@@ -1978,20 +2033,20 @@ function _checkStatus() {
|
|
|
1978
2033
|
* It can be failed if server goes through an error, If not, we will schedule the `EXECTUTE_TRANSACTION`.
|
|
1979
2034
|
*
|
|
1980
2035
|
*/
|
|
1981
|
-
function createTransaction
|
|
1982
|
-
return _createTransaction
|
|
2036
|
+
function createTransaction(_x) {
|
|
2037
|
+
return _createTransaction.apply(this, arguments);
|
|
1983
2038
|
}
|
|
1984
|
-
function _createTransaction
|
|
1985
|
-
_createTransaction
|
|
1986
|
-
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;
|
|
1987
2042
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1988
2043
|
while (1) switch (_context.prev = _context.next) {
|
|
1989
2044
|
case 0:
|
|
1990
2045
|
setStorage = actions.setStorage, getStorage = actions.getStorage, next = actions.next, schedule = actions.schedule, context = actions.context;
|
|
1991
2046
|
swap = getStorage().swapDetails; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1992
2047
|
currentStep = getCurrentStep(swap);
|
|
1993
|
-
evmTransaction = currentStep.evmTransaction, cosmosTransaction = currentStep.cosmosTransaction, transferTransaction = currentStep.transferTransaction, evmApprovalTransaction = currentStep.evmApprovalTransaction, solanaTransaction = currentStep.solanaTransaction;
|
|
1994
|
-
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)) {
|
|
1995
2050
|
_context.next = 25;
|
|
1996
2051
|
break;
|
|
1997
2052
|
}
|
|
@@ -2009,10 +2064,10 @@ function _createTransaction$1() {
|
|
|
2009
2064
|
};
|
|
2010
2065
|
_context.prev = 6;
|
|
2011
2066
|
_context.next = 9;
|
|
2012
|
-
return createTransaction(request);
|
|
2067
|
+
return httpService.createTransaction(request);
|
|
2013
2068
|
case 9:
|
|
2014
|
-
_yield$
|
|
2015
|
-
transaction = _yield$
|
|
2069
|
+
_yield$httpService$cr = _context.sent;
|
|
2070
|
+
transaction = _yield$httpService$cr.transaction;
|
|
2016
2071
|
if (transaction) {
|
|
2017
2072
|
if (isEvmTransaction(transaction)) {
|
|
2018
2073
|
if (transaction.isApprovalTx) currentStep.evmApprovalTransaction = transaction;else currentStep.evmTransaction = transaction;
|
|
@@ -2022,6 +2077,10 @@ function _createTransaction$1() {
|
|
|
2022
2077
|
currentStep.solanaTransaction = transaction;
|
|
2023
2078
|
} else if (isTrasnferTransaction(transaction)) {
|
|
2024
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;
|
|
2025
2084
|
}
|
|
2026
2085
|
}
|
|
2027
2086
|
setStorage(_extends({}, getStorage(), {
|
|
@@ -2056,7 +2115,7 @@ function _createTransaction$1() {
|
|
|
2056
2115
|
}
|
|
2057
2116
|
}, _callee, null, [[6, 17]]);
|
|
2058
2117
|
}));
|
|
2059
|
-
return _createTransaction
|
|
2118
|
+
return _createTransaction.apply(this, arguments);
|
|
2060
2119
|
}
|
|
2061
2120
|
|
|
2062
2121
|
/**
|
|
@@ -2225,7 +2284,7 @@ var _actions;
|
|
|
2225
2284
|
*/
|
|
2226
2285
|
var swapQueueDef = {
|
|
2227
2286
|
name: 'swap',
|
|
2228
|
-
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),
|
|
2229
2288
|
run: [SwapActionTypes.START],
|
|
2230
2289
|
whenTaskBlocked: function whenTaskBlocked(event, meta) {
|
|
2231
2290
|
if (event.reason.reason === BlockReason.WAIT_FOR_CONNECT_WALLET) {
|