From fffffffdb382600bc0d2d9406d0d7aef8a01a480 Mon Sep 17 00:00:00 2001 From: russeree Date: Fri, 8 Mar 2024 18:24:18 -0800 Subject: [PATCH] add audit=[bool] param to block hash url --- contributors/russeree.txt | 3 ++ .../app/components/block/block.component.ts | 44 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 contributors/russeree.txt diff --git a/contributors/russeree.txt b/contributors/russeree.txt new file mode 100644 index 000000000..0aaef47e5 --- /dev/null +++ b/contributors/russeree.txt @@ -0,0 +1,3 @@ +I hereby accept the terms of the Contributor License Agreement in the CONTRIBUTING.md file of the mempool/mempool git repository as of March 8, 2024. + +Signed: PortlandHODL diff --git a/frontend/src/app/components/block/block.component.ts b/frontend/src/app/components/block/block.component.ts index 1eb1c4798..27c4f8908 100644 --- a/frontend/src/app/components/block/block.component.ts +++ b/frontend/src/app/components/block/block.component.ts @@ -61,6 +61,7 @@ export class BlockComponent implements OnInit, OnDestroy { transactionsError: any = null; overviewError: any = null; webGlEnabled = true; + auditParamEnabled: boolean = false; auditSupported: boolean = this.stateService.env.AUDIT && this.stateService.env.BASE_MODULE === 'mempool' && this.stateService.env.MINING_DASHBOARD === true; auditModeEnabled: boolean = !this.stateService.hideAudit.value; auditAvailable = true; @@ -124,9 +125,16 @@ export class BlockComponent implements OnInit, OnDestroy { this.setAuditAvailable(this.auditSupported); if (this.auditSupported) { - this.auditPrefSubscription = this.stateService.hideAudit.subscribe((hide) => { - this.auditModeEnabled = !hide; - this.showAudit = this.auditAvailable && this.auditModeEnabled; + this.isAuditEnabledFromParam().subscribe(auditParam => { + if (this.auditParamEnabled) { + console.log(`auditParamEnabled: ${auditParam}`); + this.auditModeEnabled = auditParam; + } else { + this.auditPrefSubscription = this.stateService.hideAudit.subscribe(hide => { + this.auditModeEnabled = !hide; + this.showAudit = this.auditAvailable && this.auditModeEnabled; + }); + } }); } @@ -723,6 +731,24 @@ export class BlockComponent implements OnInit, OnDestroy { toggleAuditMode(): void { this.stateService.hideAudit.next(this.auditModeEnabled); + + this.route.queryParams.subscribe(params => { + let queryParams = { ...params }; + delete queryParams['audit']; + + let newUrl = this.router.url.split('?')[0]; + let queryString = new URLSearchParams(queryParams).toString(); + if (queryString) { + newUrl += '?' + queryString; + } + + this.location.replaceState(newUrl); + }); + + this.auditPrefSubscription = this.stateService.hideAudit.subscribe((hide) => { + this.auditModeEnabled = !hide; + this.showAudit = this.auditAvailable && this.auditModeEnabled; + }); } updateAuditAvailableFromBlockHeight(blockHeight: number): void { @@ -731,6 +757,16 @@ export class BlockComponent implements OnInit, OnDestroy { } } + isAuditEnabledFromParam(): Observable { + return this.route.queryParams.pipe( + map(params => { + this.auditParamEnabled = 'audit' in params; + + return this.auditParamEnabled ? !(params['audit'] === 'false') : true; + }) + ); + } + isAuditAvailableFromBlockHeight(blockHeight: number): boolean { if (!this.auditSupported) { return false; @@ -779,4 +815,4 @@ export class BlockComponent implements OnInit, OnDestroy { this.block.canonical = block.id; } } -} +} \ No newline at end of file