Skip to content

Conversation

@lissavxo
Copy link
Collaborator

@lissavxo lissavxo commented Nov 30, 2024

Related to #741

Description

Added server side pagination to payments page, before the payments where fetched all at once in a single api call and the pagination was made in the client, now the client will fetch payments using page and pageSize parameters.
Changed Pagination to fetch tx data from database instead of cache, because it was too complex to paginate and order getting data from cache.

Test plan

Run server and check payments page pagination, try to change pageSize and pass between the pages

@lissavxo lissavxo requested a review from chedieck November 30, 2024 23:09
@Klakurka
Copy link
Member

Tests failing.

@lissavxo lissavxo requested a review from Klakurka December 1, 2024 17:16
Copy link
Member

@Klakurka Klakurka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Viewing /payments initially works but if I do an F5 then it throws an error:

image

@lissavxo lissavxo force-pushed the feat/paginate-payments-endpoint branch from 734222c to 2d87333 Compare December 9, 2024 15:33
@lissavxo lissavxo requested a review from Klakurka December 9, 2024 15:34
Copy link
Member

@Klakurka Klakurka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't get it to build:

image

@chedieck
Copy link
Collaborator

Can't get it to build:

This is happening on master, I put #897 up to fix it

@Klakurka
Copy link
Member

Needs a rebase.

@lissavxo lissavxo force-pushed the feat/paginate-payments-endpoint branch from 2d87333 to f32747f Compare December 15, 2024 16:15
@lissavxo lissavxo requested a review from Klakurka December 15, 2024 16:15
Klakurka
Klakurka previously approved these changes Dec 15, 2024
Klakurka
Klakurka previously approved these changes Dec 16, 2024
Klakurka
Klakurka previously approved these changes Dec 17, 2024
Copy link
Collaborator

@chedieck chedieck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing about this PR is that it breaks the sorting using other columns. E.g, if we want to order by amount, there is not really a way to do that without looking at all the payments and then sorting them by amount.

Sorting by network would still be possible in this way, since the network of the address is in the cache key name.

The idea of the issue was to avoid fetching all this data at once, which is possible when the user has it ordered by date or network, but not in the other cases (amount & buttons). I don't really see a way out of it, so maybe we can use pagination only in the case that the ordering is set to happen by date and fetch the whole lot of the data if the user wants it sorted in some other way.

return allPayments
}

function sortByDate (keys: string[], order: 'ascending' | 'descending'): string[] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more clear name: sortWeekKeysByDate, since this function is specific for it.

Copy link
Collaborator

@chedieck chedieck Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more clear name: sortWeekKeysByDate, since this function is specific for it.

No need to do that anymore, since this is obsolete, it can be deleted. However, if you think this could be useful for a future task, just put a comment indicating that and rename it for more clarity.

@lissavxo
Copy link
Collaborator Author

One thing about this PR is that it breaks the sorting using other columns. E.g, if we want to order by amount, there is not really a way to do that without looking at all the payments and then sorting them by amount.

Sorting by network would still be possible in this way, since the network of the address is in the cache key name.

The idea of the issue was to avoid fetching all this data at once, which is possible when the user has it ordered by date or network, but not in the other cases (amount & buttons). I don't really see a way out of it, so maybe we can use pagination only in the case that the ordering is set to happen by date and fetch the whole lot of the data if the user wants it sorted in some other way.

don’t you think having two types of pagination might end up looking a bit messy?

Because for backend pagination, it’s one component, and for frontend, it’s another. I’d have to create something super complex. Is it really worth it?

@chedieck
Copy link
Collaborator

don’t you think having two types of pagination might end up looking a bit messy?

Because for backend pagination, it’s one component, and for frontend, it’s another. I’d have to create something super complex. Is it really worth it?

Yeah, would be messy indeed.

The main reason for this issue is that with many payments we get messages like "API response shouldn't be > 4MB", but the overall behavior is better the way already is, I think.

@chedieck
Copy link
Collaborator

I have an idea: when e.g. requesting it sorted by amount, fetch the list of payments normally (from the DB, in the server), sort it, and then serving it to the client paginated. This fixes the issue of having large API responses and keeps the better answer time if sorted by date. If sorted by amount the answer time will be basically the same as it was already, but is not bad already for what I've tested, even for large addresses.

@Klakurka
Copy link
Member

I'll wait for Estevao's review.

@lissavxo lissavxo force-pushed the feat/paginate-payments-endpoint branch from 4a6a95b to 729de7d Compare December 26, 2024 15:58
Copy link
Collaborator

@chedieck chedieck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Payments for a button with only ecash address are showing as being bitcoin cash payments

@lissavxo lissavxo force-pushed the feat/paginate-payments-endpoint branch from 84f3d90 to 3dbf6cb Compare December 26, 2024 21:08
@chedieck
Copy link
Collaborator

Bug I mentioned looks solved, but now tests are failing.

@lissavxo lissavxo force-pushed the feat/paginate-payments-endpoint branch from 3dbf6cb to 02c386c Compare December 27, 2024 16:04
Copy link
Collaborator

@chedieck chedieck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Amount ordering is wrong.

I am thinking is because the ordering is on the cripto amount, not on the converted value taking into account the price at the time of the tx.

@lissavxo lissavxo requested a review from chedieck December 27, 2024 21:50
@lissavxo lissavxo force-pushed the feat/paginate-payments-endpoint branch 3 times, most recently from 045c4d5 to 74b82d9 Compare December 27, 2024 22:03
@lissavxo lissavxo force-pushed the feat/paginate-payments-endpoint branch from 74b82d9 to 2315345 Compare December 27, 2024 22:29
Copy link
Collaborator

@chedieck chedieck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but when ordering by button name, the network shows BCH icon where it should show the XEC icon.

Copy link
Collaborator

@chedieck chedieck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added requests for the code, many things reminiscent of earlier stages of this PR that need not be created anymore.

return allPayments
}

function sortByDate (keys: string[], order: 'ascending' | 'descending'): string[] {
Copy link
Collaborator

@chedieck chedieck Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more clear name: sortWeekKeysByDate, since this function is specific for it.

No need to do that anymore, since this is obsolete, it can be deleted. However, if you think this could be useful for a future task, just put a comment indicating that and rename it for more clarity.

@lissavxo
Copy link
Collaborator Author

Looks good, but when ordering by button name, the network shows BCH icon where it should show the XEC icon.

there was a typo in the query, fixed

Copy link
Collaborator

@chedieck chedieck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Klakurka Klakurka merged commit 32dd993 into master Dec 31, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants