Skip to content

Commit

Permalink
fixup! fix(coin-module): xrp pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
jprudent committed Jan 9, 2025
1 parent 2163408 commit 8c8359b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions libs/coin-modules/coin-xrp/src/logic/listOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,19 @@ export async function listOperations(
address: string,
options: Options,
): Promise<[boolean, Options, XrplOperation[]]> {

const txs = await getTransactions(address, options);
// Filter out the transactions that are not "Payment" type because the filter on "tx_type" of the node RPC is not working as expected.
// Filter out the transactions that are not "Payment" type because the filter on "tx_type" of the node RPC is not working as expected.
const paymentTxs = txs.filter(tx => tx.tx_json.TransactionType === "Payment");
const shortage = (options.limit && txs.length < options.limit) || false;
const lastTransaction = txs.slice(-1)[0];
const nextOptions = { ...options };
if (lastTransaction) {
nextOptions.ledger_index_max = lastTransaction.tx_json.ledger_index - 1;
if(nextOptions.limit) nextOptions.limit -= paymentTxs.length;
if (nextOptions.limit) nextOptions.limit -= paymentTxs.length;
}
return [shortage, nextOptions, paymentTxs];
}


// TODO BUG: given the number of txs belonging to the SAME block > limit
// when user loop over pages using the provided token
// then user misses some txs that doesn't fit the page size limit
Expand All @@ -78,15 +76,20 @@ export async function listOperations(
const isEnough = () => txShortage || (limit && transactions.length >= limit);
// We need to call the node RPC multiple times to get the desired number of transactions by the limiter.
while (nextOptions.limit && !isEnough()) {
const [newTxShortage, newNextOptions, newTransactions] = await getPaymentTransactions(address, nextOptions);
const [newTxShortage, newNextOptions, newTransactions] = await getPaymentTransactions(
address,
nextOptions,
);
txShortage = newTxShortage;
nextOptions = newNextOptions;
transactions = transactions.concat(newTransactions);
}

const lastTransaction = transactions.slice(-1)[0];
// the next index to start the pagination from
const nextIndex = lastTransaction ? Math.max(lastTransaction.tx_json.ledger_index - 1, minLedgerVersion) : minLedgerVersion;
const nextIndex = lastTransaction
? Math.max(lastTransaction.tx_json.ledger_index - 1, minLedgerVersion)
: minLedgerVersion;

return [transactions.map(convertToCoreOperation(address)), nextIndex];
}
Expand Down

0 comments on commit 8c8359b

Please sign in to comment.