Skip to content

Commit ff9d006

Browse files
committed
Added check to not cache data from subgraph for disabled networks
1 parent fa65e6f commit ff9d006

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

packages/apps/dashboard/server/src/modules/details/details.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { Module } from '@nestjs/common';
33
import { DetailsService } from './details.service';
44
import { DetailsController } from './details.controller';
55
import { HttpModule } from '@nestjs/axios';
6+
import { StatsModule } from '../stats/stats.module';
67

78
@Module({
8-
imports: [HttpModule],
9+
imports: [HttpModule, StatsModule],
910
controllers: [DetailsController],
1011
providers: [DetailsService],
1112
})

packages/apps/dashboard/server/src/modules/details/details.service.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { plainToInstance } from 'class-transformer';
2-
import { MainnetsId } from '../../common/utils/constants';
32
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
43
import {
54
ChainId,
@@ -21,11 +20,13 @@ import { firstValueFrom } from 'rxjs';
2120
import { HMToken__factory } from '@human-protocol/core/typechain-types';
2221
import { ethers } from 'ethers';
2322
import { NetworkConfigService } from '../../common/config/network-config.service';
23+
import { StatsService } from '../stats/stats.service';
2424

2525
@Injectable()
2626
export class DetailsService {
2727
private readonly logger = new Logger(DetailsService.name);
2828
constructor(
29+
private readonly statsService: StatsService,
2930
private readonly configService: EnvironmentConfigService,
3031
private readonly httpService: HttpService,
3132
private readonly networkConfig: NetworkConfigService,
@@ -149,9 +150,7 @@ export class DetailsService {
149150

150151
public async getBestLeadersByRole(chainId?: ChainId): Promise<LeaderDto[]> {
151152
const chainIds = !chainId
152-
? (Object.values(MainnetsId).filter(
153-
(value) => typeof value === 'number',
154-
) as number[])
153+
? await this.statsService.getAvailableNetworks()
155154
: [chainId];
156155

157156
const leadersByRole: { [role: string]: LeaderDto } = {};
@@ -187,9 +186,7 @@ export class DetailsService {
187186

188187
public async getAllLeaders(chainId?: ChainId): Promise<LeaderDto[]> {
189188
const chainIds = !chainId
190-
? (Object.values(MainnetsId).filter(
191-
(value) => typeof value === 'number',
192-
) as number[])
189+
? await this.statsService.getAvailableNetworks()
193190
: [chainId];
194191

195192
const allLeaders: LeaderDto[] = [];

packages/apps/dashboard/server/src/modules/stats/stats.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { StorageModule } from '../storage/storage.module';
88
@Module({
99
imports: [HttpModule, StorageModule],
1010
controllers: [StatsController],
11+
exports: [StatsService],
1112
providers: [StatsService],
1213
})
1314
export class StatsModule {}

packages/apps/dashboard/server/src/modules/stats/stats.service.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ export class StatsService implements OnModuleInit {
180180
totalHolders: 0,
181181
totalTransactions: 0,
182182
};
183-
for (const network of Object.values(MainnetsId).filter(
184-
(value) => typeof value === 'number',
185-
) as number[]) {
183+
const availableNetworks = await this.getAvailableNetworks();
184+
for (const network of availableNetworks) {
186185
const statisticsClient = new StatisticsClient(NETWORKS[network]);
187186
const generalStats = await statisticsClient.getHMTStatistics();
188187
aggregatedStats.totalHolders += generalStats.totalHolders;
@@ -219,13 +218,11 @@ export class StatsService implements OnModuleInit {
219218
const dailyData: Record<string, CachedHMTData> = {};
220219
const monthlyData: Record<string, CachedHMTData> = {};
221220

221+
const availableNetworks = await this.getAvailableNetworks();
222+
222223
// Fetch daily data for each network
223224
await Promise.all(
224-
(
225-
Object.values(MainnetsId).filter(
226-
(value) => typeof value === 'number',
227-
) as number[]
228-
).map(async (network) => {
225+
availableNetworks.map(async (network) => {
229226
const statisticsClient = new StatisticsClient(NETWORKS[network]);
230227
let skip = 0;
231228
let fetchedRecords: DailyHMTData[] = [];

0 commit comments

Comments
 (0)