mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-04-01 02:27:56 +03:00
Merge remote-tracking branch 'refs/remotes/origin/main' into generateSwapCallData-fix
# Conflicts: # package.json
This commit is contained in:
78
src/services/Frontage/index.ts
Normal file
78
src/services/Frontage/index.ts
Normal 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';
|
||||
1
src/services/Frontage/schemas/index.ts
Normal file
1
src/services/Frontage/schemas/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './tickers-schema';
|
||||
13
src/services/Frontage/schemas/tickers-schema.ts
Normal file
13
src/services/Frontage/schemas/tickers-schema.ts
Normal 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);
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user