From d28fe93360dcfe40c436b95c23f5e3829eee0bf3 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Wed, 15 Jun 2022 11:26:58 +0200 Subject: [PATCH] Add #{timespan} in mining charts urls for easier sharing --- .../block-fee-rates-graph.component.html | 20 +++++++++---------- .../block-fee-rates-graph.component.ts | 13 ++++++++++-- .../block-fees-graph.component.html | 20 +++++++++---------- .../block-fees-graph.component.ts | 14 +++++++++++-- .../block-rewards-graph.component.html | 20 +++++++++---------- .../block-rewards-graph.component.ts | 16 ++++++++++++--- .../block-sizes-weights-graph.component.html | 20 +++++++++---------- .../block-sizes-weights-graph.component.ts | 19 +++++++++++------- .../hashrate-chart.component.html | 14 ++++++------- .../hashrate-chart.component.ts | 19 +++++++++++++----- .../hashrate-chart-pools.component.html | 16 +++++---------- .../hashrate-chart-pools.component.ts | 17 ++++++++++++---- .../pool-ranking/pool-ranking.component.html | 20 +++++++++---------- .../pool-ranking/pool-ranking.component.ts | 13 ++++++++++-- 14 files changed, 148 insertions(+), 93 deletions(-) diff --git a/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.html b/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.html index 016c80936..6da8008c6 100644 --- a/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.html +++ b/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.html @@ -9,34 +9,34 @@
diff --git a/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.ts b/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.ts index e34687745..b483f5921 100644 --- a/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.ts +++ b/frontend/src/app/components/block-fee-rates-graph/block-fee-rates-graph.component.ts @@ -12,7 +12,7 @@ import { MiningService } from 'src/app/services/mining.service'; import { selectPowerOfTen } from 'src/app/bitcoin.utils'; import { RelativeUrlPipe } from 'src/app/shared/pipes/relative-url/relative-url.pipe'; import { StateService } from 'src/app/services/state.service'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; @Component({ selector: 'app-block-fee-rates-graph', @@ -56,6 +56,7 @@ export class BlockFeeRatesGraphComponent implements OnInit { private stateService: StateService, private router: Router, private zone: NgZone, + private route: ActivatedRoute, ) { this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' }); this.radioGroupForm.controls.dateSpan.setValue('1y'); @@ -67,9 +68,17 @@ export class BlockFeeRatesGraphComponent implements OnInit { this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); + this.route + .fragment + .subscribe((fragment) => { + if (['24h', '3d', '1w', '1m', '3m', '6m', '1y', '2y', '3y', 'all'].indexOf(fragment) > -1) { + this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: true }); + } + }); + this.statsObservable$ = this.radioGroupForm.get('dateSpan').valueChanges .pipe( - startWith(this.miningWindowPreference), + startWith(this.radioGroupForm.controls.dateSpan.value), switchMap((timespan) => { this.storageService.setValue('miningWindowPreference', timespan); this.timespan = timespan; diff --git a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html index 171aa1d44..03197f26e 100644 --- a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html +++ b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html @@ -9,34 +9,34 @@
diff --git a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts index 3ae260817..7e79ed3fd 100644 --- a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts +++ b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts @@ -9,6 +9,7 @@ import { FormBuilder, FormGroup } from '@angular/forms'; import { download, formatterXAxis, formatterXAxisLabel } from 'src/app/shared/graphs.utils'; import { StorageService } from 'src/app/services/storage.service'; import { MiningService } from 'src/app/services/mining.service'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-block-fees-graph', @@ -48,7 +49,8 @@ export class BlockFeesGraphComponent implements OnInit { private apiService: ApiService, private formBuilder: FormBuilder, private storageService: StorageService, - private miningService: MiningService + private miningService: MiningService, + private route: ActivatedRoute, ) { this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' }); this.radioGroupForm.controls.dateSpan.setValue('1y'); @@ -60,9 +62,17 @@ export class BlockFeesGraphComponent implements OnInit { this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); + this.route + .fragment + .subscribe((fragment) => { + if (['24h', '3d', '1w', '1m', '3m', '6m', '1y', '2y', '3y', 'all'].indexOf(fragment) > -1) { + this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: true }); + } + }); + this.statsObservable$ = this.radioGroupForm.get('dateSpan').valueChanges .pipe( - startWith(this.miningWindowPreference), + startWith(this.radioGroupForm.controls.dateSpan.value), switchMap((timespan) => { this.storageService.setValue('miningWindowPreference', timespan); this.timespan = timespan; diff --git a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html index e84e4daff..24380d61d 100644 --- a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html +++ b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html @@ -10,34 +10,34 @@
diff --git a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts index ce71c6986..dbea4bc26 100644 --- a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts +++ b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core'; import { EChartsOption, graphic } from 'echarts'; import { Observable } from 'rxjs'; import { map, share, startWith, switchMap, tap } from 'rxjs/operators'; @@ -9,6 +9,7 @@ import { FormBuilder, FormGroup } from '@angular/forms'; import { download, formatterXAxis, formatterXAxisLabel } from 'src/app/shared/graphs.utils'; import { MiningService } from 'src/app/services/mining.service'; import { StorageService } from 'src/app/services/storage.service'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-block-rewards-graph', @@ -48,7 +49,8 @@ export class BlockRewardsGraphComponent implements OnInit { private apiService: ApiService, private formBuilder: FormBuilder, private miningService: MiningService, - private storageService: StorageService + private storageService: StorageService, + private route: ActivatedRoute, ) { } @@ -58,9 +60,17 @@ export class BlockRewardsGraphComponent implements OnInit { this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); + this.route + .fragment + .subscribe((fragment) => { + if (['24h', '3d', '1w', '1m', '3m', '6m', '1y', '2y', '3y', 'all'].indexOf(fragment) > -1) { + this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: true }); + } + }); + this.statsObservable$ = this.radioGroupForm.get('dateSpan').valueChanges .pipe( - startWith(this.miningWindowPreference), + startWith(this.radioGroupForm.controls.dateSpan.value), switchMap((timespan) => { this.storageService.setValue('miningWindowPreference', timespan); this.timespan = timespan; diff --git a/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.html b/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.html index 704df5b20..5ad2c4003 100644 --- a/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.html +++ b/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.html @@ -9,34 +9,34 @@
diff --git a/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.ts b/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.ts index 304a5a743..1cbfc44aa 100644 --- a/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.ts +++ b/frontend/src/app/components/block-sizes-weights-graph/block-sizes-weights-graph.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit, HostBinding, NgZone } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit, HostBinding } from '@angular/core'; import { EChartsOption} from 'echarts'; import { Observable } from 'rxjs'; import { map, share, startWith, switchMap, tap } from 'rxjs/operators'; @@ -8,8 +8,7 @@ import { formatNumber } from '@angular/common'; import { FormBuilder, FormGroup } from '@angular/forms'; import { StorageService } from 'src/app/services/storage.service'; import { MiningService } from 'src/app/services/mining.service'; -import { StateService } from 'src/app/services/state.service'; -import { Router } from '@angular/router'; +import { ActivatedRoute } from '@angular/router'; import { download, formatterXAxis } from 'src/app/shared/graphs.utils'; @Component({ @@ -53,9 +52,7 @@ export class BlockSizesWeightsGraphComponent implements OnInit { private formBuilder: FormBuilder, private storageService: StorageService, private miningService: MiningService, - private stateService: StateService, - private router: Router, - private zone: NgZone, + private route: ActivatedRoute, ) { } @@ -67,9 +64,17 @@ export class BlockSizesWeightsGraphComponent implements OnInit { this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); + this.route + .fragment + .subscribe((fragment) => { + if (['24h', '3d', '1w', '1m', '3m', '6m', '1y', '2y', '3y', 'all'].indexOf(fragment) > -1) { + this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: true }); + } + }); + this.blockSizesWeightsObservable$ = this.radioGroupForm.get('dateSpan').valueChanges .pipe( - startWith(this.miningWindowPreference), + startWith(this.radioGroupForm.controls.dateSpan.value), switchMap((timespan) => { this.timespan = timespan; if (!firstRun) { diff --git a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html index 2cae2ec4b..1a3d56b7b 100644 --- a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html +++ b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html @@ -28,25 +28,25 @@
diff --git a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts index 863895f8f..0278bad4d 100644 --- a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts +++ b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts @@ -1,7 +1,7 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, Input, LOCALE_ID, OnInit, HostBinding } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit, HostBinding } from '@angular/core'; import { EChartsOption, graphic } from 'echarts'; import { Observable } from 'rxjs'; -import { delay, map, retryWhen, share, startWith, switchMap, tap } from 'rxjs/operators'; +import { map, share, startWith, switchMap, tap } from 'rxjs/operators'; import { ApiService } from 'src/app/services/api.service'; import { SeoService } from 'src/app/services/seo.service'; import { formatNumber } from '@angular/common'; @@ -10,6 +10,7 @@ import { selectPowerOfTen } from 'src/app/bitcoin.utils'; import { StorageService } from 'src/app/services/storage.service'; import { MiningService } from 'src/app/services/mining.service'; import { download } from 'src/app/shared/graphs.utils'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-hashrate-chart', @@ -52,9 +53,9 @@ export class HashrateChartComponent implements OnInit { private seoService: SeoService, private apiService: ApiService, private formBuilder: FormBuilder, - private cd: ChangeDetectorRef, private storageService: StorageService, - private miningService: MiningService + private miningService: MiningService, + private route: ActivatedRoute, ) { } @@ -70,9 +71,17 @@ export class HashrateChartComponent implements OnInit { this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); + this.route + .fragment + .subscribe((fragment) => { + if (['1m', '3m', '6m', '1y', '2y', '3y', 'all'].indexOf(fragment) > -1) { + this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: true }); + } + }); + this.hashrateObservable$ = this.radioGroupForm.get('dateSpan').valueChanges .pipe( - startWith(this.miningWindowPreference), + startWith(this.radioGroupForm.controls.dateSpan.value), switchMap((timespan) => { if (!this.widget && !firstRun) { this.storageService.setValue('miningWindowPreference', timespan); diff --git a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html index a392e122b..66ec09390 100644 --- a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html +++ b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html @@ -9,26 +9,20 @@
- -
diff --git a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts index 65c46fc99..1c256d0a5 100644 --- a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts +++ b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts @@ -9,7 +9,7 @@ import { poolsColor } from 'src/app/app.constants'; import { StorageService } from 'src/app/services/storage.service'; import { MiningService } from 'src/app/services/mining.service'; import { download } from 'src/app/shared/graphs.utils'; -import { time } from 'console'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-hashrate-chart-pools', @@ -51,7 +51,8 @@ export class HashrateChartPoolsComponent implements OnInit { private formBuilder: FormBuilder, private cd: ChangeDetectorRef, private storageService: StorageService, - private miningService: MiningService + private miningService: MiningService, + private route: ActivatedRoute, ) { this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' }); this.radioGroupForm.controls.dateSpan.setValue('1y'); @@ -61,13 +62,21 @@ export class HashrateChartPoolsComponent implements OnInit { let firstRun = true; this.seoService.setTitle($localize`:@@mining.pools-historical-dominance:Pools Historical Dominance`); - this.miningWindowPreference = this.miningService.getDefaultTimespan('1m'); + this.miningWindowPreference = this.miningService.getDefaultTimespan('6m'); this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); + this.route + .fragment + .subscribe((fragment) => { + if (['6m', '1y', '2y', '3y', 'all'].indexOf(fragment) > -1) { + this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: true }); + } + }); + this.hashrateObservable$ = this.radioGroupForm.get('dateSpan').valueChanges .pipe( - startWith(this.miningWindowPreference), + startWith(this.radioGroupForm.controls.dateSpan.value), switchMap((timespan) => { if (!firstRun) { this.storageService.setValue('miningWindowPreference', timespan); 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 4651b62c1..2a84295c6 100644 --- a/frontend/src/app/components/pool-ranking/pool-ranking.component.html +++ b/frontend/src/app/components/pool-ranking/pool-ranking.component.html @@ -40,34 +40,34 @@ *ngIf="!widget && (miningStatsObservable$ | async) as stats">
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 a5bf79678..f8df32840 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,6 @@ import { ChangeDetectionStrategy, Component, Input, NgZone, OnInit, HostBinding } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { EChartsOption, PieSeriesOption } from 'echarts'; import { concat, Observable } from 'rxjs'; import { map, share, startWith, switchMap, tap } from 'rxjs/operators'; @@ -45,6 +45,7 @@ export class PoolRankingComponent implements OnInit { private seoService: SeoService, private router: Router, private zone: NgZone, + private route: ActivatedRoute, ) { } @@ -58,10 +59,18 @@ export class PoolRankingComponent implements OnInit { this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); + this.route + .fragment + .subscribe((fragment) => { + if (['24h', '3d', '1w', '1m', '3m', '6m', '1y', '2y', '3y', 'all'].indexOf(fragment) > -1) { + this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: true }); + } + }); + this.miningStatsObservable$ = concat( this.radioGroupForm.get('dateSpan').valueChanges .pipe( - startWith(this.miningWindowPreference), // (trigger when the page loads) + startWith(this.radioGroupForm.controls.dateSpan.value), // (trigger when the page loads) tap((value) => { this.timespan = value; if (!this.widget) {