@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.
- package/README.md +10 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +71 -1
- 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 +71 -2
- 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 +71 -2
- 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/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/es/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/es/index.js
CHANGED
|
@@ -6246,7 +6246,7 @@ class XykService {
|
|
|
6246
6246
|
}
|
|
6247
6247
|
}
|
|
6248
6248
|
|
|
6249
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.6.
|
|
6249
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.6.5";
|
|
6250
6250
|
/**
|
|
6251
6251
|
* CovalentClient Class
|
|
6252
6252
|
*/
|
|
@@ -6309,5 +6309,74 @@ const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision
|
|
|
6309
6309
|
return _calculated.toFixed(_decimalFixed);
|
|
6310
6310
|
};
|
|
6311
6311
|
|
|
6312
|
-
|
|
6312
|
+
const LESS_THAN_ZERO = "0.01";
|
|
6313
|
+
const ZERO = "0.00";
|
|
6314
|
+
const currencyMap = new Map([
|
|
6315
|
+
["USD", "$"],
|
|
6316
|
+
["CAD", "CA$"],
|
|
6317
|
+
["EUR", "€"],
|
|
6318
|
+
["SGD", "S$"],
|
|
6319
|
+
["INR", "₹"],
|
|
6320
|
+
["JPY", "¥"],
|
|
6321
|
+
["VND", "₫"],
|
|
6322
|
+
["CNY", "CN¥"],
|
|
6323
|
+
["KRW", "₩"],
|
|
6324
|
+
["RUB", "₽"],
|
|
6325
|
+
["TRY", "₺"],
|
|
6326
|
+
["NGN", "₦"],
|
|
6327
|
+
["ARS", "ARS"],
|
|
6328
|
+
["AUD", "A$"],
|
|
6329
|
+
["CHF", "CHF"],
|
|
6330
|
+
["GBP", "£"],
|
|
6331
|
+
]);
|
|
6332
|
+
const prettifyCurrency = (value, decimals = 2, currency = "USD", ignoreSmallValue = false, ignoreMinus = true, ignoreZero = false) => {
|
|
6333
|
+
if (typeof value === "string") {
|
|
6334
|
+
value = Number(value);
|
|
6335
|
+
}
|
|
6336
|
+
let minus = "";
|
|
6337
|
+
let currencySuffix = "";
|
|
6338
|
+
// pass ignoreMinus false to get the negative number for currency formatter
|
|
6339
|
+
if (!ignoreMinus && value < 0) {
|
|
6340
|
+
value = Math.abs(value);
|
|
6341
|
+
minus = "-";
|
|
6342
|
+
}
|
|
6343
|
+
if (value === 0 || !value) {
|
|
6344
|
+
// if value is 0, pass ignoreZero true to get this string "<$0.01"
|
|
6345
|
+
if (ignoreZero) {
|
|
6346
|
+
return "<" + currencyMap.get(currency) + LESS_THAN_ZERO;
|
|
6347
|
+
}
|
|
6348
|
+
else {
|
|
6349
|
+
return currencyMap.get(currency) + ZERO;
|
|
6350
|
+
}
|
|
6351
|
+
}
|
|
6352
|
+
else if (value < 0 || value < 1) {
|
|
6353
|
+
if (value < 0.01 && ignoreSmallValue) {
|
|
6354
|
+
return "<" + currencyMap.get(currency) + LESS_THAN_ZERO;
|
|
6355
|
+
}
|
|
6356
|
+
}
|
|
6357
|
+
else if (value > 999999999) {
|
|
6358
|
+
value = value / 1000000000;
|
|
6359
|
+
currencySuffix = "B";
|
|
6360
|
+
}
|
|
6361
|
+
else if (value > 999999) {
|
|
6362
|
+
value = value / 1000000; // convert to M for number from > 1 million
|
|
6363
|
+
currencySuffix = "M";
|
|
6364
|
+
}
|
|
6365
|
+
// Added to round down the number
|
|
6366
|
+
const expo = Math.pow(10, decimals);
|
|
6367
|
+
value = Math.floor(value * expo) / expo;
|
|
6368
|
+
// generates the value with the inputted currency
|
|
6369
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
6370
|
+
style: 'currency',
|
|
6371
|
+
currency: currency,
|
|
6372
|
+
maximumFractionDigits: decimals,
|
|
6373
|
+
currencyDisplay: "symbol"
|
|
6374
|
+
});
|
|
6375
|
+
//replace the occasional incorrect currency symbol from the formatter and replace with correct symbol from currencyMap
|
|
6376
|
+
const regex = new RegExp(`${currency}\\s?`);
|
|
6377
|
+
const _val = formatter.format(value).replace(regex, currencyMap.get(currency) ?? "$");
|
|
6378
|
+
return minus + _val + currencySuffix;
|
|
6379
|
+
};
|
|
6380
|
+
|
|
6381
|
+
export { Client, CovalentClient, calculatePrettyBalance, prettifyCurrency };
|
|
6313
6382
|
//# sourceMappingURL=index.js.map
|