mirror of
https://github.com/mempool/mempool.git
synced 2024-12-28 17:24:25 +01:00
Merge pull request #1489 from mempool/nymkappa/bugfix/single-call-pool-page
Fix spam call to `/api/v1/mining/pool/{slug}`
This commit is contained in:
commit
a79a410859
@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit }
|
|||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { EChartsOption, graphic } from 'echarts';
|
import { EChartsOption, graphic } from 'echarts';
|
||||||
import { BehaviorSubject, Observable, timer } from 'rxjs';
|
import { BehaviorSubject, Observable, timer } from 'rxjs';
|
||||||
import { map, switchMap, tap } from 'rxjs/operators';
|
import { distinctUntilChanged, map, share, switchMap, tap } from 'rxjs/operators';
|
||||||
import { BlockExtended, PoolStat } from 'src/app/interfaces/node-api.interface';
|
import { BlockExtended, PoolStat } from 'src/app/interfaces/node-api.interface';
|
||||||
import { ApiService } from 'src/app/services/api.service';
|
import { ApiService } from 'src/app/services/api.service';
|
||||||
import { StateService } from 'src/app/services/state.service';
|
import { StateService } from 'src/app/services/state.service';
|
||||||
@ -20,7 +20,7 @@ export class PoolComponent implements OnInit {
|
|||||||
@Input() left: number | string = 75;
|
@Input() left: number | string = 75;
|
||||||
|
|
||||||
gfg = true;
|
gfg = true;
|
||||||
|
|
||||||
formatNumber = formatNumber;
|
formatNumber = formatNumber;
|
||||||
poolStats$: Observable<PoolStat>;
|
poolStats$: Observable<PoolStat>;
|
||||||
blocks$: Observable<BlockExtended[]>;
|
blocks$: Observable<BlockExtended[]>;
|
||||||
@ -34,7 +34,7 @@ export class PoolComponent implements OnInit {
|
|||||||
blocks: BlockExtended[] = [];
|
blocks: BlockExtended[] = [];
|
||||||
slug: string = undefined;
|
slug: string = undefined;
|
||||||
|
|
||||||
loadMoreSubject: BehaviorSubject<string> = new BehaviorSubject(this.slug);
|
loadMoreSubject: BehaviorSubject<number> = new BehaviorSubject(this.blocks[this.blocks.length - 1]?.height);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(LOCALE_ID) public locale: string,
|
@Inject(LOCALE_ID) public locale: string,
|
||||||
@ -50,18 +50,20 @@ export class PoolComponent implements OnInit {
|
|||||||
switchMap((slug: any) => {
|
switchMap((slug: any) => {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this.slug = slug;
|
this.slug = slug;
|
||||||
this.loadMoreSubject.next(this.slug);
|
|
||||||
return this.apiService.getPoolHashrate$(this.slug)
|
return this.apiService.getPoolHashrate$(this.slug)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((data) => {
|
switchMap((data) => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
this.prepareChartOptions(data.hashrates.map(val => [val.timestamp * 1000, val.avgHashrate]));
|
this.prepareChartOptions(data.hashrates.map(val => [val.timestamp * 1000, val.avgHashrate]));
|
||||||
return slug;
|
return [slug];
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
switchMap(() => {
|
switchMap((slug) => {
|
||||||
return this.apiService.getPoolStats$(this.slug);
|
return this.apiService.getPoolStats$(slug);
|
||||||
|
}),
|
||||||
|
tap(() => {
|
||||||
|
this.loadMoreSubject.next(this.blocks[this.blocks.length - 1]?.height);
|
||||||
}),
|
}),
|
||||||
map((poolStats) => {
|
map((poolStats) => {
|
||||||
let regexes = '"';
|
let regexes = '"';
|
||||||
@ -79,6 +81,7 @@ export class PoolComponent implements OnInit {
|
|||||||
|
|
||||||
this.blocks$ = this.loadMoreSubject
|
this.blocks$ = this.loadMoreSubject
|
||||||
.pipe(
|
.pipe(
|
||||||
|
distinctUntilChanged(),
|
||||||
switchMap((flag) => {
|
switchMap((flag) => {
|
||||||
if (this.slug === undefined) {
|
if (this.slug === undefined) {
|
||||||
return [];
|
return [];
|
||||||
@ -88,7 +91,8 @@ export class PoolComponent implements OnInit {
|
|||||||
tap((newBlocks) => {
|
tap((newBlocks) => {
|
||||||
this.blocks = this.blocks.concat(newBlocks);
|
this.blocks = this.blocks.concat(newBlocks);
|
||||||
}),
|
}),
|
||||||
map(() => this.blocks)
|
map(() => this.blocks),
|
||||||
|
share(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +128,7 @@ export class PoolComponent implements OnInit {
|
|||||||
align: 'left',
|
align: 'left',
|
||||||
},
|
},
|
||||||
borderColor: '#000',
|
borderColor: '#000',
|
||||||
formatter: function(ticks: any[]) {
|
formatter: function (ticks: any[]) {
|
||||||
let hashratePowerOfTen: any = selectPowerOfTen(1);
|
let hashratePowerOfTen: any = selectPowerOfTen(1);
|
||||||
let hashrate = ticks[0].data[1];
|
let hashrate = ticks[0].data[1];
|
||||||
|
|
||||||
@ -192,14 +196,14 @@ export class PoolComponent implements OnInit {
|
|||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 20,
|
left: 20,
|
||||||
right: 15,
|
right: 15,
|
||||||
selectedDataBackground: {
|
selectedDataBackground: {
|
||||||
lineStyle: {
|
lineStyle: {
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
opacity: 0.45,
|
opacity: 0.45,
|
||||||
},
|
},
|
||||||
areaStyle: {
|
areaStyle: {
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
@ -210,7 +214,7 @@ export class PoolComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadMore() {
|
loadMore() {
|
||||||
this.loadMoreSubject.next(this.slug);
|
this.loadMoreSubject.next(this.blocks[this.blocks.length - 1]?.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
trackByBlock(index: number, block: BlockExtended) {
|
trackByBlock(index: number, block: BlockExtended) {
|
||||||
|
Loading…
Reference in New Issue
Block a user