Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Pending Transactions appear in transactions?blockID queries (#2015)
Browse files Browse the repository at this point in the history
* 🐛 Fix pending transactions query by blockID

* 🎨 Code cleanup
  • Loading branch information
nagdahimanshu authored Jan 25, 2024
1 parent 1a8da32 commit 559d266
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ const validateParams = async params => {
}
}

if (params.sort) validatedParams.sort = params.sort;

return validatedParams;
};

Expand All @@ -120,22 +118,15 @@ const getPendingTransactions = async params => {
meta: { total: 0 },
};

if ('blockID' in params || 'timestamp' in params || 'height' in params) {
return pendingTransactions;
}

const offset = Number(params.offset) || 0;
const limit = Number(params.limit) || 10;

const validatedParams = await validateParams(params);

const sortComparator = sortParam => {
const sortProp = sortParam.split(':')[0];
const sortOrder = sortParam.split(':')[1];

const comparator = (a, b) =>
sortOrder === 'asc'
? Number(a[sortProp] || 0) - Number(b[sortProp] || 0)
: Number(b[sortProp] || 0) - Number(a[sortProp] || 0);
return comparator;
};

if (pendingTransactionsList.length) {
// Filter according to the request params
const filteredPendingTxs = pendingTransactionsList.filter(
Expand All @@ -155,14 +146,11 @@ const getPendingTransactions = async params => {
(!validatedParams.currentChainTransactions || !transaction.params.receivingChainID),
);

pendingTransactions.data = filteredPendingTxs
.sort(sortComparator(validatedParams.sort))
.slice(offset, offset + limit)
.map(transaction => {
// Set the 'executionStatus'
transaction.executionStatus = TRANSACTION_STATUS.PENDING;
return transaction;
});
pendingTransactions.data = filteredPendingTxs.slice(offset, offset + limit).map(transaction => {
// Set the 'executionStatus'
transaction.executionStatus = TRANSACTION_STATUS.PENDING;
return transaction;
});

pendingTransactions.meta = {
count: pendingTransactions.data.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ describe('Test validateParams method', () => {
const params = {
moduleCommand: 'token:transfer',
address: 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo',
sort: 'timestamp:desc',
};

const result = await validateParams(params);
Expand Down

0 comments on commit 559d266

Please sign in to comment.