Skip to content

Commit

Permalink
Rename baseCurrencyOrIdOrSymbol -> baseCurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
skubarenko committed Aug 29, 2022
1 parent eaf2a7e commit 994d6f7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/atomex/atomex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class Atomex implements AtomexService {
}

async convertCurrency(fromAmount: BigNumber.Value, fromCurrency: Currency['id'], toCurrency: Currency['id']): Promise<BigNumber | undefined> {
const price = await this.priceManager.getAveragePrice({ baseCurrencyOrIdOrSymbol: fromCurrency, quoteCurrencyOrIdOrSymbol: toCurrency });
const price = await this.priceManager.getAveragePrice({ baseCurrency: fromCurrency, quoteCurrency: toCurrency });
if (!price)
return undefined;

Expand Down
4 changes: 2 additions & 2 deletions src/blockchain/atomexProtocolV1/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getRedeemRewardInNativeCurrency = async (
redeemFee: FeesInfo,
priceManager: PriceManager
): Promise<FeesInfo> => {
const nativeTokenPriceInUsd = await priceManager.getAveragePrice({ baseCurrencyOrIdOrSymbol: currencyOrId, quoteCurrencyOrIdOrSymbol: 'USD' });
const nativeTokenPriceInUsd = await priceManager.getAveragePrice({ baseCurrency: currencyOrId, quoteCurrency: 'USD' });
if (!nativeTokenPriceInUsd)
throw new Error(`Price for ${currencyOrId} in USD not found`);

Expand Down Expand Up @@ -40,7 +40,7 @@ export const getRedeemRewardInToken = async (
if (!nativeCurrency)
throw new Error(`Native currency not found fir ${currency.blockchain}`);

const nativeTokenPriceInCurrency = await priceManager.getAveragePrice({ baseCurrencyOrIdOrSymbol: nativeCurrency, quoteCurrencyOrIdOrSymbol: currencyOrId });
const nativeTokenPriceInCurrency = await priceManager.getAveragePrice({ baseCurrency: nativeCurrency, quoteCurrency: currencyOrId });

if (!nativeTokenPriceInCurrency)
throw new Error(`Price for ${nativeCurrency.id} in ${currencyOrId} not found`);
Expand Down
24 changes: 12 additions & 12 deletions src/exchange/priceManager/mixedPriceManager/mixedPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export class MixedPriceManager implements PriceManager {
private readonly providersMap: Map<string, PriceProvider>
) { }

async getAveragePrice({ baseCurrencyOrIdOrSymbol, quoteCurrencyOrIdOrSymbol, dataSource = DataSource.All }: GetAveragePriceParameters): Promise<BigNumber | undefined> {
const baseCurrencyOrSymbol = this.tryFindCurrency(baseCurrencyOrIdOrSymbol);
const quoteCurrencyOrSymbol = this.tryFindCurrency(quoteCurrencyOrIdOrSymbol);
async getAveragePrice({ baseCurrency, quoteCurrency, dataSource = DataSource.All }: GetAveragePriceParameters): Promise<BigNumber | undefined> {
const baseCurrencyOrSymbol = this.tryFindCurrency(baseCurrency);
const quoteCurrencyOrSymbol = this.tryFindCurrency(quoteCurrency);

const key = this.getCacheKey({ isAverage: true, baseCurrencyOrSymbol, quoteCurrencyOrSymbol });
if ((dataSource & DataSource.Local) === DataSource.Local) {
Expand All @@ -34,8 +34,8 @@ export class MixedPriceManager implements PriceManager {
if ((dataSource & DataSource.Remote) === DataSource.Remote) {
const providers = this.getAvailableProviders();
const pricePromises = providers.map(provider => this.getPrice({
baseCurrencyOrIdOrSymbol: baseCurrencyOrSymbol,
quoteCurrencyOrIdOrSymbol: quoteCurrencyOrSymbol,
baseCurrency: baseCurrencyOrSymbol,
quoteCurrency: quoteCurrencyOrSymbol,
provider,
dataSource
}));
Expand All @@ -56,9 +56,9 @@ export class MixedPriceManager implements PriceManager {
return undefined;
}

async getPrice({ baseCurrencyOrIdOrSymbol, quoteCurrencyOrIdOrSymbol, provider, dataSource = DataSource.All }: GetPriceParameters): Promise<BigNumber | undefined> {
const baseCurrencyOrSymbol = this.tryFindCurrency(baseCurrencyOrIdOrSymbol);
const quoteCurrencyOrSymbol = this.tryFindCurrency(quoteCurrencyOrIdOrSymbol);
async getPrice({ baseCurrency, quoteCurrency, provider, dataSource = DataSource.All }: GetPriceParameters): Promise<BigNumber | undefined> {
const baseCurrencyOrSymbol = this.tryFindCurrency(baseCurrency);
const quoteCurrencyOrSymbol = this.tryFindCurrency(quoteCurrency);

const key = this.getCacheKey({ isAverage: false, baseCurrencyOrSymbol, quoteCurrencyOrSymbol, provider });
if ((dataSource & DataSource.Local) === DataSource.Local) {
Expand Down Expand Up @@ -92,11 +92,11 @@ export class MixedPriceManager implements PriceManager {
this.cache.clear();
}

private tryFindCurrency(baseCurrencyOrIdOrSymbol: Currency | Currency['id']): Currency | string {
if (typeof baseCurrencyOrIdOrSymbol !== 'string')
return baseCurrencyOrIdOrSymbol;
private tryFindCurrency(baseCurrency: Currency | Currency['id'] | string): Currency | string {
if (typeof baseCurrency !== 'string')
return baseCurrency;

return this.currenciesProvider.getCurrency(baseCurrencyOrIdOrSymbol) || baseCurrencyOrIdOrSymbol;
return this.currenciesProvider.getCurrency(baseCurrency) || baseCurrency;
}

private getCacheKey({ isAverage, baseCurrencyOrSymbol, quoteCurrencyOrSymbol, provider }: GetCacheKeyParameters) {
Expand Down
8 changes: 4 additions & 4 deletions src/exchange/priceManager/priceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import type BigNumber from 'bignumber.js';
import type { Currency, DataSource, Disposable } from '../../common/index';

export interface GetPriceParameters {
baseCurrencyOrIdOrSymbol: Currency | Currency['id'];
quoteCurrencyOrIdOrSymbol: Currency | Currency['id'];
baseCurrency: Currency | Currency['id'] | string;
quoteCurrency: Currency | Currency['id'] | string;
provider?: string;
dataSource?: DataSource;
}

export interface GetAveragePriceParameters {
baseCurrencyOrIdOrSymbol: Currency | Currency['id'];
quoteCurrencyOrIdOrSymbol: Currency | Currency['id'];
baseCurrency: Currency | Currency['id'] | string;
quoteCurrency: Currency | Currency['id'] | string;
dataSource?: DataSource;
}

Expand Down
10 changes: 5 additions & 5 deletions tests/atomex/atomexProtocolV1/atomexProtocolV1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ describe('Atomex Protocol V1 utils', () => {
const createPriceManager = (prices: Record<string, BigNumber>) => {
const priceManager = new MockPriceManager();

const getPriceImplementation = (baseCurrencyOrIdOrSymbol: Currency | Currency['id'], quoteCurrencyOrIdOrSymbol: Currency | Currency['id']) => {
const getPriceImplementation = (baseCurrencyOrIdOrSymbol: Currency | Currency['id'] | string, quoteCurrencyOrIdOrSymbol: Currency | Currency['id'] | string) => {
const baseCurrency = typeof baseCurrencyOrIdOrSymbol === 'string' ? baseCurrencyOrIdOrSymbol : baseCurrencyOrIdOrSymbol.symbol;
const quoteCurrency = typeof quoteCurrencyOrIdOrSymbol === 'string' ? quoteCurrencyOrIdOrSymbol : quoteCurrencyOrIdOrSymbol.symbol;
const symbol = `${baseCurrency}/${quoteCurrency}`;

return prices[symbol];
};

priceManager.getPrice.mockImplementation(async ({ baseCurrencyOrIdOrSymbol, quoteCurrencyOrIdOrSymbol }) => {
return getPriceImplementation(baseCurrencyOrIdOrSymbol, quoteCurrencyOrIdOrSymbol);
priceManager.getPrice.mockImplementation(async ({ baseCurrency, quoteCurrency }) => {
return getPriceImplementation(baseCurrency, quoteCurrency);
});

priceManager.getAveragePrice.mockImplementation(async ({ baseCurrencyOrIdOrSymbol, quoteCurrencyOrIdOrSymbol }) => {
return getPriceImplementation(baseCurrencyOrIdOrSymbol, quoteCurrencyOrIdOrSymbol);
priceManager.getAveragePrice.mockImplementation(async ({ baseCurrency, quoteCurrency }) => {
return getPriceImplementation(baseCurrency, quoteCurrency);
});

return priceManager;
Expand Down

0 comments on commit 994d6f7

Please sign in to comment.