diff --git a/package.json b/package.json index 8d97e07..bb4738b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.79-rc20", + "version": "0.20.79-rc21", "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 a7d51c5..d1ac04e 100644 --- a/src/services/Frontage/index.ts +++ b/src/services/Frontage/index.ts @@ -18,18 +18,22 @@ export class Frontage { offset, limit, }: { searchValue: string } & TickersBaseSearchParams) => { - 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(); + 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( - `${this.apiUrl}/api/v1/tickers/search?${queryParams}`, + url.toString(), tickersSchema ); }; @@ -44,23 +48,28 @@ export class Frontage { limit, tickers, }: { category: TickersCategories, tickers?: string } & TickersBaseSearchParams) => { - const queryParams = new URLSearchParams({ - tickers: category === 'FAVORITES' && tickers !== undefined ? tickers : '', - category: category !== 'FAVORITES' ? 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 = new URL(this.apiUrl); + const params = new URLSearchParams(); - const url = category === 'FAVORITES' && tickers !== undefined - ? `${this.apiUrl}/api/v1/tickers/get/favourites?${queryParams}` - : `${this.apiUrl}/api/v1/tickers/get/category?${queryParams}`; + 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, + url.toString(), tickersSchema ); };