mempool/frontend/src/app/blockchain/blockchain.component.ts

71 lines
2.1 KiB
TypeScript
Raw Normal View History

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-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) => {
const txId: string | null = params.get('id');
if (!txId) {
return;
}
this.txTrackingLoading = true;
2019-07-24 23:08:28 +03:00
this.apiService.sendWebSocket({'action': 'track-tx', 'txId': 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) {
this.txTrackingLoading = true;
2019-07-24 23:08:28 +03:00
this.apiService.sendWebSocket({'action': 'track-tx', 'txId': 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');
}
}