@fileverse-dev/formulajs 4.4.11-mod-15-patch-2 → 4.4.11-mod-16

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.
@@ -1,4 +1,4 @@
1
- /* @fileverse-dev/formulajs v4.4.11-mod-15-patch-2 */
1
+ /* @fileverse-dev/formulajs v4.4.11-mod-16 */
2
2
  function _regeneratorRuntime() {
3
3
  "use strict";
4
4
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() {
@@ -10745,49 +10745,43 @@ function _typeof(o) {
10745
10745
  Gnosisscan: "GNOSISSSCAN",
10746
10746
  BASESCAN: "Basescan"
10747
10747
  };
10748
- var CHAIN_API_BASE = {
10749
- ethereum: "https://api.etherscan.io/api",
10750
- gnosis: "https://api.gnosisscan.io/api",
10751
- base: "https://api.basescan.org/api"
10748
+ var CHAIN_ID_MAP = {
10749
+ ethereum: 1,
10750
+ gnosis: 100,
10751
+ base: 8453
10752
10752
  };
10753
10753
  var fromTimeStampToBlock = function() {
10754
10754
  var _ref = _asyncToGenerator(_regeneratorRuntime().mark((function _callee(timestamp, chain, apiKey) {
10755
- var baseUrl, url, res, json;
10755
+ var chainId, url, res, json;
10756
10756
  return _regeneratorRuntime().wrap((function _callee$(_context) {
10757
10757
  while (1) switch (_context.prev = _context.next) {
10758
10758
  case 0:
10759
- baseUrl = CHAIN_API_BASE[chain];
10760
- if (baseUrl) {
10761
- _context.next = 3;
10759
+ if (!(!timestamp || !chain || !apiKey)) {
10760
+ _context.next = 2;
10762
10761
  break;
10763
10762
  }
10764
- throw new Error("Unsupported Chain");
10763
+ return _context.abrupt("return");
10765
10764
 
10766
- case 3:
10767
- _context.prev = 3;
10768
- url = "".concat(baseUrl, "?module=block&action=getblocknobytime&timestamp=").concat(timestamp, "&closest=before&apikey=").concat(apiKey);
10769
- _context.next = 7;
10765
+ case 2:
10766
+ chainId = CHAIN_ID_MAP[chain];
10767
+ url = "https://api.etherscan.io/v2/api?module=block&action=getblocknobytime&timestamp=".concat(timestamp, "&closest=before&apikey=").concat(apiKey, "&chainId=").concat(chainId);
10768
+ _context.next = 6;
10770
10769
  return fetch(url);
10771
10770
 
10772
- case 7:
10771
+ case 6:
10773
10772
  res = _context.sent;
10774
- _context.next = 10;
10773
+ _context.next = 9;
10775
10774
  return res.json();
10776
10775
 
10777
- case 10:
10776
+ case 9:
10778
10777
  json = _context.sent;
10779
10778
  return _context.abrupt("return", parseInt(json.result));
10780
10779
 
10781
- case 14:
10782
- _context.prev = 14;
10783
- _context.t0 = _context["catch"](3);
10784
- return _context.abrupt("return", 0);
10785
-
10786
- case 17:
10780
+ case 11:
10787
10781
  case "end":
10788
10782
  return _context.stop();
10789
10783
  }
10790
- }), _callee, null, [ [ 3, 14 ] ]);
10784
+ }), _callee);
10791
10785
  })));
10792
10786
  return function fromTimeStampToBlock(_x, _x2, _x3) {
10793
10787
  return _ref.apply(this, arguments);
@@ -10920,7 +10914,7 @@ function _typeof(o) {
10920
10914
  }
10921
10915
  function _OX() {
10922
10916
  _OX = _asyncToGenerator(_regeneratorRuntime().mark((function _callee4(address, categories, chain, startTime, endTime) {
10923
- var API_KEYS, apiKey, baseUrl, startBlock, endBlock, action, url, _json$result, _json$result$includes, response, json;
10917
+ var API_KEYS, apiKey, chainId, action, timeQuery, startBlock, endBlock, url, _json$result, _json$result$includes, response, json;
10924
10918
  return _regeneratorRuntime().wrap((function _callee4$(_context4) {
10925
10919
  while (1) switch (_context4.prev = _context4.next) {
10926
10920
  case 0:
@@ -10930,58 +10924,89 @@ function _typeof(o) {
10930
10924
  base: window.localStorage.getItem(SERVICE_API_KEY.Basescan)
10931
10925
  };
10932
10926
  apiKey = API_KEYS[chain];
10933
- baseUrl = CHAIN_API_BASE[chain];
10934
- _context4.next = 5;
10935
- return fromTimeStampToBlock(startTime, chain, apiKey);
10927
+ chainId = CHAIN_ID_MAP[chain];
10928
+ if (!(!apiKey || !chainId)) {
10929
+ _context4.next = 5;
10930
+ break;
10931
+ }
10932
+ return _context4.abrupt("return", "".concat(chain.toUpperCase(), "_MISSING"));
10936
10933
 
10937
10934
  case 5:
10935
+ action = "";
10936
+ if (categories === "txns") action = "account.txlist"; else {
10937
+ action = "account.balance";
10938
+ }
10939
+ timeQuery = "";
10940
+ if (!(!isNaN(startTime) && !isNaN(endTime))) {
10941
+ _context4.next = 18;
10942
+ break;
10943
+ }
10944
+ _context4.next = 11;
10945
+ return fromTimeStampToBlock(startTime, chain, apiKey);
10946
+
10947
+ case 11:
10938
10948
  startBlock = _context4.sent;
10939
- _context4.next = 8;
10940
- return fromTimeStampToBlock(endTime);
10949
+ _context4.next = 14;
10950
+ return fromTimeStampToBlock(endTime, chain, apiKey);
10941
10951
 
10942
- case 8:
10952
+ case 14:
10943
10953
  endBlock = _context4.sent;
10944
- action = "";
10945
- if (categories === "txns") action = "txlist"; else if (categories === "balances") action = "balance"; else if (categories === "portfolio") action = "tokentx";
10946
- url = "".concat(baseUrl, "?module=account&action=").concat(action, "&address=").concat(address, "&startblock=").concat(startBlock, "&endblock=").concat(endBlock, "&sort=asc&apikey=").concat(apiKey);
10947
- _context4.prev = 12;
10948
- _context4.next = 15;
10954
+ timeQuery = "&startblock=".concat(startBlock, "&endblock=").concat(endBlock);
10955
+ _context4.next = 23;
10956
+ break;
10957
+
10958
+ case 18:
10959
+ if (!(categories === "balance")) {
10960
+ _context4.next = 22;
10961
+ break;
10962
+ }
10963
+ timeQuery = "&tag=latest";
10964
+ _context4.next = 23;
10965
+ break;
10966
+
10967
+ case 22:
10968
+ throw new Error("Start and End Time is required for querying transaction list ");
10969
+
10970
+ case 23:
10971
+ url = "https://api.etherscan.io/v2/api?module=".concat(action.split(".")[0], "&action=").concat(action.split(".")[1], "&address=").concat(address, "&sort=asc&chainid=").concat(chainId, "&apikey=").concat(apiKey).concat(timeQuery);
10972
+ _context4.prev = 24;
10973
+ _context4.next = 27;
10949
10974
  return fetch(url);
10950
10975
 
10951
- case 15:
10976
+ case 27:
10952
10977
  response = _context4.sent;
10953
10978
  if (response.ok) {
10954
- _context4.next = 18;
10979
+ _context4.next = 30;
10955
10980
  break;
10956
10981
  }
10957
10982
  throw new Error("HTTP error! Status: ".concat(response.status));
10958
10983
 
10959
- case 18:
10960
- _context4.next = 20;
10984
+ case 30:
10985
+ _context4.next = 32;
10961
10986
  return response.json();
10962
10987
 
10963
- case 20:
10988
+ case 32:
10964
10989
  json = _context4.sent;
10965
10990
  if (!((_json$result = json.result) !== null && _json$result !== void 0 && (_json$result$includes = _json$result.includes) !== null && _json$result$includes !== void 0 && _json$result$includes.call(_json$result, "Invalid API Key"))) {
10966
- _context4.next = 23;
10991
+ _context4.next = 35;
10967
10992
  break;
10968
10993
  }
10969
10994
  return _context4.abrupt("return", "".concat(SERVICE_API_KEY[chain.charAt(0).toUpperCase() + chain.slice(1)], "_MISSING"));
10970
10995
 
10971
- case 23:
10996
+ case 35:
10972
10997
  return _context4.abrupt("return", json.result);
10973
10998
 
10974
- case 26:
10975
- _context4.prev = 26;
10976
- _context4.t0 = _context4["catch"](12);
10999
+ case 38:
11000
+ _context4.prev = 38;
11001
+ _context4.t0 = _context4["catch"](24);
10977
11002
  console.log(_context4.t0);
10978
11003
  return _context4.abrupt("return", "ERROR IN FETCHING");
10979
11004
 
10980
- case 30:
11005
+ case 42:
10981
11006
  case "end":
10982
11007
  return _context4.stop();
10983
11008
  }
10984
- }), _callee4, null, [ [ 12, 26 ] ]);
11009
+ }), _callee4, null, [ [ 24, 38 ] ]);
10985
11010
  })));
10986
11011
  return _OX.apply(this, arguments);
10987
11012
  }