Skip to content

Commit 3df929f

Browse files
committed
add stake configuration endpoint
1 parent 64664db commit 3df929f

15 files changed

Lines changed: 126 additions & 32 deletions

File tree

packages/apps/human-app/server/src/common/config/gateway-config.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ export class GatewayConfigService {
166166
method: HttpMethod.GET,
167167
headers: this.JSON_HEADER,
168168
},
169+
[ReputationOracleEndpoints.STAKE_CONFIG]: {
170+
endpoint: '/staking/config',
171+
method: HttpMethod.GET,
172+
headers: this.JSON_HEADER,
173+
},
169174
} as Record<ReputationOracleEndpoints, GatewayEndpointConfig>,
170175
},
171176
[ExternalApiName.HCAPTCHA_LABELING_STATS]: {

packages/apps/human-app/server/src/common/enums/reputation-oracle-endpoints.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export enum ReputationOracleEndpoints {
2727
EXCHANGE_API_KEYS_RETRIEVE = 'exchange_api_keys_retrieve',
2828
EXCHANGE_API_KEYS_SUPPORTED_EXCHANGES = 'exchange_api_keys_supported_exchanges',
2929
STAKE_SUMMARY = 'stake_summary',
30+
STAKE_CONFIG = 'stake_config',
3031
}
3132
export enum HCaptchaLabelingStatsEndpoints {
3233
USER_STATS = 'user_stats',

packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.gateway.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ import {
102102
RetrieveExchangeApiKeysResponse,
103103
SupportedExchangeResponse,
104104
} from '../../modules/exchange-api-keys/model/exchange-api-keys.model';
105-
import { StakeSummaryResponse } from '../../modules/staking/model/staking.model';
105+
import {
106+
StakeConfigResponse,
107+
StakeSummaryResponse,
108+
} from '../../modules/staking/model/staking.model';
106109

107110
@Injectable()
108111
export class ReputationOracleGateway {
@@ -194,6 +197,15 @@ export class ReputationOracleGateway {
194197
return this.handleRequestToReputationOracle<StakeSummaryResponse>(options);
195198
}
196199

200+
async getStakeConfig(token: string): Promise<StakeConfigResponse> {
201+
const options = this.getEndpointOptions(
202+
ReputationOracleEndpoints.STAKE_CONFIG,
203+
undefined,
204+
token,
205+
);
206+
return this.handleRequestToReputationOracle<StakeConfigResponse>(options);
207+
}
208+
197209
async supportedExchanges(
198210
token: string,
199211
): Promise<SupportedExchangeResponse[]> {

packages/apps/human-app/server/src/modules/staking/model/staking.model.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ export class StakeSummaryResponse {
1010
@AutoMap()
1111
onChainStake: number;
1212

13-
@ApiProperty({ name: 'min_threshold' })
14-
@AutoMap()
15-
minThreshold: number;
16-
17-
@ApiProperty({ name: 'eligibility_enabled' })
18-
@AutoMap()
19-
eligibilityEnabled: boolean;
20-
2113
@ApiProperty({ name: 'exchange_error', required: false, nullable: true })
2214
@AutoMap()
2315
exchangeError?: string;
@@ -26,3 +18,13 @@ export class StakeSummaryResponse {
2618
@AutoMap()
2719
onChainError?: string;
2820
}
21+
22+
export class StakeConfigResponse {
23+
@ApiProperty({ name: 'min_threshold' })
24+
@AutoMap()
25+
minThreshold: number;
26+
27+
@ApiProperty({ name: 'eligibility_enabled' })
28+
@AutoMap()
29+
eligibilityEnabled: boolean;
30+
}

packages/apps/human-app/server/src/modules/staking/spec/staking.controller.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,13 @@ describe('StakingController', () => {
4747
expect(result).toEqual(stakingServiceMock.getStakeSummary(TOKEN));
4848
});
4949
});
50+
51+
describe('getStakeConfig', () => {
52+
it('should call service.getStakeConfig with token and return response', async () => {
53+
const req: RequestWithUser = { token: TOKEN } as RequestWithUser;
54+
const result = await controller.getStakeConfig(req);
55+
expect(service.getStakeConfig).toHaveBeenCalledWith(TOKEN);
56+
expect(result).toEqual(stakingServiceMock.getStakeConfig(TOKEN));
57+
});
58+
});
5059
});
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
export const TOKEN = 'test_user_token';
22

33
export const stakeSummaryResponseFixture = {
4-
exchangeStake: 1000,
5-
onChainStake: 500,
6-
minThreshold: 1000,
4+
exchangeStake: '1000',
5+
onChainStake: '500',
6+
};
7+
8+
export const stakeConfigResponseFixture = {
9+
minThreshold: '1000',
710
eligibilityEnabled: true,
811
};
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { stakeSummaryResponseFixture } from './staking.fixtures';
1+
import {
2+
stakeConfigResponseFixture,
3+
stakeSummaryResponseFixture,
4+
} from './staking.fixtures';
25

36
export const stakingServiceMock = {
47
getStakeSummary: jest.fn().mockReturnValue(stakeSummaryResponseFixture),
8+
getStakeConfig: jest.fn().mockReturnValue(stakeConfigResponseFixture),
59
};

packages/apps/human-app/server/src/modules/staking/spec/staking.service.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { ReputationOracleGateway } from '../../../integrations/reputation-oracle/reputation-oracle.gateway';
33
import { StakingService } from '../staking.service';
4-
import { stakeSummaryResponseFixture, TOKEN } from './staking.fixtures';
4+
import {
5+
stakeConfigResponseFixture,
6+
stakeSummaryResponseFixture,
7+
TOKEN,
8+
} from './staking.fixtures';
59

610
describe('StakingService', () => {
711
let service: StakingService;
@@ -10,6 +14,7 @@ describe('StakingService', () => {
1014
beforeEach(async () => {
1115
reputationOracleMock = {
1216
getStakeSummary: jest.fn(),
17+
getStakeConfig: jest.fn(),
1318
};
1419

1520
const module: TestingModule = await Test.createTestingModule({
@@ -36,4 +41,15 @@ describe('StakingService', () => {
3641
expect(result).toEqual(stakeSummaryResponseFixture);
3742
});
3843
});
44+
45+
describe('getStakeConfig', () => {
46+
it('should retrieve stake config', async () => {
47+
(reputationOracleMock.getStakeConfig as jest.Mock).mockResolvedValue(
48+
stakeConfigResponseFixture,
49+
);
50+
const result = await service.getStakeConfig(TOKEN);
51+
expect(reputationOracleMock.getStakeConfig).toHaveBeenCalledWith(TOKEN);
52+
expect(result).toEqual(stakeConfigResponseFixture);
53+
});
54+
});
3955
});

packages/apps/human-app/server/src/modules/staking/staking.controller.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { Controller, Get, Request } from '@nestjs/common';
44
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
55
import { RequestWithUser } from '../../common/interfaces/jwt';
66
import { StakingService } from './staking.service';
7-
import { StakeSummaryResponse } from './model/staking.model';
7+
import {
8+
StakeConfigResponse,
9+
StakeSummaryResponse,
10+
} from './model/staking.model';
811

912
@ApiTags('Staking')
1013
@ApiBearerAuth()
@@ -22,4 +25,12 @@ export class StakingController {
2225
): Promise<StakeSummaryResponse> {
2326
return this.service.getStakeSummary(req.token);
2427
}
28+
29+
@ApiOperation({ summary: 'Get staking configuration' })
30+
@Get('/config')
31+
async getStakeConfig(
32+
@Request() req: RequestWithUser,
33+
): Promise<StakeConfigResponse> {
34+
return this.service.getStakeConfig(req.token);
35+
}
2536
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Injectable } from '@nestjs/common';
22
import { ReputationOracleGateway } from '../../integrations/reputation-oracle/reputation-oracle.gateway';
3-
import { StakeSummaryResponse } from './model/staking.model';
3+
import {
4+
StakeConfigResponse,
5+
StakeSummaryResponse,
6+
} from './model/staking.model';
47

58
@Injectable()
69
export class StakingService {
@@ -9,4 +12,8 @@ export class StakingService {
912
getStakeSummary(token: string): Promise<StakeSummaryResponse> {
1013
return this.reputationOracle.getStakeSummary(token);
1114
}
15+
16+
getStakeConfig(token: string): Promise<StakeConfigResponse> {
17+
return this.reputationOracle.getStakeConfig(token);
18+
}
1219
}

0 commit comments

Comments
 (0)