@rango-dev/queue-manager-rango-preset 0.1.15-next.7 → 0.1.15-next.8

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.
@@ -829,20 +829,17 @@ function claimQueue() {
829
829
  }
830
830
  };
831
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() {
832
+ var swapTransactionToDataMap = {};
833
+ function useTransactionsData() {
840
834
  return {
841
- getTransactionResponseByHash: function getTransactionResponseByHash(hash) {
842
- return swapTransactionToResponseMap[hash];
835
+ getTransactionDataByHash: function getTransactionDataByHash(hash) {
836
+ return swapTransactionToDataMap[hash] || {};
843
837
  },
844
- setTransactionResponseByHash: function setTransactionResponseByHash(hash, response) {
845
- swapTransactionToResponseMap[hash] = response;
838
+ setTransactionDataByHash: function setTransactionDataByHash(hash, data) {
839
+ var r = swapTransactionToDataMap[hash];
840
+ if (!r) swapTransactionToDataMap[hash] = {};
841
+ swapTransactionToDataMap[hash].response = data.response || swapTransactionToDataMap[hash].response;
842
+ swapTransactionToDataMap[hash].receiptReceived = data.receiptReceived || swapTransactionToDataMap[hash].receiptReceived || false;
846
843
  }
847
844
  };
848
845
  }
@@ -1499,8 +1496,8 @@ function isRequiredWalletConnected(swap, getState) {
1499
1496
  };
1500
1497
  }
1501
1498
  function singTransaction(actions) {
1502
- var _useTransactionsRespo = useTransactionsResponse(),
1503
- setTransactionResponseByHash = _useTransactionsRespo.setTransactionResponseByHash;
1499
+ var _useTransactionsData = useTransactionsData(),
1500
+ setTransactionDataByHash = _useTransactionsData.setTransactionDataByHash;
1504
1501
  var getStorage = actions.getStorage,
1505
1502
  setStorage = actions.setStorage,
1506
1503
  failed = actions.failed,
@@ -1578,7 +1575,9 @@ function singTransaction(actions) {
1578
1575
  description: isApproval ? 'Approve' : 'Swap'
1579
1576
  } : undefined);
1580
1577
  // response used for evm transactions to get receipt and track replaced
1581
- response && setTransactionResponseByHash(hash, response);
1578
+ response && setTransactionDataByHash(hash, {
1579
+ response: response
1580
+ });
1582
1581
  schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
1583
1582
  next();
1584
1583
  onFinish();
@@ -1864,7 +1863,7 @@ function checkTransactionStatus(_x) {
1864
1863
  function _checkTransactionStatus() {
1865
1864
  _checkTransactionStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
1866
1865
  var _status, _status2, _status3, _status4, _status5, _status6, _status7, _status9, _status10, _status11;
1867
- 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;
1866
+ var getStorage, setStorage, next, schedule, retry, failed, context, swap, meta, currentStep, txId, getTxReceiptFailed, status, signer, _useTransactionsData, getTransactionDataByHash, setTransactionDataByHash, txType, sourceWallet, _signer, _getTransactionDataBy, txResponse, receiptReceived, _yield$signer$wait, updatedTxHash, updatedTxResponse, currentStepBlockchain, explorerUrl, _currentStep$explorer, _prettifyErrorMessage, extraMessage, extraMessageDetail, extraMessageErrorCode, updateResult, outputAmount, prevOutputAmount, newTransaction, nextStep, _status8;
1868
1867
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1869
1868
  while (1) switch (_context.prev = _context.next) {
1870
1869
  case 0:
@@ -1872,11 +1871,17 @@ function _checkTransactionStatus() {
1872
1871
  swap = getStorage().swapDetails;
1873
1872
  meta = context.meta; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1874
1873
  currentStep = getCurrentStep(swap);
1874
+ if (currentStep != null && currentStep.executedTransactionId) {
1875
+ _context.next = 6;
1876
+ break;
1877
+ }
1878
+ return _context.abrupt("return");
1879
+ case 6:
1875
1880
  txId = currentStep.executedTransactionId;
1876
1881
  getTxReceiptFailed = false;
1877
1882
  status = null;
1878
1883
  signer = null;
1879
- _useTransactionsRespo = useTransactionsResponse(), getTransactionResponseByHash = _useTransactionsRespo.getTransactionResponseByHash, setTransactionResponseByHash = _useTransactionsRespo.setTransactionResponseByHash;
1884
+ _useTransactionsData = useTransactionsData(), getTransactionDataByHash = _useTransactionsData.getTransactionDataByHash, setTransactionDataByHash = _useTransactionsData.setTransactionDataByHash;
1880
1885
  try {
1881
1886
  txType = getCurrentStepTxType(currentStep);
1882
1887
  sourceWallet = getRelatedWallet(swap, currentStep);
@@ -1885,15 +1890,16 @@ function _checkTransactionStatus() {
1885
1890
  // wallet is not connected yet
1886
1891
  // no need to do anything
1887
1892
  }
1888
- _context.prev = 10;
1889
- if (!((_signer = signer) != null && _signer.wait)) {
1890
- _context.next = 19;
1893
+ _context.prev = 12;
1894
+ // if wallet is connected, try to get transaction reciept
1895
+ _getTransactionDataBy = getTransactionDataByHash(txId), txResponse = _getTransactionDataBy.response, receiptReceived = _getTransactionDataBy.receiptReceived;
1896
+ if (!((_signer = signer) != null && _signer.wait && !receiptReceived)) {
1897
+ _context.next = 21;
1891
1898
  break;
1892
1899
  }
1893
- txResponse = getTransactionResponseByHash(txId);
1894
- _context.next = 15;
1900
+ _context.next = 17;
1895
1901
  return signer.wait(txId, txResponse);
1896
- case 15:
1902
+ case 17:
1897
1903
  _yield$signer$wait = _context.sent;
1898
1904
  updatedTxHash = _yield$signer$wait.hash;
1899
1905
  updatedTxResponse = _yield$signer$wait.response;
@@ -1910,14 +1916,20 @@ function _checkTransactionStatus() {
1910
1916
  }
1911
1917
  }
1912
1918
  txId = currentStep.executedTransactionId;
1913
- if (updatedTxHash && updatedTxResponse) setTransactionResponseByHash(updatedTxHash, updatedTxResponse);
1919
+ if (updatedTxHash && updatedTxResponse) setTransactionDataByHash(updatedTxHash, {
1920
+ response: updatedTxResponse
1921
+ });
1922
+ } else {
1923
+ setTransactionDataByHash(updatedTxHash, {
1924
+ receiptReceived: true
1925
+ });
1914
1926
  }
1915
- case 19:
1916
- _context.next = 27;
1917
- break;
1918
1927
  case 21:
1919
- _context.prev = 21;
1920
- _context.t0 = _context["catch"](10);
1928
+ _context.next = 29;
1929
+ break;
1930
+ case 23:
1931
+ _context.prev = 23;
1932
+ _context.t0 = _context["catch"](12);
1921
1933
  _prettifyErrorMessage = prettifyErrorMessage(_context.t0), extraMessage = _prettifyErrorMessage.extraMessage, extraMessageDetail = _prettifyErrorMessage.extraMessageDetail, extraMessageErrorCode = _prettifyErrorMessage.extraMessageErrorCode;
1922
1934
  updateResult = updateSwapStatus({
1923
1935
  getStorage: getStorage,
@@ -1934,39 +1946,39 @@ function _checkTransactionStatus() {
1934
1946
  getTxReceiptFailed = true;
1935
1947
  // We shouldn't return here, because we need to trigger check status job in backend.
1936
1948
  // This is not a ui requirement but the backend one.
1937
- case 27:
1938
- _context.prev = 27;
1939
- _context.next = 30;
1949
+ case 29:
1950
+ _context.prev = 29;
1951
+ _context.next = 32;
1940
1952
  return httpService().checkStatus({
1941
1953
  requestId: swap.requestId,
1942
1954
  txId: txId,
1943
1955
  step: currentStep.id
1944
1956
  });
1945
- case 30:
1957
+ case 32:
1946
1958
  status = _context.sent;
1947
- _context.next = 39;
1959
+ _context.next = 41;
1948
1960
  break;
1949
- case 33:
1950
- _context.prev = 33;
1951
- _context.t1 = _context["catch"](27);
1952
- _context.next = 37;
1961
+ case 35:
1962
+ _context.prev = 35;
1963
+ _context.t1 = _context["catch"](29);
1964
+ _context.next = 39;
1953
1965
  return delay(INTERVAL_FOR_CHECK);
1954
- case 37:
1966
+ case 39:
1955
1967
  retry();
1956
1968
  return _context.abrupt("return");
1957
- case 39:
1969
+ case 41:
1958
1970
  if (!getTxReceiptFailed) {
1959
- _context.next = 41;
1971
+ _context.next = 43;
1960
1972
  break;
1961
1973
  }
1962
1974
  return _context.abrupt("return", failed());
1963
- case 41:
1975
+ case 43:
1964
1976
  if (!((currentStep == null ? void 0 : currentStep.status) === 'failed')) {
1965
- _context.next = 43;
1977
+ _context.next = 45;
1966
1978
  break;
1967
1979
  }
1968
1980
  return _context.abrupt("return");
1969
- case 43:
1981
+ case 45:
1970
1982
  outputAmount = ((_status = status) == null ? void 0 : _status.outputAmount) || (currentStep.outputAmount ? currentStep.outputAmount : null);
1971
1983
  prevOutputAmount = currentStep.outputAmount || null;
1972
1984
  swap.extraMessage = ((_status2 = status) == null ? void 0 : _status2.extraMessage) || swap.extraMessage;
@@ -2012,31 +2024,31 @@ function _checkTransactionStatus() {
2012
2024
  swapDetails: swap
2013
2025
  }));
2014
2026
  if (!(((_status9 = status) == null ? void 0 : _status9.status) === 'failed')) {
2015
- _context.next = 62;
2027
+ _context.next = 64;
2016
2028
  break;
2017
2029
  }
2018
2030
  failed();
2019
- _context.next = 70;
2031
+ _context.next = 72;
2020
2032
  break;
2021
- case 62:
2033
+ case 64:
2022
2034
  if (!(((_status10 = status) == null ? void 0 : _status10.status) === 'success' || ((_status11 = status) == null ? void 0 : _status11.status) === 'running' && !!status.newTx)) {
2023
- _context.next = 67;
2035
+ _context.next = 69;
2024
2036
  break;
2025
2037
  }
2026
2038
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2027
2039
  next();
2028
- _context.next = 70;
2040
+ _context.next = 72;
2029
2041
  break;
2030
- case 67:
2031
- _context.next = 69;
2032
- return delay(INTERVAL_FOR_CHECK);
2033
2042
  case 69:
2043
+ _context.next = 71;
2044
+ return delay(INTERVAL_FOR_CHECK);
2045
+ case 71:
2034
2046
  retry();
2035
- case 70:
2047
+ case 72:
2036
2048
  case "end":
2037
2049
  return _context.stop();
2038
2050
  }
2039
- }, _callee, null, [[10, 21], [27, 33]]);
2051
+ }, _callee, null, [[12, 23], [29, 35]]);
2040
2052
  }));
