Fix infinite address scroll

This commit is contained in:
Mononaut 2024-02-06 21:39:29 +00:00
parent fea115bcbc
commit dfdd286f75
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E

View File

@ -31,8 +31,7 @@ export class AddressComponent implements OnInit, OnDestroy {
addressLoadingStatus$: Observable<number>; addressLoadingStatus$: Observable<number>;
addressInfo: null | AddressInformation = null; addressInfo: null | AddressInformation = null;
totalConfirmedTxCount = 0; fullyLoaded = false;
loadedConfirmedTxCount = 0;
txCount = 0; txCount = 0;
received = 0; received = 0;
sent = 0; sent = 0;
@ -66,7 +65,7 @@ export class AddressComponent implements OnInit, OnDestroy {
switchMap((params: ParamMap) => { switchMap((params: ParamMap) => {
this.error = undefined; this.error = undefined;
this.isLoadingAddress = true; this.isLoadingAddress = true;
this.loadedConfirmedTxCount = 0; this.fullyLoaded = false;
this.address = null; this.address = null;
this.isLoadingTransactions = true; this.isLoadingTransactions = true;
this.transactions = null; this.transactions = null;
@ -128,7 +127,6 @@ export class AddressComponent implements OnInit, OnDestroy {
this.tempTransactions = transactions; this.tempTransactions = transactions;
if (transactions.length) { if (transactions.length) {
this.lastTransactionTxId = transactions[transactions.length - 1].txid; this.lastTransactionTxId = transactions[transactions.length - 1].txid;
this.loadedConfirmedTxCount += transactions.filter((tx) => tx.status.confirmed).length;
} }
const fetchTxs: string[] = []; const fetchTxs: string[] = [];
@ -191,8 +189,6 @@ export class AddressComponent implements OnInit, OnDestroy {
this.audioService.playSound('magic'); this.audioService.playSound('magic');
} }
} }
this.totalConfirmedTxCount++;
this.loadedConfirmedTxCount++;
}); });
} }
@ -252,16 +248,20 @@ export class AddressComponent implements OnInit, OnDestroy {
} }
loadMore() { loadMore() {
if (this.isLoadingTransactions || !this.totalConfirmedTxCount || this.loadedConfirmedTxCount >= this.totalConfirmedTxCount) { if (this.isLoadingTransactions || this.fullyLoaded) {
return; return;
} }
this.isLoadingTransactions = true; this.isLoadingTransactions = true;
this.retryLoadMore = false; this.retryLoadMore = false;
this.electrsApiService.getAddressTransactions$(this.address.address, this.lastTransactionTxId) this.electrsApiService.getAddressTransactions$(this.address.address, this.lastTransactionTxId)
.subscribe((transactions: Transaction[]) => { .subscribe((transactions: Transaction[]) => {
this.lastTransactionTxId = transactions[transactions.length - 1].txid; if (transactions && transactions.length) {
this.loadedConfirmedTxCount += transactions.length; this.lastTransactionTxId = transactions[transactions.length - 1].txid;
this.transactions = this.transactions.concat(transactions); this.transactions = this.transactions.concat(transactions);
}
if (transactions?.length == null || transactions.length < 50) {
this.fullyLoaded = true;
}
this.isLoadingTransactions = false; this.isLoadingTransactions = false;
}, },
(error) => { (error) => {
@ -278,7 +278,6 @@ export class AddressComponent implements OnInit, OnDestroy {
this.received = this.address.chain_stats.funded_txo_sum + this.address.mempool_stats.funded_txo_sum; this.received = this.address.chain_stats.funded_txo_sum + this.address.mempool_stats.funded_txo_sum;
this.sent = this.address.chain_stats.spent_txo_sum + this.address.mempool_stats.spent_txo_sum; this.sent = this.address.chain_stats.spent_txo_sum + this.address.mempool_stats.spent_txo_sum;
this.txCount = this.address.chain_stats.tx_count + this.address.mempool_stats.tx_count; this.txCount = this.address.chain_stats.tx_count + this.address.mempool_stats.tx_count;
this.totalConfirmedTxCount = this.address.chain_stats.tx_count;
} }
ngOnDestroy() { ngOnDestroy() {