[NEM Library] incomingTransactionsPaginated work with 0-tx accounts?

Just playing around with the library at the moment, though I’m not yet using Typescript (shall switch over when I start a new project), but I’ve noticed some quirks while using incomingTransactionsPaginated. Is it my code, or the fact I’m not yet using TS, or both. :slight_smile:

  1. When trying to fetch transactions from accounts with zero incoming transactions, I can’t seem to get anything returned. Chances are highly likely I’m doing something wrong, but I thought I’d check. If there are transactions, then the subscribe method spits them out as you’d expect.

  2. I’m trying to use the pagination to fill an array before sending them to the front end. But each time I do so using the code below, I seem to introduce duplicates. At this point I’ll be blind to my own errors, so please let me know if something looks/smells funny. transactionsMax is the maximum I need to display, so I don’t need to fetch more than than from the NIS.

const accountHttp = new AccountHttp();
const preparedAddress = new Address(address);

const pageSize = 100;
const recent = accountHttp.incomingTransactionsPaginated(preparedAddress, {
pageSize
});

let total = [];
recent.subscribe(incoming => {
total = [...total, ...incoming];
console.log(incoming);
if (total.length < transactionsMax && incoming.length === pageSize) {
recent.nextPage();
} else {
socket.send(payload('transactionsRecent', total));
}
});

I would start trying to just use one server instead for the connection pool.

const accountHttp = new AccountHttp([  {protocol: "http", domain: "192.3.61.243", port: 7890}]);

:warning: Verify the IP I used is valid.

By the other side, I don’t understand the condition incoming.length === pageSize. I may say, use incoming.length !== 0. It will call the recent.nextPage() when more transaction are pending to be fetched.

:information_source: The reason for just using one server is that the connection pool doesn’t handle well the pagination using multiple nodes at once yet. It’s a known issue.

1 Like

Thanks for that! Specifying an individual node did the trick.

1 Like

By the other side, I don’t understand the condition incoming.length === pageSize. I may say, use incoming.length !== 0. It will call the recent.nextPage() when more transaction are pending to be fetched.

Oh yeah, I used the page size (to indicate a full list with a high chance of more to follow) rather than incoming.length !==0, as I can’t seem to get anything returned from the function when there are no further transactions (i.e. when either the page is empty, or if the account has zero incoming transactions). I’m trying to use it with my donations account (which has no transactions), and the function is hanging without returning anything. :thinking:

Edit: Oh, I just needed to ‘else’ call complete().

1 Like