2041
2053
  return _checkTransactionStatus.apply(this, arguments);
2042
2054
  }
@@ -2053,14 +2065,14 @@ function checkApprovalStatus(_x2) {
2053
2065
  */
2054
2066
  function _checkApprovalStatus() {
2055
2067
  _checkApprovalStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
2056
- 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;
2068
+ var getStorage, setStorage, next, schedule, retry, failed, context, swap, meta, _useTransactionsData2, getTransactionDataByHash, setTransactionDataByHash, currentStep, txId, signer, txType, sourceWallet, _signer2, _getTransactionDataBy2, txResponse, receiptReceived, _yield$signer$wait2, updatedTxHash, updatedTxResponse, currentStepBlockchain, explorerUrl, _currentStep$explorer2, _prettifyErrorMessage2, extraMessage, extraMessageDetail, extraMessageErrorCode, updateResult, isApproved, response, message, details, _updateResult;
2057
2069
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2058
2070
  while (1) switch (_context2.prev = _context2.next) {
2059
2071
  case 0:
2060
2072
  getStorage = _ref2.getStorage, setStorage = _ref2.setStorage, next = _ref2.next, schedule = _ref2.schedule, retry = _ref2.retry, failed = _ref2.failed, context = _ref2.context;
2061
2073
  swap = getStorage().swapDetails;
2062
2074
  meta = context.meta;
2063
- _useTransactionsRespo2 = useTransactionsResponse(), getTransactionResponseByHash = _useTransactionsRespo2.getTransactionResponseByHash, setTransactionResponseByHash = _useTransactionsRespo2.setTransactionResponseByHash;
2075
+ _useTransactionsData2 = useTransactionsData(), getTransactionDataByHash = _useTransactionsData2.getTransactionDataByHash, setTransactionDataByHash = _useTransactionsData2.setTransactionDataByHash;
2064
2076
  currentStep = getCurrentStep(swap);
2065
2077
  if (currentStep) {
2066
2078
  _context2.next = 8;
@@ -2069,6 +2081,12 @@ function _checkApprovalStatus() {
2069
2081
  console.log('ignore check status, current step is null');
2070
2082
  return _context2.abrupt("return");
2071
2083
  case 8:
2084
+ if (currentStep != null && currentStep.executedTransactionId) {
2085
+ _context2.next = 10;
2086
+ break;
2087
+ }
2088
+ return _context2.abrupt("return");
2089
+ case 10:
2072
2090
  txId = currentStep.executedTransactionId;
2073
2091
  signer = null;
2074
2092
  try {
@@ -2079,15 +2097,15 @@ function _checkApprovalStatus() {
2079
2097
  // wallet is not connected yet
2080
2098
  // no need to do anything
2081
2099
  }
2082
- _context2.prev = 11;
2083
- if (!((_signer2 = signer) != null && _signer2.wait)) {
2084
- _context2.next = 20;
2100
+ _context2.prev = 13;
2101
+ _getTransactionDataBy2 = getTransactionDataByHash(txId), txResponse = _getTransactionDataBy2.response, receiptReceived = _getTransactionDataBy2.receiptReceived; // if wallet is connected, try to get transaction reciept
2102
+ if (!((_signer2 = signer) != null && _signer2.wait && !receiptReceived)) {
2103
+ _context2.next = 22;
2085
2104
  break;
2086
2105
  }
2087
- txResponse = getTransactionResponseByHash(txId);
2088
- _context2.next = 16;
2106
+ _context2.next = 18;
2089
2107
  return signer.wait(txId, txResponse);
2090
- case 16:
2108
+ case 18:
2091
2109
  _yield$signer$wait2 = _context2.sent;
2092
2110
  updatedTxHash = _yield$signer$wait2.hash;
2093
2111
  updatedTxResponse = _yield$signer$wait2.response;
@@ -2104,14 +2122,20 @@ function _checkApprovalStatus() {
2104
2122
  }
2105
2123
  }
2106
2124
  txId = currentStep.executedTransactionId;
2107
- if (updatedTxHash && updatedTxResponse) setTransactionResponseByHash(updatedTxHash, updatedTxResponse);
2125
+ if (updatedTxHash && updatedTxResponse) setTransactionDataByHash(updatedTxHash, {
2126
+ response: updatedTxResponse
2127
+ });
2128
+ } else {
2129
+ setTransactionDataByHash(updatedTxHash, {
2130
+ receiptReceived: true
2131
+ });
2108
2132
  }
2109
- case 20:
2110
- _context2.next = 28;
2111
- break;
2112
2133
  case 22:
2113
- _context2.prev = 22;
2114
- _context2.t0 = _context2["catch"](11);
2134
+ _context2.next = 30;
2135
+ break;
2136
+ case 24:
2137
+ _context2.prev = 24;
2138
+ _context2.t0 = _context2["catch"](13);
2115
2139
  _prettifyErrorMessage2 = prettifyErrorMessage(_context2.t0), extraMessage = _prettifyErrorMessage2.extraMessage, extraMessageDetail = _prettifyErrorMessage2.extraMessageDetail, extraMessageErrorCode = _prettifyErrorMessage2.extraMessageErrorCode;
2116
2140
  updateResult = updateSwapStatus({
2117
2141
  getStorage: getStorage,
@@ -2126,19 +2150,19 @@ function _checkApprovalStatus() {
2126
2150
  eventType: 'task_failed'
2127
2151
  }, updateResult));
2128
2152
  return _context2.abrupt("return", failed());
2129
- case 28:
2153
+ case 30:
2130
2154
  isApproved = false;
2131
- _context2.prev = 29;
2132
- _context2.next = 32;
2133
- return httpService().checkApproval(swap.requestId, currentStep.executedTransactionId || '');
2134
- case 32:
2155
+ _context2.prev = 31;
2156
+ _context2.next = 34;
2157
+ return httpService().checkApproval(swap.requestId, currentStep.executedTransactionId);
2158
+ case 34:
2135
2159
  response = _context2.sent;
2136
2160
  if (!((currentStep == null ? void 0 : currentStep.status) === 'failed')) {
2137
- _context2.next = 35;
2161
+ _context2.next = 37;
2138
2162
  break;
2139
2163
  }
2140
2164
  return _context2.abrupt("return");
2141
- case 35:
2165
+ case 37:
2142
2166
  isApproved = response.isApproved;
2143
2167
  if (!isApproved && (response.txStatus === 'failed' || response.txStatus === 'success')) {
2144
2168
  if (response.txStatus === 'failed') {
@@ -2171,15 +2195,15 @@ function _checkApprovalStatus() {
2171
2195
  step: currentStep
2172
2196
  });
2173
2197
  }
2174
- _context2.next = 42;
2198
+ _context2.next = 44;
2175
2199
  break;
2176
- case 39:
2177
- _context2.prev = 39;
2178
- _context2.t1 = _context2["catch"](29);
2200
+ case 41:
2201
+ _context2.prev = 41;
2202
+ _context2.t1 = _context2["catch"](31);
2179
2203
  isApproved = false;
2180
- case 42:
2204
+ case 44:
2181
2205
  if (!isApproved) {
2182
- _context2.next = 58;
2206
+ _context2.next = 60;
2183
2207
  break;
2184
2208
  }
2185
2209
  currentStep.status = 'approved';
@@ -2201,18 +2225,18 @@ function _checkApprovalStatus() {
2201
2225
  });
2202
2226
  schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
2203
2227
  next();
2204
- _context2.next = 61;
2228
+ _context2.next = 63;
2205
2229
  break;
2206
- case 58:
2207
- _context2.next = 60;
2208
- return delay(2000);
2209
2230
  case 60:
2231
+ _context2.next = 62;
2232
+ return delay(2000);
2233
+ case 62:
2210
2234
  retry();
2211
- case 61:
2235
+ case 63:
2212
2236
  case "end":
2213
2237
  return _context2.stop();
2214
2238
  }
2215
- }, _callee2, null, [[11, 22], [29, 39]]);
2239
+ }, _callee2, null, [[13, 24], [31, 41]]);
2216
2240
  }));
2217
2241
  return _checkApprovalStatus.apply(this, arguments);
2218
2242
  }