From 8b0d1db776bc3e98b45f80f5c4628e1057b523f9 Mon Sep 17 00:00:00 2001 From: Miguel Medeiros Date: Sat, 31 Jul 2021 13:40:15 -0300 Subject: [PATCH] Fix concurrent asynchronous calls. (#675) * Fix concurrent asynchronous calls. * Remove test without mempool info websocket. * Remove isloading$ variable. --- .../cypress/integration/mainnet/mainnet.spec.ts | 3 ++- frontend/cypress/support/websocket.ts | 8 ++++---- .../blockchain-blocks.component.html | 4 ++-- .../blockchain-blocks.component.ts | 8 +++++--- .../blockchain/blockchain.component.html | 4 ++-- .../blockchain/blockchain.component.ts | 16 +++------------- .../mempool-blocks/mempool-blocks.component.html | 4 ++-- .../mempool-blocks/mempool-blocks.component.ts | 3 ++- .../television/television.component.html | 4 ++-- .../television/television.component.ts | 2 -- 10 files changed, 24 insertions(+), 32 deletions(-) diff --git a/frontend/cypress/integration/mainnet/mainnet.spec.ts b/frontend/cypress/integration/mainnet/mainnet.spec.ts index 90b8667d1..91cce9868 100644 --- a/frontend/cypress/integration/mainnet/mainnet.spec.ts +++ b/frontend/cypress/integration/mainnet/mainnet.spec.ts @@ -1,4 +1,4 @@ -import { emitMempoolInfo } from "../../support/websocket"; +import { emitMempoolInfo, emitWithoutMempoolInfo } from "../../support/websocket"; describe('Mainnet', () => { beforeEach(() => { @@ -51,6 +51,7 @@ describe('Mainnet', () => { loaded: true } }); + cy.get(':nth-child(1) > #bitcoin-block-0').should('not.exist'); cy.get(':nth-child(2) > #bitcoin-block-0').should('not.exist'); cy.get(':nth-child(3) > #bitcoin-block-0').should('not.exist'); diff --git a/frontend/cypress/support/websocket.ts b/frontend/cypress/support/websocket.ts index 74b065116..ce971fae9 100644 --- a/frontend/cypress/support/websocket.ts +++ b/frontend/cypress/support/websocket.ts @@ -70,15 +70,15 @@ export const emitMempoolInfo = ({ default: win.mockSocket.send('{"action":"init"}'); win.mockSocket.send('{"action":"want","data":["blocks","stats","mempool-blocks","live-2h-chart"]}'); - cy.readFile('cypress/fixtures/mainnet_mempoolInfo.json', 'ascii').then((fixture) => { - win.mockSocket.send(JSON.stringify(fixture)); - }); win.mockSocket.send('{"conversions":{"USD":32365.338815782445}}'); cy.readFile('cypress/fixtures/mainnet_live2hchart.json', 'ascii').then((fixture) => { win.mockSocket.send(JSON.stringify(fixture)); }); + cy.readFile('cypress/fixtures/mainnet_mempoolInfo.json', 'ascii').then((fixture) => { + win.mockSocket.send(JSON.stringify(fixture)); + }); } }); cy.waitForSkeletonGone(); return cy.get('#mempool-block-0'); -}; +}; \ No newline at end of file diff --git a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html index 99b8d4cce..c0c036dda 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html @@ -1,4 +1,4 @@ -
+
  @@ -25,7 +25,7 @@
-
+
diff --git a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts index af6ac35c7..c8c4dc5f4 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, ChangeDetectorRef, Input } from '@angular/core'; -import { Subscription, Observable } from 'rxjs'; +import { Subscription } from 'rxjs'; import { Block } from 'src/app/interfaces/electrs.interface'; import { StateService } from 'src/app/services/state.service'; import { Router } from '@angular/router'; @@ -11,8 +11,7 @@ import { Router } from '@angular/router'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class BlockchainBlocksComponent implements OnInit, OnDestroy { - @Input() isLoading$: Observable; - + network = ''; blocks: Block[] = this.mountEmptyBlocks(); markHeight: number; @@ -23,6 +22,7 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy { blockStyles = []; interval: any; tabHidden = false; + loadingBlocks = false; arrowVisible = false; arrowLeftPx = 30; @@ -54,6 +54,8 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy { return; } + this.loadingBlocks = true; + if (this.blocks.length && block.height !== this.blocks[0].height + 1) { this.blocks = []; this.blocksFilled = false; diff --git a/frontend/src/app/components/blockchain/blockchain.component.html b/frontend/src/app/components/blockchain/blockchain.component.html index 21e1a7111..ac6d2e37c 100644 --- a/frontend/src/app/components/blockchain/blockchain.component.html +++ b/frontend/src/app/components/blockchain/blockchain.component.html @@ -1,8 +1,8 @@
- - + +
diff --git a/frontend/src/app/components/blockchain/blockchain.component.ts b/frontend/src/app/components/blockchain/blockchain.component.ts index 73dc09768..8be9d7e82 100644 --- a/frontend/src/app/components/blockchain/blockchain.component.ts +++ b/frontend/src/app/components/blockchain/blockchain.component.ts @@ -1,21 +1,11 @@ -import { Component, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core'; -import { StateService } from 'src/app/services/state.service'; -import { Subscription, Observable } from 'rxjs'; - +import { Component, ChangeDetectionStrategy } from '@angular/core'; @Component({ selector: 'app-blockchain', templateUrl: './blockchain.component.html', styleUrls: ['./blockchain.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class BlockchainComponent implements OnInit { - isLoading$: Observable; +export class BlockchainComponent { - constructor( - private stateService: StateService, - ) {} - - ngOnInit() { - this.isLoading$ = this.stateService.isLoadingWebSocket$; - } + constructor() { } } diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html index 4ffef5c91..429623a6d 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html @@ -1,4 +1,4 @@ -
+
@@ -38,7 +38,7 @@
-
+
diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts index 7846b9b71..0cd23f60a 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts @@ -13,7 +13,6 @@ import { feeLevels, mempoolFeeColors } from 'src/app/app.constants'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class MempoolBlocksComponent implements OnInit, OnDestroy { - @Input() isLoading$: Observable; mempoolBlocks: MempoolBlock[] = this.mountEmptyBlocks(); mempoolBlocks$: Observable; @@ -31,6 +30,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { blockPadding = 30; arrowVisible = false; tabHidden = false; + loadingMempoolBlocks = true; rightPosition = 0; transition = '2s'; @@ -106,6 +106,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { timeAvgMins += Math.abs(timeAvgDiff); } + this.loadingMempoolBlocks = false; return timeAvgMins * 60 * 1000; }) ); diff --git a/frontend/src/app/components/television/television.component.html b/frontend/src/app/components/television/television.component.html index 404e10ece..e8a423b0b 100644 --- a/frontend/src/app/components/television/television.component.html +++ b/frontend/src/app/components/television/television.component.html @@ -12,8 +12,8 @@
- - + +
diff --git a/frontend/src/app/components/television/television.component.ts b/frontend/src/app/components/television/television.component.ts index 7ed56d663..ae5d9abfd 100644 --- a/frontend/src/app/components/television/television.component.ts +++ b/frontend/src/app/components/television/television.component.ts @@ -12,7 +12,6 @@ import { Observable } from 'rxjs'; styleUrls: ['./television.component.scss'] }) export class TelevisionComponent implements OnInit { - isLoading$: Observable; mempoolStats: OptimizedMempoolStats[] = []; mempoolVsizeFeesData: any; @@ -27,7 +26,6 @@ export class TelevisionComponent implements OnInit { ngOnInit() { this.seoService.setTitle($localize`:@@46ce8155c9ab953edeec97e8950b5a21e67d7c4e:TV view`); this.websocketService.want(['blocks', 'live-2h-chart', 'mempool-blocks']); - this.isLoading$ = this.stateService.isLoadingWebSocket$; this.apiService.list2HStatistics$() .subscribe((mempoolStats) => {