@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.
package/lib/cjs/index.cjs CHANGED
@@ -13001,25 +13001,20 @@ const SERVICE_API_KEY = {
13001
13001
  BASESCAN: 'Basescan'
13002
13002
  };
13003
13003
 
13004
- const CHAIN_API_BASE = {
13005
- ethereum: 'https://api.etherscan.io/api',
13006
- gnosis: 'https://api.gnosisscan.io/api',
13007
- base: 'https://api.basescan.org/api',
13008
- };
13004
+ const CHAIN_ID_MAP = {
13005
+ ethereum: 1,
13006
+ gnosis: 100,
13007
+ base: 8453,
13008
+ };
13009
13009
 
13010
13010
  const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
13011
- const baseUrl = CHAIN_API_BASE[chain];
13012
- if(!baseUrl){
13013
- throw new Error('Unsupported Chain')
13014
- }
13015
- try {
13016
- const url = `${baseUrl}?module=block&action=getblocknobytime&timestamp=${timestamp}&closest=before&apikey=${apiKey}`;
13011
+ if(!timestamp || !chain || !apiKey) return
13012
+ const chainId = CHAIN_ID_MAP[chain];
13013
+ const url = `https://api.etherscan.io/v2/api?module=block&action=getblocknobytime&timestamp=${timestamp}&closest=before&apikey=${apiKey}&chainId=${chainId}`;
13017
13014
  const res = await fetch(url);
13018
13015
  const json = await res.json();
13019
13016
  return parseInt(json.result);
13020
- } catch {
13021
- return 0;
13022
- }
13017
+
13023
13018
  };
13024
13019
 
