From f37e6b856070cf785f6aae829be216d281b2214d Mon Sep 17 00:00:00 2001 From: martiliones Date: Sat, 27 Jan 2024 02:12:57 +0600 Subject: [PATCH] fix: transaction query options --- lib/api/get.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/api/get.js b/lib/api/get.js index c6553b0..26cefad 100644 --- a/lib/api/get.js +++ b/lib/api/get.js @@ -23,11 +23,7 @@ export async function getBlock(id = requiredParam('id')) { } export async function getBlocks(...queries) { - const urlQuery = queries.join(','); - - const parsedQuery = new URLSearchParams(urlQuery.replace(/,/g, '&')); - - const res = await api.getBlocks(parsedQuery); // todo + const res = await api.getBlocks(queryStringToObject(queries)); return res.data || res; } @@ -103,11 +99,7 @@ export async function getTransaction(id = requiredParam('id')) { } export async function getTransactions(...queries) { - const urlQuery = queries.join(','); - - const parsedQuery = new URLSearchParams(urlQuery.replace(/,/g, '&')); - - const res = await api.getTransactions(parsedQuery); // todo + const res = await api.getTransactions(queryStringToObject(queries)); return res.data || res; } @@ -137,3 +129,14 @@ export async function getTransactionsReceivedByAddress( 'orderBy=timestamp:desc', ); } + +function queryStringToObject(queries) { + const params = new URLSearchParams(queries.join('&').replace(/,/g, '&')); + const result = {}; + + for (const [key, value] of params.entries()) { + result[key] = value; + } + + return result; +}