@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.
@@ -17,9 +17,6 @@ export declare class TransactionService {
17
17
  * @param {GetTransactionQueryParamOpts} queryParamOpts
18
18
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
19
19
  * - `noLogs`: Omit log events.
20
- * - `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.
21
- * - `withNftSales`: Decoded NFT sales details including marketplace (e.g. Opensea) and cached media links. Additional 0.05 credits charged if data available.
22
- * - `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.
23
20
  * - `withSafe`: Include safe details.
24
21
  *
25
22
  */
@@ -64,7 +61,7 @@ export declare class TransactionService {
64
61
  * - `withSafe`: Include safe details.
65
62
  *
66
63
  */
67
- getTransactionsForBlock(chainName: Chain, blockHeight: number | string, queryParamOpts?: GetTransactionsForBlockQueryParamOpts): Promise<GoldRushResponse<TransactionsBlockResponse>>;
64
+ getTransactionsForBlock(chainName: Chain, blockHeight: number | string | "latest", queryParamOpts?: GetTransactionsForBlockQueryParamOpts): Promise<GoldRushResponse<TransactionsBlockResponse>>;
68
65
  /**
69
66
  *
70
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;
@@ -455,12 +455,17 @@ export interface LogoUrls {
455
455
  /** * The chain logo URL. */
456
456
  chain_logo_url: string;
457
457
  }
458
- export type GoldRushResponse<T> = Nullable<{
458
+ export type GoldRushResponse<T> = {
459
459
  data: T;
460
- error: boolean;
461
- error_code: number | string;
460
+ error: false | null;
461
+ error_code: null;
462
+ error_message: null;
463
+ } | {
464
+ data: null;
465
+ error: true;
466
+ error_code: number;
462
467
  error_message: string;
463
- }>;
468
+ };
464
469
  export interface GoldRushClientSettings {
465
470
  /** * Toggle to analyze the execution of each api request. */
466
471
  debug?: boolean;
@@ -405,12 +405,6 @@ export type GetTransactionQueryParamOpts = Nullable<{
405
405
  quoteCurrency?: Quote;
406
406
  /** * Omit log events. */
407
407
  noLogs?: boolean;
408
- /** * 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. */
409
- withDex?: boolean;
410
- /** * Decoded NFT sales details including marketplace (e.g. Opensea) and cached media links. Additional 0.05 credits charged if data available. */
411
- withNftSales?: boolean;
412
- /** * 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. */
413
- withLending?: boolean;
414
408
  /** * Include safe details. */
415
409
  withSafe?: boolean;
416
410
  }>;
@@ -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.0";
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,
@@ -1730,9 +1730,6 @@ class TransactionService {
1730
1730
  * @param {GetTransactionQueryParamOpts} queryParamOpts
1731
1731
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1732
1732
  * - `noLogs`: Omit log events.
1733
- * - `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.
1734
- * - `withNftSales`: Decoded NFT sales details including marketplace (e.g. Opensea) and cached media links. Additional 0.05 credits charged if data available.
1735
- * - `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.
1736
1733
  * - `withSafe`: Include safe details.
1737
1734
  *
1738
1735
  */
@@ -1746,18 +1743,6 @@ class TransactionService {
1746
1743
  key: "no-logs",
1747
1744
  value: queryParamOpts?.noLogs,
1748
1745
  },
1749
- {
1750
- key: "with-dex",
1751
- value: queryParamOpts?.withDex,
1752
- },
1753
- {
1754
- key: "with-nft-sales",
1755
- value: queryParamOpts?.withNftSales,
1756
- },
1757
- {
1758
- key: "with-lending",
1759
- value: queryParamOpts?.withLending,
1760
- },
1761
1746
  ]);
1762
1747
  const parseData = (data) => {
1763
1748
  if (data.data) {
@@ -2457,7 +2442,7 @@ class Execution {
2457
2442
  const parsedData = parseData(data);
2458
2443
  completed = true;
2459
2444
  return {
2460
- data: parsedData.data ?? null,
2445
+ data: parsedData.data,
2461
2446
  error: false,
2462
2447
  error_code: null,
2463
2448
  error_message: null,
@@ -3635,6 +3620,86 @@ const prettifyCurrency = (value, decimals = 2, currency = "USD", ignoreSmallValu
3635
3620
  return minus + formattedValue + currencySuffix;
3636
3621
  };
3637
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
+
3638
3703
  var ChainName;
3639
3704
  (function (ChainName) {
3640
3705
  ChainName["ETH_MAINNET"] = "eth-mainnet";
@@ -3970,5 +4035,5 @@ var ChainID;
3970
4035
  ChainID[ChainID["COVALENT_INTERNAL_NETWORK_V1"] = 1131378225] = "COVALENT_INTERNAL_NETWORK_V1";
3971
4036
  })(ChainID || (ChainID = {}));
3972
4037
 
3973
- export { ChainID, ChainName, GoldRushClient, bigIntParser, calculatePrettyBalance, isValidApiKey, prettifyCurrency };
4038
+ export { ChainID, ChainName, GoldRushClient, bigIntParser, calculatePrettyBalance, isValidApiKey, prettifyCurrency, timestampParser };
3974
4039
  //# sourceMappingURL=index.js.map