Adding a global websocket loader observable.

fixes #95
This commit is contained in:
softsimon 2020-07-22 19:21:40 +07:00
parent 6b3e84255a
commit 0f611ecf8a
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
5 changed files with 15 additions and 7 deletions

View File

@ -10,8 +10,7 @@
<ng-template [ngIf]="isLoading">
<div class="loading-block">
<h3>Waiting for blocks...</h3>
<br>
<div class="spinner-border text-light"></div>
<div class="spinner-border text-light mt-2"></div>
</div>
</ng-template>

View File

@ -1,21 +1,28 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { StateService } from 'src/app/services/state.service';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-blockchain',
templateUrl: './blockchain.component.html',
styleUrls: ['./blockchain.component.scss']
})
export class BlockchainComponent implements OnInit {
export class BlockchainComponent implements OnInit, OnDestroy {
txTrackingLoading = false;
txShowTxNotFound = false;
isLoading = true;
subscription: Subscription;
constructor(
private stateService: StateService,
) {}
ngOnInit() {
this.stateService.blocks$.subscribe(() => this.isLoading = false);
this.subscription = this.stateService.isLoadingWebSocket$
.subscribe((isLoading) => this.isLoading = isLoading);
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}

View File

@ -68,7 +68,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
this.stateService.blocks$
.subscribe(([block]) => {
if (block.matchRate >= 80 && !this.tabHidden) {
if (block.matchRate >= 66 && !this.tabHidden) {
this.blockIndex++;
}
});

View File

@ -29,6 +29,7 @@ export class StateService {
txReplaced$ = new Subject<Transaction>();
mempoolTransactions$ = new Subject<Transaction>();
blockTransactions$ = new Subject<Transaction>();
isLoadingWebSocket$ = new ReplaySubject<boolean>(1);
live2Chart$ = new Subject<OptimizedMempoolStats>();

View File

@ -52,16 +52,17 @@ export class WebsocketService {
this.startSubscription();
});
}
startSubscription(retrying = false) {
this.stateService.isLoadingWebSocket$.next(true);
if (retrying) {
this.stateService.connectionState$.next(1);
}
this.websocketSubject.next({'action': 'init'});
this.subscription = this.websocketSubject
.subscribe((response: WebsocketResponse) => {
this.stateService.isLoadingWebSocket$.next(false);
if (response.blocks && response.blocks.length) {
const blocks = response.blocks;
blocks.forEach((block: Block) => {