From 4f02efd7fee3ae31c97751a97061daf1139f8636 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Mon, 14 Feb 2022 13:21:35 +0900 Subject: [PATCH] Fix block link in pool page - Click on chart slice open pool page --- backend/src/api/mining.ts | 1 - backend/src/repositories/BlocksRepository.ts | 2 +- .../pool-ranking/pool-ranking.component.html | 2 +- .../pool-ranking/pool-ranking.component.ts | 21 ++++++++++++++++--- .../app/components/pool/pool.component.html | 16 +++++++------- .../src/app/interfaces/node-api.interface.ts | 4 ++++ 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/backend/src/api/mining.ts b/backend/src/api/mining.ts index bf8c6b340..2a978868f 100644 --- a/backend/src/api/mining.ts +++ b/backend/src/api/mining.ts @@ -2,7 +2,6 @@ import { PoolInfo, PoolStats } from '../mempool.interfaces'; import BlocksRepository, { EmptyBlocks } from '../repositories/BlocksRepository'; import PoolsRepository from '../repositories/PoolsRepository'; import bitcoinClient from './bitcoin/bitcoin-client'; -import { Common } from './common'; class Mining { constructor() { diff --git a/backend/src/repositories/BlocksRepository.ts b/backend/src/repositories/BlocksRepository.ts index d8465ea71..644c6a277 100644 --- a/backend/src/repositories/BlocksRepository.ts +++ b/backend/src/repositories/BlocksRepository.ts @@ -172,7 +172,7 @@ class BlocksRepository { startHeight: number | null = null ): Promise { const params: any[] = []; - let query = `SELECT height, hash, tx_count, size, weight, pool_id, UNIX_TIMESTAMP(blockTimestamp) as timestamp, 0 as reward + let query = `SELECT height, hash as id, tx_count, size, weight, pool_id, UNIX_TIMESTAMP(blockTimestamp) as timestamp, 0 as reward FROM blocks WHERE pool_id = ?`; params.push(poolId); diff --git a/frontend/src/app/components/pool-ranking/pool-ranking.component.html b/frontend/src/app/components/pool-ranking/pool-ranking.component.html index 45707d328..1f6fdbc0e 100644 --- a/frontend/src/app/components/pool-ranking/pool-ranking.component.html +++ b/frontend/src/app/components/pool-ranking/pool-ranking.component.html @@ -1,7 +1,7 @@
-
+
diff --git a/frontend/src/app/components/pool-ranking/pool-ranking.component.ts b/frontend/src/app/components/pool-ranking/pool-ranking.component.ts index 27515d503..d1b64f190 100644 --- a/frontend/src/app/components/pool-ranking/pool-ranking.component.ts +++ b/frontend/src/app/components/pool-ranking/pool-ranking.component.ts @@ -1,6 +1,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; -import { EChartsOption } from 'echarts'; +import { Router } from '@angular/router'; +import { EChartsOption, PieSeriesOption } from 'echarts'; import { combineLatest, Observable, of } from 'rxjs'; import { catchError, map, share, skip, startWith, switchMap, tap } from 'rxjs/operators'; import { SinglePoolStats } from 'src/app/interfaces/node-api.interface'; @@ -31,6 +32,7 @@ export class PoolRankingComponent implements OnInit, OnDestroy { chartInitOptions = { renderer: 'svg' }; + chartInstance: any = undefined; miningStatsObservable$: Observable; @@ -40,6 +42,7 @@ export class PoolRankingComponent implements OnInit, OnDestroy { private formBuilder: FormBuilder, private miningService: MiningService, private seoService: SeoService, + private router: Router, ) { this.seoService.setTitle($localize`:@@mining.mining-pools:Mining Pools`); this.poolsWindowPreference = this.storageService.getValue('poolsWindowPreference') ? this.storageService.getValue('poolsWindowPreference') : '1w'; @@ -107,7 +110,7 @@ export class PoolRankingComponent implements OnInit, OnDestroy { if (parseFloat(pool.share) < poolShareThreshold) { return; } - data.push({ + data.push({ value: pool.share, name: pool.name + (this.isMobile() ? `` : ` (${pool.share}%)`), label: { @@ -129,7 +132,8 @@ export class PoolRankingComponent implements OnInit, OnDestroy { pool.blockCount.toString() + ` blocks`; } } - } + }, + data: pool.poolId, }); }); return data; @@ -197,6 +201,17 @@ export class PoolRankingComponent implements OnInit, OnDestroy { }; } + onChartInit(ec) { + if (this.chartInstance !== undefined) { + return; + } + + this.chartInstance = ec; + this.chartInstance.on('click', (e) => { + this.router.navigate(['/mining/pool/', e.data.data]); + }) + } + /** * Default mining stats if something goes wrong */ diff --git a/frontend/src/app/components/pool/pool.component.html b/frontend/src/app/components/pool/pool.component.html index 471cd1449..fff474564 100644 --- a/frontend/src/app/components/pool/pool.component.html +++ b/frontend/src/app/components/pool/pool.component.html @@ -47,11 +47,11 @@
-
+
- + - +
AddressesAddresses
{{ address }}
@@ -60,22 +60,22 @@
~
Coinbase TagsCoinbase Tags {{ poolStats.pool.regexes }}
-
+
- - + + - - + +
Mined Blocks{{ poolStats.blockCount }}Mined Blocks{{ poolStats.blockCount }}
Empty Blocks{{ poolStats.emptyBlocks.length }}Empty Blocks{{ poolStats.emptyBlocks.length }}
diff --git a/frontend/src/app/interfaces/node-api.interface.ts b/frontend/src/app/interfaces/node-api.interface.ts index dfcb5836e..472df0088 100644 --- a/frontend/src/app/interfaces/node-api.interface.ts +++ b/frontend/src/app/interfaces/node-api.interface.ts @@ -106,6 +106,10 @@ export interface BlockExtension { reward?: number; coinbaseTx?: Transaction; matchRate?: number; + pool?: { + id: number; + name: string; + } stage?: number; // Frontend only }