Price conversion iprovements

This commit is contained in:
Aleksandr Kraiz
2023-08-08 10:21:54 +04:00
parent 72581b0f4b
commit cd0a0128d8
6 changed files with 24 additions and 78 deletions

View File

@@ -7,10 +7,10 @@ export default function convertPrice(
prices: Partial<Record<string, string>> // quoted in quoteAsset. [name]: priceQuotedInQuoteAsset
) {
const assetInPrice = prices[assetInName];
if (assetInPrice === undefined) throw Error(`Price conversion: AssetIn (${assetInName}) price is undefined`);
if (assetInPrice === undefined) throw Error(`Price conversion: AssetIn (${assetInName}) price is undefined. Available prices: ${JSON.stringify(prices)}`);
const assetOutPrice = prices[assetOutName];
if (assetOutPrice === undefined) throw Error(`Price conversion: AssetOut (${assetOutName}) price is undefined`);
if (assetOutPrice === undefined) throw Error(`Price conversion: AssetOut (${assetOutName}) price is undefined. Available prices: ${JSON.stringify(prices)}`);
const assetInPriceBN = new BigNumber(assetInPrice);
const assetOutPriceBN = new BigNumber(assetOutPrice);

View File

@@ -16,6 +16,7 @@ export { default as getNativeCryptocurrencyName } from './getNativeCryptocurrenc
export { default as laconicParse } from './laconic-parse.js';
export { default as isValidChainId } from './isValidChainId.js';
export { default as isKnownEnv } from './isKnownEnv.js';
export { default as removeFieldsFromObject } from './removeFieldsFromObject.js';
// export { default as HttpError } from './httpError';
export * from './typeHelpers.js';

View File

@@ -0,0 +1,16 @@
const removeFieldsFromObject = <
T extends Record<string, unknown>,
K extends keyof T
>(
obj: T,
fields: K[]
): Omit<T, K> => {
const result = { ...obj };
for (const field of fields) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete result[field];
}
return result;
};
export default removeFieldsFromObject;