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