feat: Frontage service code review

This commit is contained in:
Mikhail Gladchenko
2024-05-13 13:58:26 +01:00
parent 1521032eb3
commit a8f168228c
2 changed files with 19 additions and 44 deletions

View File

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

View File

@@ -18,15 +18,15 @@ export class Frontage {
offset,
limit,
}: { searchValue: string } & TickersBaseSearchParams) => {
const queryParams = [
`searchValue=${encodeURIComponent(searchValue)}`,
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('&');
const queryParams = new URLSearchParams({
searchValue: encodeURIComponent(searchValue),
currentNetwork: currentNetwork !== undefined ? encodeURIComponent(currentNetwork).toUpperCase() : '',
targetNetwork: targetNetwork !== undefined ? encodeURIComponent(targetNetwork).toUpperCase() : '',
sortBy: sortBy !== undefined ? encodeURIComponent(sortBy) : '',
sortType: sortType !== undefined ? encodeURIComponent(sortType) : '',
offset: offset !== undefined ? offset.toString() : '',
limit: limit !== undefined ? limit.toString() : '',
}).toString();
return fetchWithValidation(
`${this.apiUrl}/api/v1/tickers/search?${queryParams}`,
@@ -44,15 +44,15 @@ export class Frontage {
limit,
tickers,
}: { category: TickersCategories, tickers?: string } & TickersBaseSearchParams) => {
const queryParams = [
category === 'FAVORITES' && tickers !== undefined ? `tickers=${encodeURIComponent(tickers)}` : `category=${encodeURIComponent(category)}`,
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('&');
const queryParams = new URLSearchParams({
category: category === 'FAVORITES' && tickers !== undefined ? `tickers=${encodeURIComponent(tickers)}` : `category=${encodeURIComponent(category)}`,
currentNetwork: currentNetwork !== undefined ? encodeURIComponent(currentNetwork).toUpperCase() : '',
targetNetwork: targetNetwork !== undefined ? encodeURIComponent(targetNetwork).toUpperCase() : '',
sortBy: sortBy !== undefined ? encodeURIComponent(sortBy) : '',
sortType: sortType !== undefined ? encodeURIComponent(sortType) : '',
offset: offset !== undefined ? offset.toString() : '',
limit: limit !== undefined ? limit.toString() : '',
}).toString();
const url = category === 'FAVORITES' && tickers !== undefined
? `${this.apiUrl}/api/v1/tickers/get/favourites?${queryParams}`
@@ -63,31 +63,6 @@ export class Frontage {
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
);
};
}
export * as schemas from './schemas/index.js';