@covalenthq/client-sdk 0.6.3 → 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.
- package/README.md +10 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +80 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/CovalentClient.d.ts +1 -1
- package/dist/cjs/util/prettifyCurrency.d.ts +2 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +80 -4
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/CovalentClient.d.ts +1 -1
- package/dist/es/util/prettifyCurrency.d.ts +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +80 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/CovalentClient.d.ts +1 -1
- package/dist/esm/util/prettifyCurrency.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +1 -1
- package/dist/services/CovalentClient.js +1 -1
- package/dist/util/CalculatePrettyBalance.js +9 -2
- package/dist/util/CalculatePrettyBalance.js.map +1 -1
- package/dist/util/prettifyCurrency.d.ts +2 -0
- package/dist/util/prettifyCurrency.js +69 -0
- package/dist/util/prettifyCurrency.js.map +1 -0
- package/package.json +1 -1
|
@@ -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.
|
|
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;
|
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.
|
|
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.
|
|
8
|
+
export const userAgent = "com.covalenthq.sdk.typescript/0.6.5";
|
|
9
9
|
export class Response {
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
export const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision = 0) => {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
let bigIntValue;
|
|
4
|
+
let bigDecimalValue;
|
|
5
|
+
try {
|
|
6
|
+
bigIntValue = BigInt(value);
|
|
7
|
+
bigDecimalValue = new Big(bigIntValue.toString());
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
bigDecimalValue = new Big(value.toString());
|
|
11
|
+
}
|
|
5
12
|
const _decimals = decimals || 18;
|
|
6
13
|
const _expoValue = BigInt(Math.pow(10, _decimals));
|
|
7
14
|
const bigDecimalExpo = new Big(_expoValue.toString());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalculatePrettyBalance.js","sourceRoot":"","sources":["../../src/util/CalculatePrettyBalance.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAC;AAEzB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAClC,KAAsB,EACtB,WAAmB,EAAE,EACrB,WAAoB,IAAI,EACxB,YAAoB,CAAC,EACf,EAAE;IACR,
|
|
1
|
+
{"version":3,"file":"CalculatePrettyBalance.js","sourceRoot":"","sources":["../../src/util/CalculatePrettyBalance.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAC;AAEzB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAClC,KAAsB,EACtB,WAAmB,EAAE,EACrB,WAAoB,IAAI,EACxB,YAAoB,CAAC,EACf,EAAE;IACR,IAAI,WAAmB,CAAC;IACxB,IAAI,eAAe,CAAC;IACpB,IAAI;QACA,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,eAAe,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC;KACrD;IAAC,OAAO,KAAK,EAAE;QACZ,eAAe,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;KAC/C;IAED,MAAM,SAAS,GAAW,QAAQ,IAAI,EAAE,CAAC;IACzC,MAAM,UAAU,GAAW,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAC3D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAExD,kEAAkE;IAClE,IAAI,CAAC,QAAQ,EAAE;QACX,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC;KACjC;IACD,IAAI,aAAa,GAAG,SAAS,CAAC;IAC9B,IAAI,SAAS,KAAK,CAAC,EAAE;QACjB,aAAa,GAAG,CAAC,CAAC;QAClB,IAAI,WAAW,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE;YACrB,aAAa,GAAG,CAAC,CAAC;SACrB;KACJ;IACD,OAAO,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AAC9C,CAAC,CAAC"}
|
|
@@ -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,c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