Skip to content

Commit

Permalink
fix: transaction query options
Browse files Browse the repository at this point in the history
  • Loading branch information
martiliones committed Jan 26, 2024
1 parent f5176a8 commit f37e6b8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/api/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

0 comments on commit f37e6b8

Please sign in to comment.