Merge remote-tracking branch 'refs/remotes/origin/main' into generateSwapCallData-fix

# Conflicts:
#	package.json
This commit is contained in:
TheJuze
2024-05-15 16:08:44 +03:00
10 changed files with 131 additions and 6 deletions

View File

@@ -0,0 +1,78 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import { tickersSchema } from './schemas';
import type { TickersBaseSearchParams, TickersCategories } from '../../types';
export class Frontage {
private readonly apiUrl: string;
constructor(apiUrl: string) {
this.apiUrl = apiUrl;
}
searchTickers = ({
searchValue,
currentNetwork,
targetNetwork,
sortBy,
sortType,
offset,
limit,
}: { searchValue: string } & TickersBaseSearchParams) => {
const url = new URL(this.apiUrl);
const params = new URLSearchParams();
params.set('searchValue', encodeURIComponent(searchValue));
if (currentNetwork !== undefined) params.set('currentNetwork', encodeURIComponent(currentNetwork).toUpperCase());
if (targetNetwork !== undefined) params.set('targetNetwork', encodeURIComponent(targetNetwork).toUpperCase());
if (sortBy !== undefined) params.set('sortBy', encodeURIComponent(sortBy));
if (sortType !== undefined) params.set('sortType', encodeURIComponent(sortType));
if (offset !== undefined) params.set('offset', offset.toString());
if (limit !== undefined) params.set('limit', limit.toString());
url.pathname += '/api/v1/tickers/search';
url.search = params.toString();
return fetchWithValidation(
url.toString(),
tickersSchema
);
};
getTickers = ({
category,
currentNetwork,
targetNetwork,
sortBy,
sortType,
offset,
limit,
tickers,
}: { category: TickersCategories, tickers?: string } & TickersBaseSearchParams) => {
const url = new URL(this.apiUrl);
const params = new URLSearchParams();
if (category === 'FAVORITES' && tickers !== undefined) params.set('tickers', tickers);
if (category !== 'FAVORITES') params.set('category', category);
if (currentNetwork !== undefined) params.set('currentNetwork', encodeURIComponent(currentNetwork).toUpperCase());
if (targetNetwork !== undefined) params.set('targetNetwork', encodeURIComponent(targetNetwork).toUpperCase());
if (sortBy !== undefined) params.set('sortBy', encodeURIComponent(sortBy));
if (sortType !== undefined) params.set('sortType', encodeURIComponent(sortType));
if (offset !== undefined) params.set('offset', offset.toString());
if (limit !== undefined) params.set('limit', limit.toString());
if (category === 'FAVORITES' && tickers !== undefined) {
url.pathname += '/api/v1/tickers/get/favourites';
} else {
url.pathname += '/api/v1/tickers/get/category';
}
url.search = params.toString();
return fetchWithValidation(
url.toString(),
tickersSchema
);
};
}
export * as schemas from './schemas/index.js';

View File

@@ -0,0 +1 @@
export * from './tickers-schema';

View File

@@ -0,0 +1,13 @@
import { z } from 'zod';
import { SupportedChainId } from '../../../types';
export const tickerSchema = z.object({
pair: z.string(),
volume24: z.number(),
change24: z.number(),
lastPrice: z.number(),
pricePrecision: z.number(),
networks: z.array(z.nativeEnum(SupportedChainId)),
});
export const tickersSchema = z.array(tickerSchema);

View File

@@ -3,3 +3,4 @@ export * as blockchainService from './BlockchainService/index.js';
export * as priceFeed from './PriceFeed/index.js';
export * as referralSystem from './ReferralSystem/index.js';
export * as indexer from './Indexer/index.js';
export * as frontage from './Frontage/index.js';