@covalenthq/client-sdk 2.1.1 → 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.1";
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,
@@ -3622,6 +3622,86 @@ const prettifyCurrency = (value, decimals = 2, currency = "USD", ignoreSmallValu
3622
3622
  return minus + formattedValue + currencySuffix;
3623
3623
  };
3624
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
+
3625
3705
  exports.ChainName = void 0;
3626
3706
  (function (ChainName) {
3627
3707
  ChainName["ETH_MAINNET"] = "eth-mainnet";
@@ -3962,4 +4042,5 @@ exports.bigIntParser = bigIntParser;
3962
4042
  exports.calculatePrettyBalance = calculatePrettyBalance;
3963
4043
  exports.isValidApiKey = isValidApiKey;
3964
4044
  exports.prettifyCurrency = prettifyCurrency;
4045
+ exports.timestampParser = timestampParser;
3965
4046
  //# sourceMappingURL=index.js.map