feat: updated new changes from frontage

This commit is contained in:
Mikhail Gladchenko
2024-04-17 16:15:47 +01:00
parent f8e4b643c3
commit 9705ce0131
4 changed files with 33 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@orionprotocol/sdk", "name": "@orionprotocol/sdk",
"version": "0.20.79-rc7", "version": "0.20.79-rc8",
"description": "Orion Protocol SDK", "description": "Orion Protocol SDK",
"main": "./lib/index.cjs", "main": "./lib/index.cjs",
"module": "./lib/index.js", "module": "./lib/index.js",

View File

@@ -10,6 +10,7 @@ export class Frontage {
this.searchTickers = this.searchTickers.bind(this); this.searchTickers = this.searchTickers.bind(this);
this.getTickers = this.getTickers.bind(this); this.getTickers = this.getTickers.bind(this);
this.getFavorites = this.getFavorites.bind(this);
} }
searchTickers = ({ searchTickers = ({
@@ -57,7 +58,32 @@ export class Frontage {
].filter(Boolean).join('&'); ].filter(Boolean).join('&');
return fetchWithValidation( return fetchWithValidation(
`${this.apiUrl}/api/v1/tickers/get?${queryParams}`, `${this.apiUrl}/api/v1/tickers/get/category?${queryParams}`,
tickersSchema
);
};
getFavorites = ({
tickers,
currentNetwork,
targetNetwork,
sortBy,
sortType,
offset,
limit,
}: { tickers: string } & TickersBaseSearchParams) => {
const queryParams = [
`tickers=${encodeURIComponent(tickers)}`,
currentNetwork !== undefined ? `&currentNetwork=${encodeURIComponent(currentNetwork).toUpperCase()}` : '',
targetNetwork !== undefined ? `&targetNetwork=${encodeURIComponent(targetNetwork).toUpperCase()}` : '',
sortBy !== undefined ? `&sortBy=${encodeURIComponent(sortBy)}` : '',
sortType !== undefined ? `&sortType=${encodeURIComponent(sortType)}` : '',
offset !== undefined ? `&offset=${offset}` : '',
limit !== undefined ? `&limit=${limit}` : '',
].filter(Boolean).join('&');
return fetchWithValidation(
`${this.apiUrl}/api/v1/tickers/get/favourites?${queryParams}`,
tickersSchema tickersSchema
); );
}; };

View File

@@ -1,9 +1,11 @@
import { z } from 'zod'; import { z } from 'zod';
export const tickersSchema = z.array(z.object({ export const tickerSchema = z.object({
pair: z.string(), pair: z.string(),
volume24: z.number(), volume24: z.number(),
change24: z.number(), change24: z.number(),
lastPrice: z.number(), lastPrice: z.number(),
networks: z.array(z.string()), networks: z.array(z.string()),
})); });
export const tickersSchema = z.array(tickerSchema);

View File

@@ -465,7 +465,7 @@ export type OrderSource = 'TERMINAL_MARKET' | 'TERMINAL_LIMIT' | 'SWAP_UI' | 'WI
// Frontage // Frontage
export type NetworkCode = typeof networkCodes[number]; export type NetworkCode = typeof networkCodes[number];
export type TickersCategories = 'USD' | 'ORN' | 'BNB' | 'ALTS'; export type TickersCategories = 'USD' | 'ORN' | 'NATIVE' | 'ALTS';
export type TickersSortBy = 'PRICE' | 'CHANGE' | 'VOLUME'; export type TickersSortBy = 'PRICE' | 'CHANGE' | 'VOLUME';