13025
13020
  async function ETHERSCAN(address, page, offset) {
@@ -13087,20 +13082,23 @@ async function OX(address, categories, chain, startTime, endTime) {
13087
13082
  gnosis: window.localStorage.getItem(SERVICE_API_KEY.Gnosisscan),
13088
13083
  base: window.localStorage.getItem(SERVICE_API_KEY.Basescan),
13089
13084
  };
13090
-
13091
13085
  const apiKey = API_KEYS[chain];
13092
- const baseUrl = CHAIN_API_BASE[chain];
13093
-
13094
- const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13095
- const endBlock = await fromTimeStampToBlock(endTime);
13086
+ const chainId = CHAIN_ID_MAP[chain];
13087
+ if (!apiKey || !chainId) return `${chain.toUpperCase()}_MISSING`;
13096
13088
 
13097
13089
  let action = '';
13098
- if (categories === 'txns') action = 'txlist';
13099
- else if (categories === 'balances') action = 'balance';
13100
- else if (categories === 'portfolio') action = 'tokentx';
13101
-
13102
- let url = `${baseUrl}?module=account&action=${action}&address=${address}&startblock=${startBlock}&endblock=${endBlock}&sort=asc&apikey=${apiKey}`;
13103
-
13090
+ if (categories === 'txns') action = 'account.txlist';
13091
+ else {action = 'account.balance';} let timeQuery = '';
13092
+ if(!isNaN(startTime) && !isNaN(endTime)){
13093
+ const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13094
+ const endBlock = await fromTimeStampToBlock(endTime, chain, apiKey);
13095
+ timeQuery = `&startblock=${startBlock}&endblock=${endBlock}`;
13096
+ } else if(categories === 'balance') {
13097
+ timeQuery = `&tag=latest`;
13098
+ } else {
13099
+ throw new Error('Start and End Time is required for querying transaction list ')
13100
+ }
13101
+ const url = `https://api.etherscan.io/v2/api?module=${action.split('.')[0]}&action=${action.split('.')[1]}&address=${address}&sort=asc&chainid=${chainId}&apikey=${apiKey}${timeQuery}`;
13104
13102
  try {
13105
13103
  const response = await fetch(url);
13106
13104
  if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
@@ -48,7 +48,7 @@ var FUNCTION_LOCALE = [
48
48
  n: "Ox",
49
49
  t: 20,
50
50
  d: "Fetches address data like transactions, balances, or portfolio info from multiple supported chains.",
51
- a: "Dynamically queries blockchain data such as transactions, balances, or token portfolio by resolving time ranges to block ranges.",
51
+ a: "Dynamically queries blockchain data such as transactions, balances by resolving time ranges to block ranges.",
52
52
  p: [
53
53
  {
54
54
  name: "address",
@@ -58,7 +58,7 @@ var FUNCTION_LOCALE = [
58
58
  },
59
59
  {
60
60
  name: "categories",
61
- detail: `Type of data to fetch. Supported values: "txns", "balances", "portfolio".`,
61
+ detail: `Type of data to fetch. Supported values: "txns", "balance".`,
62
62
  example: `"txns"`,
63
63
  require: "m"
64
64
  },
@@ -70,14 +70,14 @@ var FUNCTION_LOCALE = [
70
70
  },
71
71
  {
72
72
  name: "startTime",
73
- detail: "Start time in UNIX timestamp (seconds). Will be converted to a starting block.",
73
+ detail: "Start time in UNIX timestamp (seconds). Will be converted to a starting block. Required for txns category",
74
74
  example: "1680300000",
75
75
  require: "m",
76
76
  type: "rangenumber"
77
77
  },
78
78
  {
79
79
  name: "endTime",
80
- detail: "End time in UNIX timestamp (seconds). Will be converted to an ending block.",
80
+ detail: "End time in UNIX timestamp (seconds). Will be converted to an ending block. Required for txns category",
81
81
  example: "1680900000",
82
82
  require: "m",
83
83
  type: "rangenumber"
package/lib/esm/index.mjs CHANGED
@@ -12999,25 +12999,20 @@ const SERVICE_API_KEY = {
12999
12999
  BASESCAN: 'Basescan'
13000
13000
  };
13001
13001
 
13002
- const CHAIN_API_BASE = {
13003
- ethereum: 'https://api.etherscan.io/api',
13004
- gnosis: 'https://api.gnosisscan.io/api',
13005
- base: 'https://api.basescan.org/api',
13006
- };
13002
+ const CHAIN_ID_MAP = {
13003
+ ethereum: 1,
13004
+ gnosis: 100,
13005
+ base: 8453,
13006
+ };
13007
13007
 
13008
13008
  const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
13009
- const baseUrl = CHAIN_API_BASE[chain];
13010
- if(!baseUrl){
13011
- throw new Error('Unsupported Chain')
13012
- }
13013
- try {
13014
- const url = `${baseUrl}?module=block&action=getblocknobytime&timestamp=${timestamp}&closest=before&apikey=${apiKey}`;
13009
+ if(!timestamp || !chain || !apiKey) return
13010
+ const chainId = CHAIN_ID_MAP[chain];
13011
+ const url = `https://api.etherscan.io/v2/api?module=block&action=getblocknobytime&timestamp=${timestamp}&closest=before&apikey=${apiKey}&chainId=${chainId}`;
13015
13012
  const res = await fetch(url);
13016
13013
  const json = await res.json();
13017
13014
  return parseInt(json.result);
13018
- } catch {
13019
- return 0;
13020
- }
13015
+
13021
13016
  };
13022
13017
 
13023
13018
  async function ETHERSCAN(address, page, offset) {
@@ -13085,20 +13080,23 @@ async function OX(address, categories, chain, startTime, endTime) {
13085
13080
  gnosis: window.localStorage.getItem(SERVICE_API_KEY.Gnosisscan),
13086
13081
  base: window.localStorage.getItem(SERVICE_API_KEY.Basescan),
13087
13082
  };
13088
-
13089
13083
  const apiKey = API_KEYS[chain];
13090
- const baseUrl = CHAIN_API_BASE[chain];
13091
-
13092
- const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13093
- const endBlock = await fromTimeStampToBlock(endTime);
13084
+ const chainId = CHAIN_ID_MAP[chain];
13085
+ if (!apiKey || !chainId) return `${chain.toUpperCase()}_MISSING`;
13094
13086
 
13095
13087
  let action = '';
13096
- if (categories === 'txns') action = 'txlist';
13097
- else if (categories === 'balances') action = 'balance';
13098
- else if (categories === 'portfolio') action = 'tokentx';
13099
-
13100
- let url = `${baseUrl}?module=account&action=${action}&address=${address}&startblock=${startBlock}&endblock=${endBlock}&sort=asc&apikey=${apiKey}`;
13101
-
13088
+ if (categories === 'txns') action = 'account.txlist';
13089
+ else {action = 'account.balance';} let timeQuery = '';
13090
+ if(!isNaN(startTime) && !isNaN(endTime)){
13091
+ const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13092
+ const endBlock = await fromTimeStampToBlock(endTime, chain, apiKey);
13093
+ timeQuery = `&startblock=${startBlock}&endblock=${endBlock}`;
13094
+ } else if(categories === 'balance') {
13095
+ timeQuery = `&tag=latest`;
13096
+ } else {
13097
+ throw new Error('Start and End Time is required for querying transaction list ')
13098
+ }
13099
+ const url = `https://api.etherscan.io/v2/api?module=${action.split('.')[0]}&action=${action.split('.')[1]}&address=${address}&sort=asc&chainid=${chainId}&apikey=${apiKey}${timeQuery}`;
13102
13100
  try {
13103
13101
  const response = await fetch(url);
13104
13102
  if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formulajs",
3
- "version": "4.4.11-mod-15-patch-2",
3
+ "version": "4.4.11-mod-16",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {