insight-previous-tcr
Version:
A blockchain explorer for Bitcore
55 lines (49 loc) • 1.5 kB
text/typescript
import { Component, Input, OnInit } from "@angular/core";
import { TxsProvider } from "../../providers/transactions/transactions";
import * as _ from "lodash";
import { ApiProvider, ChainNetwork } from "../../providers/api/api";
export class TransactionListComponent implements OnInit {
public loading = true;
public queryType?: string;
public queryValue?: string;
public transactions?: any = [];
public chainNetwork: ChainNetwork;
public limit = 10;
public chunkSize = 100;
constructor(private txProvider: TxsProvider) {}
public ngOnInit(): void {
if (this.transactions && this.transactions.length === 0) {
this.txProvider
.getTxs(this.chainNetwork, { [this.queryType]: this.queryValue })
.subscribe(
response => {
// Newly Generated Coins (Coinbase) First
const txs = response.map(tx => this.txProvider.toAppTx(tx));
const sortedTxs = _.sortBy(txs, (tx: any) => {
return tx.isCoinBase ? 0 : 1;
});
this.transactions = sortedTxs;
this.loading = false;
},
() => {
this.loading = false;
}
);
} else {
this.loading = false;
}
}
public loadMore(infiniteScroll) {
this.limit += this.chunkSize;
this.chunkSize *= 2;
infiniteScroll.complete();
}
}