Add match rate to block page
This commit is contained in:
		
							parent
							
								
									b6343ddc2d
								
							
						
					
					
						commit
						f3eb403c17
					
				| @ -20,6 +20,7 @@ import indexer from '../indexer'; | ||||
| import fiatConversion from './fiat-conversion'; | ||||
| import poolsParser from './pools-parser'; | ||||
| import BlocksSummariesRepository from '../repositories/BlocksSummariesRepository'; | ||||
| import BlocksAuditsRepository from '../repositories/BlocksAuditsRepository'; | ||||
| import mining from './mining/mining'; | ||||
| import DifficultyAdjustmentsRepository from '../repositories/DifficultyAdjustmentsRepository'; | ||||
| import PricesRepository from '../repositories/PricesRepository'; | ||||
| @ -186,14 +187,18 @@ class Blocks { | ||||
|       if (!pool) { // We should never have this situation in practise
 | ||||
|         logger.warn(`Cannot assign pool to block ${blockExtended.height} and 'unknown' pool does not exist. ` + | ||||
|           `Check your "pools" table entries`); | ||||
|         return blockExtended; | ||||
|       } else { | ||||
|         blockExtended.extras.pool = { | ||||
|           id: pool.id, | ||||
|           name: pool.name, | ||||
|           slug: pool.slug, | ||||
|         }; | ||||
|       } | ||||
| 
 | ||||
|       blockExtended.extras.pool = { | ||||
|         id: pool.id, | ||||
|         name: pool.name, | ||||
|         slug: pool.slug, | ||||
|       }; | ||||
|       const auditSummary = await BlocksAuditsRepository.$getShortBlockAudit(block.id); | ||||
|       if (auditSummary) { | ||||
|         blockExtended.extras.matchRate = auditSummary.matchRate; | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     return blockExtended; | ||||
|  | ||||
| @ -71,6 +71,20 @@ class BlocksAuditRepositories { | ||||
|       throw e; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   public async $getShortBlockAudit(hash: string): Promise<any> { | ||||
|     try { | ||||
|       const [rows]: any[] = await DB.query( | ||||
|         `SELECT hash as id, match_rate as matchRate
 | ||||
|         FROM blocks_audits | ||||
|         WHERE blocks_audits.hash = "${hash}" | ||||
|       `);
 | ||||
|       return rows[0]; | ||||
|     } catch (e: any) { | ||||
|       logger.err(`Cannot fetch block audit from db. Reason: ` + (e instanceof Error ? e.message : e)); | ||||
|       throw e; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export default new BlocksAuditRepositories(); | ||||
|  | ||||
| @ -110,6 +110,13 @@ | ||||
|                   </span> | ||||
|                   </td> | ||||
|                 </tr> | ||||
|                 <tr *ngIf="indexingAvailable"> | ||||
|                   <td i18n="block.health">Block health</td> | ||||
|                   <td> | ||||
|                     <a *ngIf="block.extras?.matchRate != null" [routerLink]="['/block-audit/' | relativeUrl, blockHash]">{{ block.extras.matchRate }}%</a> | ||||
|                     <span *ngIf="block.extras?.matchRate == null" i18n="unknown">Unknown</span> | ||||
|                   </td> | ||||
|                 </tr> | ||||
|               </ng-template> | ||||
|             </tbody> | ||||
|           </table> | ||||
|  | ||||
| @ -47,6 +47,7 @@ export class BlockComponent implements OnInit, OnDestroy { | ||||
|   transactionsError: any = null; | ||||
|   overviewError: any = null; | ||||
|   webGlEnabled = true; | ||||
|   indexingAvailable = false; | ||||
| 
 | ||||
|   transactionSubscription: Subscription; | ||||
|   overviewSubscription: Subscription; | ||||
| @ -86,6 +87,9 @@ export class BlockComponent implements OnInit, OnDestroy { | ||||
|       this.timeLtr = !!ltr; | ||||
|     }); | ||||
| 
 | ||||
|     this.indexingAvailable = (this.stateService.env.BASE_MODULE === 'mempool' && | ||||
|       this.stateService.env.MINING_DASHBOARD === true); | ||||
| 
 | ||||
|     this.txsLoadingStatus$ = this.route.paramMap | ||||
|       .pipe( | ||||
|         switchMap(() => this.stateService.loadingIndicators$), | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user