2019-07-24 23:08:28 +03:00
|
|
|
import { Component, OnInit, OnDestroy, Renderer2 } from '@angular/core';
|
|
|
|
import { MemPoolService, ITxTracking } from '../services/mem-pool.service';
|
2019-07-21 17:59:47 +03:00
|
|
|
import { ApiService } from '../services/api.service';
|
|
|
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
2019-07-24 23:08:28 +03:00
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { take } from 'rxjs/operators';
|
2019-07-21 17:59:47 +03:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-blockchain',
|
|
|
|
templateUrl: './blockchain.component.html',
|
|
|
|
styleUrls: ['./blockchain.component.scss']
|
|
|
|
})
|
|
|
|
export class BlockchainComponent implements OnInit, OnDestroy {
|
2019-07-24 23:08:28 +03:00
|
|
|
txTrackingSubscription: Subscription;
|
|
|
|
blocksSubscription: Subscription;
|
2019-07-21 17:59:47 +03:00
|
|
|
|
|
|
|
txTrackingLoading = false;
|
|
|
|
txShowTxNotFound = false;
|
2019-07-24 23:08:28 +03:00
|
|
|
isLoading = true;
|
2019-07-21 17:59:47 +03:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private memPoolService: MemPoolService,
|
|
|
|
private apiService: ApiService,
|
|
|
|
private renderer: Renderer2,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2019-08-09 21:45:31 +03:00
|
|
|
this.apiService.webSocketWant(['stats', 'blocks', 'projected-blocks']);
|
2019-07-26 12:48:32 +03:00
|
|
|
|
2019-07-24 23:08:28 +03:00
|
|
|
this.txTrackingSubscription = this.memPoolService.txTracking$
|
|
|
|
.subscribe((response: ITxTracking) => {
|
|
|
|
this.txTrackingLoading = false;
|
|
|
|
this.txShowTxNotFound = response.notFound;
|
|
|
|
if (this.txShowTxNotFound) {
|
|
|
|
setTimeout(() => { this.txShowTxNotFound = false; }, 2000);
|
2019-07-21 17:59:47 +03:00
|
|
|
}
|
2019-07-24 23:08:28 +03:00
|
|
|
});
|
|
|
|
|
2019-07-21 17:59:47 +03:00
|
|
|
this.renderer.addClass(document.body, 'disable-scroll');
|
|
|
|
|
|
|
|
this.route.paramMap
|
|
|
|
.subscribe((params: ParamMap) => {
|
2019-10-24 15:37:39 +08:00
|
|
|
if (this.memPoolService.txTracking$.value.enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-21 17:59:47 +03:00
|
|
|
const txId: string | null = params.get('id');
|
|
|
|
if (!txId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.txTrackingLoading = true;
|
2019-08-09 21:45:31 +03:00
|
|
|
this.apiService.webSocketStartTrackTx(txId);
|
2019-07-21 17:59:47 +03:00
|
|
|
});
|
|
|
|
|
2019-07-24 23:08:28 +03:00
|
|
|
this.memPoolService.txIdSearch$
|
2019-07-21 17:59:47 +03:00
|
|
|
.subscribe((txId) => {
|
|
|
|
if (txId) {
|
2019-10-24 15:37:39 +08:00
|
|
|
|
|
|
|
if (this.memPoolService.txTracking$.value.enabled
|
|
|
|
&& this.memPoolService.txTracking$.value.tx
|
|
|
|
&& this.memPoolService.txTracking$.value.tx.txid === txId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log('enabling tracking loading from idSearch!');
|
2019-07-21 17:59:47 +03:00
|
|
|
this.txTrackingLoading = true;
|
2019-08-09 21:45:31 +03:00
|
|
|
this.apiService.webSocketStartTrackTx(txId);
|
2019-07-21 17:59:47 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-24 23:08:28 +03:00
|
|
|
this.blocksSubscription = this.memPoolService.blocks$
|
|
|
|
.pipe(
|
|
|
|
take(1)
|
|
|
|
)
|
|
|
|
.subscribe((block) => this.isLoading = false);
|
2019-07-21 17:59:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2019-07-24 23:08:28 +03:00
|
|
|
this.blocksSubscription.unsubscribe();
|
|
|
|
this.txTrackingSubscription.unsubscribe();
|
2019-07-21 17:59:47 +03:00
|
|
|
this.renderer.removeClass(document.body, 'disable-scroll');
|
|
|
|
}
|
|
|
|
}
|