mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-17 00:31:34 +03:00
Price conversion iprovements
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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';
|
||||
|
||||
16
src/utils/removeFieldsFromObject.ts
Normal file
16
src/utils/removeFieldsFromObject.ts
Normal 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;
|
||||
Reference in New Issue
Block a user