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

66 lines
2.0 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2019-11-13 14:51:44 +08:00
import { ActivatedRoute, ParamMap } from '@angular/router';
import { ElectrsApiService } from '../../services/electrs-api.service';
2019-11-13 14:51:44 +08:00
import { switchMap } from 'rxjs/operators';
import { Address, Transaction } from '../../interfaces/electrs.interface';
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 {
address: Address;
addressString: string;
2019-11-13 14:51:44 +08:00
isLoadingAddress = true;
transactions: Transaction[];
2019-11-13 14:51:44 +08:00
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 electrsApiService: ElectrsApiService,
2019-11-13 14:51:44 +08:00
) { }
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;
this.isLoadingTransactions = true;
this.transactions = null;
this.addressString = params.get('id') || '';
return this.electrsApiService.getAddress$(this.addressString);
2019-11-13 14:51:44 +08:00
})
)
.subscribe((address) => {
this.address = address;
this.isLoadingAddress = false;
window.scrollTo(0, 0);
2019-11-13 14:51:44 +08:00
this.getAddressTransactions(address.address);
},
(error) => {
2019-11-14 15:03:01 +08:00
console.log(error);
2019-11-13 14:51:44 +08:00
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.electrsApiService.getAddressTransactions$(address)
2019-11-13 14:51:44 +08:00
.subscribe((transactions: any) => {
this.transactions = transactions;
this.isLoadingTransactions = false;
});
}
loadMore() {
this.isLoadingTransactions = true;
this.electrsApiService.getAddressTransactionsFromHash$(this.address.address, this.transactions[this.transactions.length - 1].txid)
2019-11-13 14:51:44 +08:00
.subscribe((transactions) => {
this.transactions = this.transactions.concat(transactions);
this.isLoadingTransactions = false;
});
}
2019-11-10 16:44:00 +08:00
}