mempool/frontend/src/app/explorer/address/address.component.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-11-13 14:51:44 +08:00
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { ApiService } from 'src/app/services/api.service';
import { switchMap } from 'rxjs/operators';
2019-11-10 16:44:00 +08:00
@Component({
selector: 'app-address',
templateUrl: './address.component.html',
styleUrls: ['./address.component.scss']
})
export class AddressComponent implements OnInit {
2019-11-13 14:51:44 +08:00
address: any;
isLoadingAddress = true;
latestBlockHeight: number;
transactions: any[];
isLoadingTransactions = true;
error: any;
2019-11-10 16:44:00 +08:00
2019-11-13 14:51:44 +08:00
constructor(
private route: ActivatedRoute,
private apiService: ApiService,
private ref: ChangeDetectorRef,
) { }
2019-11-10 16:44:00 +08:00
ngOnInit() {
2019-11-13 14:51:44 +08:00
this.route.paramMap.pipe(
switchMap((params: ParamMap) => {
this.error = undefined;
this.isLoadingAddress = true;
const address: string = params.get('id') || '';
return this.apiService.getAddress$(address);
})
)
.subscribe((address) => {
this.address = address;
this.isLoadingAddress = false;
this.getAddressTransactions(address.address);
this.ref.markForCheck();
},
(error) => {
this.error = error;
this.isLoadingAddress = false;
});
2019-11-10 16:44:00 +08:00
}
2019-11-13 14:51:44 +08:00
getAddressTransactions(address: string) {
this.apiService.getAddressTransactions$(address)
.subscribe((transactions: any) => {
this.transactions = transactions;
this.isLoadingTransactions = false;
});
}
loadMore() {
this.isLoadingTransactions = true;
this.apiService.getAddressTransactionsFromHash$(this.address.id, this.transactions[this.transactions.length - 1].txid)
.subscribe((transactions) => {
this.transactions = this.transactions.concat(transactions);
this.isLoadingTransactions = false;
});
}
2019-11-10 16:44:00 +08:00
}