From a8f168228c020c53bf89311ec48fdec975c4b394 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 13 May 2024 13:58:26 +0100 Subject: [PATCH] feat: Frontage service code review --- package.json | 2 +- src/services/Frontage/index.ts | 61 ++++++++++------------------------ 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 0dcf55b..5108a1b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/services/Frontage/index.ts b/src/services/Frontage/index.ts index a3f5720..939f3a4 100644 --- a/src/services/Frontage/index.ts +++ b/src/services/Frontage/index.ts @@ -18,15 +18,15 @@ export class Frontage { offset, limit, }: { searchValue: string } & TickersBaseSearchParams) => { - const queryParams = [ - `searchValue=${encodeURIComponent(searchValue)}`, - currentNetwork !== undefined ? `¤tNetwork=${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 ? `¤tNetwork=${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 ? `¤tNetwork=${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';