@covalenthq/client-sdk 0.6.4 → 0.6.6
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 +72 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +2 -2
- package/dist/cjs/services/CovalentClient.d.ts +1 -1
- package/dist/cjs/util/prettifyCurrency.d.ts +2 -0
- package/dist/cjs/util/types/BalanceServiceTypes.d.ts +2 -2
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +72 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +2 -2
- package/dist/es/services/CovalentClient.d.ts +1 -1
- package/dist/es/util/prettifyCurrency.d.ts +2 -0
- package/dist/es/util/types/BalanceServiceTypes.d.ts +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +72 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +2 -2
- package/dist/esm/services/CovalentClient.d.ts +1 -1
- package/dist/esm/util/prettifyCurrency.d.ts +2 -0
- package/dist/esm/util/types/BalanceServiceTypes.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/services/BalanceService.d.ts +2 -2
- package/dist/services/BalanceService.js +1 -1
- package/dist/services/BalanceService.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/dist/util/types/BalanceServiceTypes.d.ts +2 -2
- package/package.json +1 -1
|
@@ -212,8 +212,6 @@ declare class BlockTransactionWithContractTransfers {
|
|
|
212
212
|
pretty_gas_quote: string;
|
|
213
213
|
/** * The native gas exchange rate for the requested `quote-currency`. */
|
|
214
214
|
gas_quote_rate: number;
|
|
215
|
-
/** * The explorer links for this transaction. */
|
|
216
|
-
explorers: Explorer[];
|
|
217
215
|
transfers: TokenTransferItem[];
|
|
218
216
|
constructor(data: BlockTransactionWithContractTransfers);
|
|
219
217
|
}
|
|
@@ -274,6 +272,8 @@ declare class TokenTransferItem {
|
|
|
274
272
|
balance_quote: number;
|
|
275
273
|
/** * Additional details on which transfer events were invoked. Defaults to `true`. */
|
|
276
274
|
method_calls: MethodCallsForTransfers[];
|
|
275
|
+
/** * The explorer links for this transaction. */
|
|
276
|
+
explorers: Explorer[];
|
|
277
277
|
constructor(data: TokenTransferItem);
|
|
278
278
|
}
|
|
279
279
|
declare class MethodCallsForTransfers {
|
|
@@ -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.6";
|
|
25
25
|
export declare class Response<T> {
|
|
26
26
|
data: T;
|
|
27
27
|
error: boolean;
|
|
@@ -169,8 +169,6 @@ export interface BlockTransactionWithContractTransfers {
|
|
|
169
169
|
pretty_gas_quote: string;
|
|
170
170
|
/** * The native gas exchange rate for the requested `quote-currency`. */
|
|
171
171
|
gas_quote_rate: number;
|
|
172
|
-
/** * The explorer links for this transaction. */
|
|
173
|
-
explorers: Explorer[];
|
|
174
172
|
transfers: TokenTransferItem[];
|
|
175
173
|
}
|
|
176
174
|
export interface TokenTransferItem {
|
|
@@ -212,6 +210,8 @@ export interface TokenTransferItem {
|
|
|
212
210
|
balance_quote: number;
|
|
213
211
|
/** * Additional details on which transfer events were invoked. Defaults to `true`. */
|
|
214
212
|
method_calls: MethodCallsForTransfers[];
|
|
213
|
+
/** * The explorer links for this transaction. */
|
|
214
|
+
explorers: Explorer[];
|
|
215
215
|
}
|
|
216
216
|
export interface MethodCallsForTransfers {
|
|
217
217
|
/** * The address of the sender. */
|
package/dist/esm/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/esm/index.js
CHANGED
|
@@ -657,7 +657,6 @@ class BlockTransactionWithContractTransfers {
|
|
|
657
657
|
this.gas_quote = data.gas_quote;
|
|
658
658
|
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
659
659
|
this.gas_quote_rate = data.gas_quote_rate;
|
|
660
|
-
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer$1(itemData)) : null;
|
|
661
660
|
this.transfers = data.transfers && data.transfers !== null ? data.transfers.map((itemData) => new TokenTransferItem(itemData)) : null;
|
|
662
661
|
}
|
|
663
662
|
}
|
|
@@ -696,6 +695,7 @@ class TokenTransferItem {
|
|
|
696
695
|
this.pretty_delta_quote = data.pretty_delta_quote;
|
|
697
696
|
this.balance_quote = data.balance_quote;
|
|
698
697
|
this.method_calls = data.method_calls && data.method_calls !== null ? data.method_calls.map((itemData) => new MethodCallsForTransfers(itemData)) : null;
|
|
698
|
+
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer$1(itemData)) : null;
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
701
|
class MethodCallsForTransfers {
|
|
@@ -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.6";
|
|
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
|