helium-js
helium-js copied to clipboard
*hasMore* attribute of list is always set to true even when list is empty.
While working on the issue https://github.com/helium/explorer/issues/216, I found out that hasMore
attribute of the list is always set to true even when the list is empty and also when there is no more data to show.
To check the bug, we only need to add console.log(this.list)
statement as shown below in ActivityList.js component in Explorer.
This is the code snippet that is used create a list.
Hey @danielcolinjames and @allenan. I would love to know your suggestions on this issue.
left some comments regarding this on https://github.com/helium/explorer/pull/257. But the gist is that helium-js exposes 2 different pagination strategies. The first is a traditional page-based system that wraps the cursor system from the API. The nextPage
and hasMore
functions and the data
property are part of this system. The second pagination system is an async iterator approach which uses take
to abstract the concept of pages. You can continue to "take" from the resource and it will perform any page fetches required to satisfy that amount under the hood. When take
stops returning items, you've exhausted that resource. Hopefully that helps clear things up
Hey @allenan, Thanks for the explanation. This has cleared my doubt. Is it possible to remove hasMore
attribute from the response when a take
function is called because even when the list is empty initially the hasMore
attribute is set to true and is creating confusion between the two pagination methods.
I seem to have this problem for traditional page-based system:
const { activity } = new Client(Network.production).accounts.get(account)
const txs: AnyTransaction[] = []
let page = await activity.list()
page.data.forEach(anyTx => txs.push(anyTx))
// this fails with 429 (too many requests); page.hasMore seems to be always true,
// even if there are 2 txs, like for 13eCVbi4tTofg38hT5rUFufKHmp1v9X4WDLtBUx2aytaFjRGqf4 (random address from explorer)
// for which the loop is expected to not even start
while(page.hasMore) {
page = await page.nextPage()
page.data.forEach(anyTx => txs.push(anyTx))
}