Adds pagination to transaction history
Implements pagination for the transaction history, enabling users to navigate through their transactions in manageable chunks. This improves performance and user experience, especially for users with a large number of transactions. It also introduces total entry counts.
This commit is contained in:
parent
4b327a0aab
commit
69b8f6e2d3
4 changed files with 120 additions and 12 deletions
|
|
@ -10,6 +10,13 @@ window.app = Vue.createApp({
|
|||
balance: null,
|
||||
allUserBalances: [],
|
||||
transactions: [],
|
||||
transactionPagination: {
|
||||
total: 0,
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
has_next: false,
|
||||
has_prev: false
|
||||
},
|
||||
accounts: [],
|
||||
currencies: [],
|
||||
users: [],
|
||||
|
|
@ -306,18 +313,39 @@ window.app = Vue.createApp({
|
|||
console.error('Error loading all user balances:', error)
|
||||
}
|
||||
},
|
||||
async loadTransactions() {
|
||||
async loadTransactions(offset = null) {
|
||||
try {
|
||||
// Use provided offset or current pagination offset
|
||||
const currentOffset = offset !== null ? offset : this.transactionPagination.offset
|
||||
|
||||
const response = await LNbits.api.request(
|
||||
'GET',
|
||||
'/castle/api/v1/entries/user',
|
||||
`/castle/api/v1/entries/user?limit=${this.transactionPagination.limit}&offset=${currentOffset}`,
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
this.transactions = response.data
|
||||
|
||||
// Update transactions and pagination info
|
||||
this.transactions = response.data.entries
|
||||
this.transactionPagination.total = response.data.total
|
||||
this.transactionPagination.offset = response.data.offset
|
||||
this.transactionPagination.has_next = response.data.has_next
|
||||
this.transactionPagination.has_prev = response.data.has_prev
|
||||
} catch (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
}
|
||||
},
|
||||
nextTransactionsPage() {
|
||||
if (this.transactionPagination.has_next) {
|
||||
const newOffset = this.transactionPagination.offset + this.transactionPagination.limit
|
||||
this.loadTransactions(newOffset)
|
||||
}
|
||||
},
|
||||
prevTransactionsPage() {
|
||||
if (this.transactionPagination.has_prev) {
|
||||
const newOffset = Math.max(0, this.transactionPagination.offset - this.transactionPagination.limit)
|
||||
this.loadTransactions(newOffset)
|
||||
}
|
||||
},
|
||||
async loadAccounts() {
|
||||
try {
|
||||
const response = await LNbits.api.request(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue