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

Pending Transactions appear in transactions?blockID queries #2015

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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