@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.
@@ -61,7 +61,7 @@ export declare class TransactionService {
61
61
  * - `withSafe`: Include safe details.
62
62
  *
63
63
  */
64
- getTransactionsForBlock(chainName: Chain, blockHeight: number | string, queryParamOpts?: GetTransactionsForBlockQueryParamOpts): Promise<GoldRushResponse<TransactionsBlockResponse>>;
64
+ getTransactionsForBlock(chainName: Chain, blockHeight: number | string | "latest", queryParamOpts?: GetTransactionsForBlockQueryParamOpts): Promise<GoldRushResponse<TransactionsBlockResponse>>;
65
65
  /**
66
66
  *
67
67
  * Commonly used to fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
@@ -0,0 +1 @@
1
+ export declare const timestampParser: (timestamp: string | Date, type: "descriptive" | "DD MMM YY" | "relative" | "YYYY MM DD") => string;
@@ -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/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "2.1.1";
1
+ var version = "2.1.2";
2
2
 
3
3
  const bigIntParser = (val) => {
4
4
  if (val === null || val === undefined) {
@@ -176,8 +176,8 @@ class BalanceService {
176
176
  ...portfolioItem,
177
177
  holdings: portfolioItem.holdings?.map((holdingItem) => ({
178
178
  ...holdingItem,
179
- timestamp: holdingItem.timestamp && data.data?.updated_at
180
- ? new Date(data.data.updated_at)
179
+ timestamp: holdingItem.timestamp
180
+ ? new Date(holdingItem.timestamp)
181
181
  : null,
182
182
  close: {
183
183
  ...holdingItem.close,
@@ -3620,6 +3620,86 @@ const prettifyCurrency = (value, decimals = 2, currency = "USD", ignoreSmallValu
3620
3620
  return minus + formattedValue + currencySuffix;
3621
3621
  };
3622
3622
 
3623
+ const months = [
3624
+ "January",
3625
+ "February",
3626
+ "March",
3627
+ "April",
3628
+ "May",
3629
+ "June",
3630
+ "July",
3631
+ "August",
3632
+ "September",
3633
+ "October",
3634
+ "November",
3635
+ "December",
3636
+ ];
3637
+ const timestampParser = (timestamp, type) => {
3638
+ const _unix = new Date(timestamp);
3639
+ switch (type) {
3640
+ case "descriptive": {
3641
+ const _minutes = _unix.getMinutes();
3642
+ const _hours = _unix.getHours();
3643
+ const _seconds = _unix.getSeconds();
3644
+ const _parsedSeconds = `${_seconds <= 9 ? "0" : ""}${_seconds}`;
3645
+ const _parsedMinutes = `${_minutes <= 9 ? "0" : ""}${_minutes}`;
3646
+ const _parsedHours = `${_hours <= 9 ? "0" : ""}${_hours}`;
3647
+ return `${months[_unix.getMonth()]} ${_unix.getDate()} ${_unix.getFullYear()} at ${_parsedHours}:${_parsedMinutes}:${_parsedSeconds}`;
3648
+ }
3649
+ case "DD MMM YY": {
3650
+ const day = _unix.getDate().toString().padStart(2, "0");
3651
+ const month = months[_unix.getMonth()].substring(0, 3);
3652
+ const year = _unix.getFullYear();
3653
+ return `${day} ${month} ${year}`;
3654
+ }
3655
+ case "relative": {
3656
+ const currentTime = new Date();
3657
+ const unixTime = new Date(_unix);
3658
+ const timeDifference = currentTime.getTime() - unixTime.getTime();
3659
+ const secondsDifference = Math.floor(timeDifference / 1000);
3660
+ const minutesDifference = Math.floor(secondsDifference / 60);
3661
+ const hoursDifference = Math.floor(minutesDifference / 60);
3662
+ const daysDifference = Math.floor(hoursDifference / 24);
3663
+ const monthsDifference = Math.floor(daysDifference / 30);
3664
+ const yearsDifference = Math.floor(daysDifference / 365);
3665
+ if (yearsDifference > 0) {
3666
+ return `${yearsDifference} year${yearsDifference > 1 ? "s" : ""} ago`;
3667
+ }
3668
+ else if (monthsDifference > 0) {
3669
+ return `${monthsDifference} month${monthsDifference > 1 ? "s" : ""} ago`;
3670
+ }
3671
+ else if (daysDifference > 0) {
3672
+ return `${daysDifference} day${daysDifference > 1 ? "s" : ""} ago`;
3673
+ }
3674
+ else if (hoursDifference > 0) {
3675
+ return `${hoursDifference} hour${hoursDifference > 1 ? "s" : ""} ago`;
3676
+ }
3677
+ else if (minutesDifference > 0) {
3678
+ return `${minutesDifference} minute${minutesDifference > 1 ? "s" : ""} ago`;
3679
+ }
3680
+ else if (secondsDifference > 0) {
3681
+ return `${secondsDifference} second${secondsDifference > 1 ? "s" : ""} ago`;
3682
+ }
3683
+ else {
3684
+ return `just now`;
3685
+ }
3686
+ }
3687
+ case "YYYY MM DD": {
3688
+ const offsetMinutes = _unix.getTimezoneOffset();
3689
+ const offsetMilliseconds = offsetMinutes * 60 * 1000;
3690
+ const utcTime = _unix.getTime() + offsetMilliseconds;
3691
+ const _utc_unix = new Date(utcTime);
3692
+ const year = _utc_unix.getFullYear();
3693
+ const month = String(_utc_unix.getMonth() + 1).padStart(2, "0");
3694
+ const day = String(_utc_unix.getDate()).padStart(2, "0");
3695
+ return `${year}-${month}-${day}`;
3696
+ }
3697
+ default: {
3698
+ return _unix.toISOString();
3699
+ }
3700
+ }
3701
+ };
3702
+
3623
3703
  var ChainName;
3624
3704
  (function (ChainName) {
3625
3705
  ChainName["ETH_MAINNET"] = "eth-mainnet";
@@ -3955,5 +4035,5 @@ var ChainID;
3955
4035
  ChainID[ChainID["COVALENT_INTERNAL_NETWORK_V1"] = 1131378225] = "COVALENT_INTERNAL_NETWORK_V1";
3956
4036
  })(ChainID || (ChainID = {}));
3957
4037
 
3958
- export { ChainID, ChainName, GoldRushClient, bigIntParser, calculatePrettyBalance, isValidApiKey, prettifyCurrency };
4038
+ export { ChainID, ChainName, GoldRushClient, bigIntParser, calculatePrettyBalance, isValidApiKey, prettifyCurrency, timestampParser };
3959
4039
  //# sourceMappingURL=index.js.map