@covalenthq/client-sdk 0.6.1 → 0.6.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.
@@ -21,7 +21,7 @@ export type Chains = "btc-mainnet" | "eth-mainnet" | "matic-mainnet" | "bsc-main
21
21
  * CovalentClient Class
22
22
  */
23
23
  export type Quotes = "USD" | "CAD" | "EUR" | "SGD" | "INR" | "JPY" | "VND" | "CNY" | "KRW" | "RUB" | "TRY" | "NGN" | "ARS" | "AUD" | "CHF" | "GBP";
24
- export declare const userAgent = "com.covalenthq.sdk.typescript/0.6.1";
24
+ export declare const userAgent = "com.covalenthq.sdk.typescript/0.6.2";
25
25
  export declare class Response<T> {
26
26
  data: T;
27
27
  error: boolean;
@@ -0,0 +1 @@
1
+ export declare const calculatePrettyBalance: (value: number | bigint, decimals?: number, roundOff?: boolean, precision?: number) => string;
@@ -7,3 +7,4 @@ export * from "./util/types/SecurityServiceTypes";
7
7
  export * from "./util/types/XykServiceTypes";
8
8
  export * from "./util/types/GenericTypes";
9
9
  export * from "./util/types/TransactionServiceTypes";
10
+ export { calculatePrettyBalance } from "./util/CalculatePrettyBalance";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import { parseISO } from 'date-fns';
3
+ import Big from 'big.js';
3
4
 
4
5
  const DEFAULT_BACKOFF_MAX_RETRIES = 5;
5
6
  const BASE_DELAY_MS = 1000; // Base delay in milliseconds
@@ -5865,7 +5866,7 @@ class XykService {
5865
5866
  }
5866
5867
  }
5867
5868
 
5868
- const userAgent = "com.covalenthq.sdk.typescript/0.6.1";
5869
+ const userAgent = "com.covalenthq.sdk.typescript/0.6.2";
5869
5870
  /**
5870
5871
  * CovalentClient Class
5871
5872
  */
@@ -5900,5 +5901,26 @@ class Client {
5900
5901
  }
5901
5902
  }
5902
5903
 
5903
- export { Client, CovalentClient };
5904
+ const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision = 0) => {
5905
+ const bigIntValue = BigInt(value);
5906
+ const bigDecimalValue = new Big(bigIntValue.toString());
5907
+ const _decimals = decimals || 18;
5908
+ const _expoValue = BigInt(Math.pow(10, _decimals));
5909
+ const bigDecimalExpo = new Big(_expoValue.toString());
5910
+ const _calculated = bigDecimalValue.div(bigDecimalExpo);
5911
+ // removes the decimal places, true by default so it adds decimals
5912
+ if (!roundOff) {
5913
+ return _calculated.toString();
5914
+ }
5915
+ let _decimalFixed = precision;
5916
+ if (precision === 0) {
5917
+ _decimalFixed = 2;
5918
+ if (_calculated.lt(100)) {
5919
+ _decimalFixed = 6;
5920
+ }
5921
+ }
5922
+ return _calculated.toFixed(_decimalFixed);
5923
+ };
5924
+
5925
+ export { Client, CovalentClient, calculatePrettyBalance };
5904
5926
  //# sourceMappingURL=index.js.map