@covalenthq/client-sdk 2.1.0 → 2.1.2

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/README.md CHANGED
@@ -251,7 +251,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
251
251
 
252
252
  <details>
253
253
  <summary>
254
- 3. <strong>Balance Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
254
+ 3. <strong>Base Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
255
255
  </summary>
256
256
 
257
257
  - `getBlock()`: Fetch and render a single block for a block explorer.
@@ -3,6 +3,7 @@ export { bigIntParser } from "./src/utils/functions/bigIntParser";
3
3
  export { calculatePrettyBalance } from "./src/utils/functions/calculatePrettyBalance";
4
4
  export { isValidApiKey } from "./src/utils/functions/isValidApiKey";
5
5
  export { prettifyCurrency } from "./src/utils/functions/prettifyCurrency";
6
+ export { timestampParser } from "./src/utils/functions/timestamp-parser";
6
7
  export * from "./src/utils/types/BalanceService.types";
7
8
  export * from "./src/utils/types/BaseService.types";
8
9
  export * from "./src/utils/types/Generic.types";
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var version = "2.1.0";
3
+ var version = "2.1.2";
4
4
 
5
5
  const bigIntParser = (val) => {
6
6
  if (val === null || val === undefined) {
@@ -178,8 +178,8 @@ class BalanceService {
178
178
  ...portfolioItem,
179
179
  holdings: portfolioItem.holdings?.map((holdingItem) => ({
180
180
  ...holdingItem,
181
- timestamp: holdingItem.timestamp && data.data?.updated_at
182
- ? new Date(data.data.updated_at)
181
+ timestamp: holdingItem.timestamp
182
+ ? new Date(holdingItem.timestamp)
183
183
  : null,
184
184
  close: {
185
185
  ...holdingItem.close,
@@ -1732,9 +1732,6 @@ class TransactionService {
1732
1732
  * @param {GetTransactionQueryParamOpts} queryParamOpts
1733
1733
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1734
1734
  * - `noLogs`: Omit log events.
1735
- * - `withDex`: Decoded DEX details including protocol (e.g. Uniswap), event (e.g 'add_liquidity') and tokens involved with historical prices. Additional 0.05 credits charged if data available.
1736
- * - `withNftSales`: Decoded NFT sales details including marketplace (e.g. Opensea) and cached media links. Additional 0.05 credits charged if data available.
1737
- * - `withLending`: Decoded lending details including protocol (e.g. Aave), event (e.g. 'deposit') and tokens involved with prices. Additional 0.05 credits charged if data available.
1738
1735
  * - `withSafe`: Include safe details.
1739
1736
  *
1740
1737
  */
@@ -1748,18 +1745,6 @@ class TransactionService {
1748
1745
  key: "no-logs",
1749
1746
  value: queryParamOpts?.noLogs,
1750
1747
  },
1751
- {
1752
- key: "with-dex",
1753
- value: queryParamOpts?.withDex,
1754
- },
1755
- {
1756
- key: "with-nft-sales",
1757
- value: queryParamOpts?.withNftSales,
1758
- },
1759
- {
1760
- key: "with-lending",
1761
- value: queryParamOpts?.withLending,
1762
- },
1763
1748
  ]);
1764
1749
  const parseData = (data) => {
1765
1750
  if (data.data) {
@@ -2459,7 +2444,7 @@ class Execution {
2459
2444
  const parsedData = parseData(data);
2460
2445
  completed = true;
2461
2446
  return {
2462
- data: parsedData.data ?? null,
2447
+ data: parsedData.data,
2463
2448
  error: false,
2464
2449
  error_code: null,
2465
2450
  error_message: null,
@@ -3637,6 +3622,86 @@ const prettifyCurrency = (value, decimals = 2, currency = "USD", ignoreSmallValu
3637
3622
  return minus + formattedValue + currencySuffix;
3638
3623
  };
3639
3624
 
3625
+ const months = [
3626
+ "January",
3627
+ "February",
3628
+ "March",
3629
+ "April",
3630
+ "May",
3631
+ "June",
3632
+ "July",
3633
+ "August",
3634
+ "September",
3635
+ "October",
3636
+ "November",
3637
+ "December",
3638
+ ];
3639
+ const timestampParser = (timestamp, type) => {
3640
+ const _unix = new Date(timestamp);
3641
+ switch (type) {
3642
+ case "descriptive": {
3643
+ const _minutes = _unix.getMinutes();
3644
+ const _hours = _unix.getHours();
3645
+ const _seconds = _unix.getSeconds();
3646
+ const _parsedSeconds = `${_seconds <= 9 ? "0" : ""}${_seconds}`;
3647
+ const _parsedMinutes = `${_minutes <= 9 ? "0" : ""}${_minutes}`;
3648
+ const _parsedHours = `${_hours <= 9 ? "0" : ""}${_hours}`;
3649
+ return `${months[_unix.getMonth()]} ${_unix.getDate()} ${_unix.getFullYear()} at ${_parsedHours}:${_parsedMinutes}:${_parsedSeconds}`;
3650
+ }
3651
+ case "DD MMM YY": {
3652
+ const day = _unix.getDate().toString().padStart(2, "0");
3653
+ const month = months[_unix.getMonth()].substring(0, 3);
3654
+ const year = _unix.getFullYear();
3655
+ return `${day} ${month} ${year}`;
3656
+ }
3657
+ case "relative": {
3658
+ const currentTime = new Date();
3659
+ const unixTime = new Date(_unix);
3660
+ const timeDifference = currentTime.getTime() - unixTime.getTime();
3661
+ const secondsDifference = Math.floor(timeDifference / 1000);
3662
+ const minutesDifference = Math.floor(secondsDifference / 60);
3663
+ const hoursDifference = Math.floor(minutesDifference / 60);
3664
+ const daysDifference = Math.floor(hoursDifference / 24);
3665
+ const monthsDifference = Math.floor(daysDifference / 30);
3666
+ const yearsDifference = Math.floor(daysDifference / 365);
3667
+ if (yearsDifference > 0) {
3668
+ return `${yearsDifference} year${yearsDifference > 1 ? "s" : ""} ago`;
3669
+ }
3670
+ else if (monthsDifference > 0) {
3671
+ return `${monthsDifference} month${monthsDifference > 1 ? "s" : ""} ago`;
3672
+ }
3673
+ else if (daysDifference > 0) {
3674
+ return `${daysDifference} day${daysDifference > 1 ? "s" : ""} ago`;
3675
+ }
3676
+ else if (hoursDifference > 0) {
3677
+ return `${hoursDifference} hour${hoursDifference > 1 ? "s" : ""} ago`;
3678
+ }
3679
+ else if (minutesDifference > 0) {
3680
+ return `${minutesDifference} minute${minutesDifference > 1 ? "s" : ""} ago`;
3681
+ }
3682
+ else if (secondsDifference > 0) {
3683
+ return `${secondsDifference} second${secondsDifference > 1 ? "s" : ""} ago`;
3684
+ }
3685
+ else {
3686
+ return `just now`;
3687
+ }
3688
+ }
3689
+ case "YYYY MM DD": {
3690
+ const offsetMinutes = _unix.getTimezoneOffset();
3691
+ const offsetMilliseconds = offsetMinutes * 60 * 1000;
3692
+ const utcTime = _unix.getTime() + offsetMilliseconds;
3693
+ const _utc_unix = new Date(utcTime);
3694
+ const year = _utc_unix.getFullYear();
3695
+ const month = String(_utc_unix.getMonth() + 1).padStart(2, "0");
3696
+ const day = String(_utc_unix.getDate()).padStart(2, "0");
3697
+ return `${year}-${month}-${day}`;
3698
+ }
3699
+ default: {
3700
+ return _unix.toISOString();
3701
+ }
3702
+ }
3703
+ };
3704
+
3640
3705
  exports.ChainName = void 0;
3641
3706
  (function (ChainName) {
3642
3707
  ChainName["ETH_MAINNET"] = "eth-mainnet";
@@ -3977,4 +4042,5 @@ exports.bigIntParser = bigIntParser;
3977
4042
  exports.calculatePrettyBalance = calculatePrettyBalance;
3978
4043
  exports.isValidApiKey = isValidApiKey;
3979
4044
  exports.prettifyCurrency = prettifyCurrency;
4045
+ exports.timestampParser = timestampParser;
3980
4046
  //# sourceMappingURL=index.js.map