From 43dac03ec00933a5879a05ae4f1e4711a64ba61d Mon Sep 17 00:00:00 2001 From: softsimon Date: Thu, 11 Jun 2020 00:11:15 +0700 Subject: [PATCH] Bigfix: Don't chime when switching networks. fixes #84 --- .../blockchain-blocks/blockchain-blocks.component.ts | 6 ++---- frontend/src/app/services/state.service.ts | 2 +- frontend/src/app/services/websocket.service.ts | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) 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 730306003..1e9fe53b6 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts @@ -4,7 +4,6 @@ import { Block } from 'src/app/interfaces/electrs.interface'; import { StateService } from 'src/app/services/state.service'; import { Router } from '@angular/router'; import { AudioService } from 'src/app/services/audio.service'; -import { KEEP_BLOCKS_AMOUNT } from 'src/app/app.constants'; @Component({ selector: 'app-blockchain-blocks', @@ -40,15 +39,14 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy { this.stateService.networkChanged$.subscribe((network) => this.network = network); this.blocksSubscription = this.stateService.blocks$ - .subscribe(([block, txConfirmed]) => { - const currentBlocksAmount = this.blocks.length; + .subscribe(([block, txConfirmed, refilling]) => { if (this.blocks.some((b) => b.height === block.height)) { return; } this.blocks.unshift(block); this.blocks = this.blocks.slice(0, 8); - if (currentBlocksAmount === KEEP_BLOCKS_AMOUNT) { + if (!refilling) { setTimeout(() => this.audioService.playSound('bright-harmony')); block.stage = block.matchRate >= 80 ? 1 : 2; } diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index 46bb37f18..466c2cb84 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -20,7 +20,7 @@ export class StateService { latestBlockHeight = 0; networkChanged$ = new ReplaySubject(1); - blocks$ = new ReplaySubject<[Block, boolean]>(KEEP_BLOCKS_AMOUNT); + blocks$ = new ReplaySubject<[Block, boolean, boolean]>(KEEP_BLOCKS_AMOUNT); conversions$ = new ReplaySubject(1); mempoolStats$ = new ReplaySubject(1); mempoolBlocks$ = new ReplaySubject(1); diff --git a/frontend/src/app/services/websocket.service.ts b/frontend/src/app/services/websocket.service.ts index 00d89ba44..b414added 100644 --- a/frontend/src/app/services/websocket.service.ts +++ b/frontend/src/app/services/websocket.service.ts @@ -64,7 +64,7 @@ export class WebsocketService { blocks.forEach((block: Block) => { if (block.height > this.stateService.latestBlockHeight) { this.stateService.latestBlockHeight = block.height; - this.stateService.blocks$.next([block, false]); + this.stateService.blocks$.next([block, false, true]); } }); } @@ -76,7 +76,7 @@ export class WebsocketService { if (response.block) { if (response.block.height > this.stateService.latestBlockHeight) { this.stateService.latestBlockHeight = response.block.height; - this.stateService.blocks$.next([response.block, !!response.txConfirmed]); + this.stateService.blocks$.next([response.block, !!response.txConfirmed, false]); } if (response.txConfirmed) {