@covalenthq/client-sdk 0.6.4 → 0.6.5

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.4";
24
+ export declare const userAgent = "com.covalenthq.sdk.typescript/0.6.5";
25
25
  export declare class Response<T> {
26
26
  data: T;
27
27
  error: boolean;
@@ -0,0 +1,2 @@
1
+ import { Quote } from "../services/CovalentClient";
2
+ export declare const prettifyCurrency: (value: any, decimals?: number, currency?: Quote, ignoreSmallValue?: boolean, ignoreMinus?: boolean, ignoreZero?: boolean) => string;
package/dist/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from "./util/types/XykServiceTypes";
8
8
  export * from "./util/types/GenericTypes";
9
9
  export * from "./util/types/TransactionServiceTypes";
10
10
  export { calculatePrettyBalance } from "./util/CalculatePrettyBalance";
11
+ export { prettifyCurrency } from "./util/prettifyCurrency";
package/dist/index.js CHANGED
@@ -8,4 +8,5 @@ export * from "./util/types/XykServiceTypes";
8
8
  export * from "./util/types/GenericTypes";
9
9
  export * from "./util/types/TransactionServiceTypes";
10
10
  export { calculatePrettyBalance } from "./util/CalculatePrettyBalance";
11
+ export { prettifyCurrency } from "./util/prettifyCurrency";
11
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAwD,MAAM,2BAA2B,CAAC;AACzH,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAwD,MAAM,2BAA2B,CAAC;AACzH,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -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.4";
24
+ export declare const userAgent = "com.covalenthq.sdk.typescript/0.6.5";
25
25
  export declare class Response<T> {
26
26
  data: T;
27
27
  error: boolean;
@@ -5,7 +5,7 @@ import { NftService } from "./NftService";
5
5
  import { PricingService } from "./PricingService";
6
6
  import { TransactionService } from "./TransactionService";
7
7
  import { XykService } from "./XykService";
8
- export const userAgent = "com.covalenthq.sdk.typescript/0.6.4";
8
+ export const userAgent = "com.covalenthq.sdk.typescript/0.6.5";
9
9
  export class Response {
10
10
  }
11
11
  /**
@@ -0,0 +1,2 @@
1
+ import { Quote } from "../services/CovalentClient";
2
+ export declare const prettifyCurrency: (value: any, decimals?: number, currency?: Quote, ignoreSmallValue?: boolean, ignoreMinus?: boolean, ignoreZero?: boolean) => string;
@@ -0,0 +1,69 @@
1
+ const LESS_THAN_ZERO = "0.01";
2
+ const ZERO = "0.00";
3
+ const currencyMap = new Map([
4
+ ["USD", "$"],
5
+ ["CAD", "CA$"],
6
+ ["EUR", "€"],
7
+ ["SGD", "S$"],
8
+ ["INR", "₹"],
9
+ ["JPY", "¥"],
10
+ ["VND", "₫"],
11
+ ["CNY", "CN¥"],
12
+ ["KRW", "₩"],
13
+ ["RUB", "₽"],
14
+ ["TRY", "₺"],
15
+ ["NGN", "₦"],
16
+ ["ARS", "ARS"],
17
+ ["AUD", "A$"],
18
+ ["CHF", "CHF"],
19
+ ["GBP", "£"],
20
+ ]);
21
+ export const prettifyCurrency = (value, decimals = 2, currency = "USD", ignoreSmallValue = false, ignoreMinus = true, ignoreZero = false) => {
22
+ if (typeof value === "string") {
23
+ value = Number(value);
24
+ }
25
+ let minus = "";
26
+ let currencySuffix = "";
27
+ // pass ignoreMinus false to get the negative number for currency formatter
28
+ if (!ignoreMinus && value < 0) {
29
+ value = Math.abs(value);
30
+ minus = "-";
31
+ }
32
+ if (value === 0 || !value) {
33
+ // if value is 0, pass ignoreZero true to get this string "<$0.01"
34
+ if (ignoreZero) {
35
+ return "<" + currencyMap.get(currency) + LESS_THAN_ZERO;
36
+ }
37
+ else {
38
+ return currencyMap.get(currency) + ZERO;
39
+ }
40
+ }
41
+ else if (value < 0 || value < 1) {
42
+ if (value < 0.01 && ignoreSmallValue) {
43
+ return "<" + currencyMap.get(currency) + LESS_THAN_ZERO;
44
+ }
45
+ }
46
+ else if (value > 999999999) {
47
+ value = value / 1000000000;
48
+ currencySuffix = "B";
49
+ }
50
+ else if (value > 999999) {
51
+ value = value / 1000000; // convert to M for number from > 1 million
52
+ currencySuffix = "M";
53
+ }
54
+ // Added to round down the number
55
+ const expo = Math.pow(10, decimals);
56
+ value = Math.floor(value * expo) / expo;
57
+ // generates the value with the inputted currency
58
+ const formatter = new Intl.NumberFormat('en-US', {
59
+ style: 'currency',
60
+ currency: currency,
61
+ maximumFractionDigits: decimals,
62
+ currencyDisplay: "symbol"
63
+ });
64
+ //replace the occasional incorrect currency symbol from the formatter and replace with correct symbol from currencyMap
65
+ const regex = new RegExp(`${currency}\\s?`);
66
+ const _val = formatter.format(value).replace(regex, currencyMap.get(currency) ?? "$");
67
+ return minus + _val + currencySuffix;
68
+ };
69
+ //# sourceMappingURL=prettifyCurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prettifyCurrency.js","sourceRoot":"","sources":["../../src/util/prettifyCurrency.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,IAAI,GAAG,MAAM,CAAC;AAEpB,MAAM,WAAW,GAAG,IAAI,GAAG,CAAiB;IACxC,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,IAAI,CAAC;IACb,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,KAAK,EAAE,IAAI,CAAC;IACb,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,KAAK,EAAE,GAAG,CAAC;CACb,CAAC,CAAC;AAEL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