From 7230b65dc31751f4573f0e1175dc38ca0a92bc22 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Tue, 11 Jul 2023 16:35:00 +0900 Subject: [PATCH] remove console.log, fix null blocks --- .../src/app/components/block/block.component.ts | 2 +- .../blockchain-blocks.component.ts | 2 +- frontend/src/app/services/state.service.ts | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/components/block/block.component.ts b/frontend/src/app/components/block/block.component.ts index faadd7b5c..5a24ebab8 100644 --- a/frontend/src/app/components/block/block.component.ts +++ b/frontend/src/app/components/block/block.component.ts @@ -142,7 +142,7 @@ export class BlockComponent implements OnInit, OnDestroy { if (block?.extras?.reward != undefined) { this.fees = block.extras.reward / 100000000 - this.blockSubsidy; } - } else if (block.height === this.block.height) { + } else if (block.height === this.block?.height) { this.block.stale = true; this.block.canonical = block.id; } 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 f9f25315f..245973885 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts @@ -210,7 +210,7 @@ export class BlockchainBlocksComponent implements OnInit, OnChanges, OnDestroy { if (this.chainTip == null) { this.pendingMarkBlock = { animate, newBlockFromLeft }; } - const blockindex = this.blocks.findIndex((b) => { console.log(b); return b.height === this.markHeight }); + const blockindex = this.blocks.findIndex((b) => b.height === this.markHeight); if (blockindex > -1) { if (!animate) { this.arrowTransition = 'inherit'; diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index 4b1323939..a3392d738 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -5,7 +5,7 @@ import { IBackendInfo, MempoolBlock, MempoolBlockDelta, MempoolInfo, Recommended import { BlockExtended, DifficultyAdjustment, MempoolPosition, OptimizedMempoolStats, RbfTree } from '../interfaces/node-api.interface'; import { Router, NavigationStart } from '@angular/router'; import { isPlatformBrowser } from '@angular/common'; -import { map, scan, shareReplay } from 'rxjs/operators'; +import { filter, map, scan, shareReplay } from 'rxjs/operators'; import { StorageService } from './storage.service'; export interface MarkBlockState { @@ -94,7 +94,8 @@ export class StateService { networkChanged$ = new ReplaySubject(1); lightningChanged$ = new ReplaySubject(1); - blocks$ = new BehaviorSubject([]); + blocksSubject$ = new BehaviorSubject([]); + blocks$: Observable; transactions$ = new ReplaySubject(6); conversions$ = new ReplaySubject(1); bsqPrice$ = new ReplaySubject(1); @@ -200,11 +201,13 @@ export class StateService { this.networkChanged$.subscribe((network) => { this.transactions$ = new ReplaySubject(6); - this.blocks$ = new ReplaySubject<[BlockExtended, string]>(this.env.KEEP_BLOCKS_AMOUNT); + this.blocksSubject$ = new BehaviorSubject([]); }); this.blockVSize = this.env.BLOCK_WEIGHT_UNITS / 4; + this.blocks$ = this.blocksSubject$.pipe(filter(blocks => blocks != null && blocks.length > 0)); + const savedTimePreference = this.storageService.getValue('time-preference-ltr'); const rtlLanguage = (this.locale.startsWith('ar') || this.locale.startsWith('fa') || this.locale.startsWith('he')); // default time direction is right-to-left, unless locale is a RTL language @@ -344,12 +347,12 @@ export class StateService { resetBlocks(blocks: BlockExtended[]): void { this.blocks = blocks.reverse(); - this.blocks$.next(blocks); + this.blocksSubject$.next(blocks); } addBlock(block: BlockExtended): void { this.blocks.unshift(block); this.blocks = this.blocks.slice(0, this.env.KEEP_BLOCKS_AMOUNT); - this.blocks$.next(this.blocks); + this.blocksSubject$.next(this.blocks); } }