Skip to content

Commit cd9f31b

Browse files
committed
refactor: chain id type
1 parent 76aecda commit cd9f31b

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

packages/apps/dashboard/server/src/common/constants/chains.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ import { ChainId as SdkChainId } from '@human-protocol/sdk';
22

33
import Environment from '../utils/environment';
44

5-
export enum ProductionChainId {
6-
POLYGON_MAINNET = SdkChainId.POLYGON,
7-
BSC_MAINNET = SdkChainId.BSC_MAINNET,
8-
ETHEREUM = SdkChainId.MAINNET,
9-
}
5+
export const ProductionChainId = {
6+
POLYGON_MAINNET: SdkChainId.POLYGON,
7+
BSC_MAINNET: SdkChainId.BSC_MAINNET,
8+
ETHEREUM: SdkChainId.MAINNET,
9+
} as const satisfies Record<string, SdkChainId>;
1010

11-
export enum DevelopmentChainId {
12-
POLYGON_AMOY = SdkChainId.POLYGON_AMOY,
13-
BSC_TESTNET = SdkChainId.BSC_TESTNET,
14-
SEPOLIA = SdkChainId.SEPOLIA,
15-
LOCALHOST = SdkChainId.LOCALHOST,
16-
}
11+
type ProductionChainId =
12+
(typeof ProductionChainId)[keyof typeof ProductionChainId];
13+
14+
export const DevelopmentChainId = {
15+
POLYGON_AMOY: SdkChainId.POLYGON_AMOY,
16+
BSC_TESTNET: SdkChainId.BSC_TESTNET,
17+
SEPOLIA: SdkChainId.SEPOLIA,
18+
LOCALHOST: SdkChainId.LOCALHOST,
19+
} as const satisfies Record<string, SdkChainId>;
20+
21+
type DevelopmentChainId =
22+
(typeof DevelopmentChainId)[keyof typeof DevelopmentChainId];
1723

1824
export const ChainIds = Object.values(
1925
Environment.isProduction() ? ProductionChainId : DevelopmentChainId,

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class DetailsService {
5959
if (!network) throw new BadRequestException('Invalid chainId provided');
6060
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
6161

62-
const escrowData = await EscrowUtils.getEscrow(chainId as number, address);
62+
const escrowData = await EscrowUtils.getEscrow(chainId, address);
6363
if (escrowData) {
6464
const escrowDto: EscrowDto = plainToInstance(EscrowDto, escrowData, {
6565
excludeExtraneousValues: true,
@@ -87,10 +87,7 @@ export class DetailsService {
8787
const stakingClient = await StakingClient.build(provider);
8888
const stakingData = await stakingClient.getStakerInfo(address);
8989

90-
const operatorData = await OperatorUtils.getOperator(
91-
chainId as number,
92-
address,
93-
);
90+
const operatorData = await OperatorUtils.getOperator(chainId, address);
9491
if (operatorData) {
9592
const operatorDto: OperatorDto = plainToInstance(
9693
OperatorDto,
@@ -118,7 +115,7 @@ export class DetailsService {
118115
return operatorDto;
119116
}
120117

121-
const workerData = await WorkerUtils.getWorker(chainId as number, address);
118+
const workerData = await WorkerUtils.getWorker(chainId, address);
122119

123120
const walletDto: WalletDto = plainToInstance(WalletDto, {
124121
chainId,
@@ -161,7 +158,7 @@ export class DetailsService {
161158
skip: number,
162159
): Promise<TransactionPaginationDto[]> {
163160
const transactions = await TransactionUtils.getTransactions({
164-
chainId: chainId as number,
161+
chainId,
165162
fromAddress: address,
166163
toAddress: address,
167164
first,
@@ -188,7 +185,7 @@ export class DetailsService {
188185
skip: number,
189186
): Promise<EscrowPaginationDto[]> {
190187
const filter: IEscrowsFilter = {
191-
chainId: chainId as number,
188+
chainId,
192189
first,
193190
skip,
194191
};
@@ -274,7 +271,7 @@ export class DetailsService {
274271
first?: number,
275272
): IOperatorsFilter {
276273
const operatorsFilter: IOperatorsFilter = {
277-
chainId: chainId as number,
274+
chainId,
278275
minStakedAmount: MIN_STAKED_AMOUNT,
279276
roles: [
280277
Role.JobLauncher,
@@ -429,10 +426,7 @@ export class DetailsService {
429426
chainId: ChainId,
430427
address: string,
431428
): Promise<KVStoreDataDto[]> {
432-
const kvStoreData = await KVStoreUtils.getKVStoreData(
433-
chainId as number,
434-
address,
435-
);
429+
const kvStoreData = await KVStoreUtils.getKVStoreData(chainId, address);
436430

437431
const data: KVStoreDataDto[] = kvStoreData.map((data: any) => {
438432
return plainToInstance(KVStoreDataDto, {

0 commit comments

Comments
 (0)