-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathdapp.config.service.ts
More file actions
57 lines (47 loc) · 1.71 KB
/
dapp.config.service.ts
File metadata and controls
57 lines (47 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { FileUtils } from "@multiversx/sdk-nestjs-common";
import { Injectable } from "@nestjs/common";
import { ApiConfigService } from "src/common/api-config/api.config.service";
import { DappConfig } from "./entities/dapp-config";
import { GatewayService } from "src/common/gateway/gateway.service";
@Injectable()
export class DappConfigService {
private readonly dappConfig: DappConfig | undefined;
constructor(
private readonly apiConfigService: ApiConfigService,
private readonly gatewayService: GatewayService,
) {
this.dappConfig = this.getDappConfigurationRaw();
}
async getDappConfiguration(): Promise<DappConfig | undefined> {
if (!this.dappConfig) {
return undefined;
}
const networkConfig = await this.gatewayService.getNetworkConfig();
const refreshRate = networkConfig.erd_round_duration;
const chainId = networkConfig.erd_chain_id;
const overrides: Partial<DappConfig> = {};
//TODO: remove after battle of nodes
if (chainId === 'B') {
overrides.walletAddress = "https://bon-wallet.multiversx.com";
overrides.apiAddress = "https://api.battleofnodes.com";
overrides.explorerAddress = "https://bon-explorer.multiversx.com";
overrides.id = "bon";
overrides.name = "BattleOfNodes";
}
if (refreshRate != null) {
overrides.refreshRate = refreshRate;
}
if (chainId != null) {
overrides.chainId = chainId;
}
return {
...this.dappConfig,
...overrides,
};
}
getDappConfigurationRaw(): DappConfig | undefined {
const network = this.apiConfigService.getNetwork();
const configuration = FileUtils.parseJSONFile(`./config/dapp.config.${network}.json`);
return configuration;
}
}