Skip to content

Commit 7227ea8

Browse files
author
flopez7
committed
Refactor job creation logic to remove fortune fundAmount from JL client and add it into JL server
1 parent 74e2cec commit 7227ea8

6 files changed

Lines changed: 45 additions & 28 deletions

File tree

packages/apps/job-launcher/client/src/components/Jobs/Create/CryptoPayForm.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export const CryptoPayForm = ({
226226
paymentTokenSymbol,
227227
Number(amount),
228228
fundTokenSymbol,
229-
fundAmount,
230229
);
231230
} else if (jobType === JobType.CVAT && cvatRequest) {
232231
await jobService.createCvatJob(

packages/apps/job-launcher/client/src/components/Jobs/Create/FiatPayForm.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ export const FiatPayForm = ({
253253
CURRENCY.usd,
254254
amount,
255255
tokenSymbol,
256-
fundAmount,
257256
);
258257
} else if (jobType === JobType.CVAT && cvatRequest) {
259258
await createCvatJob(

packages/apps/job-launcher/client/src/services/job.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ import {
1515
import api from '../utils/api';
1616
import { getFilenameFromContentDisposition } from '../utils/string';
1717

18-
const buildFortuneManifest = (
19-
data: FortuneRequest,
20-
fundAmount: number,
21-
): FortuneManifest => ({
18+
const buildFortuneManifest = (data: FortuneRequest): FortuneManifest => ({
2219
submissionsRequired: Number(data.fortunesRequested),
2320
requesterTitle: data.title,
2421
requesterDescription: data.description,
25-
fundAmount,
2622
requestType: JobType.FORTUNE,
2723
qualifications: data.qualifications,
2824
});
@@ -76,7 +72,6 @@ export const createFortuneJob = async (
7672
paymentCurrency: string,
7773
paymentAmount: number | string,
7874
escrowFundToken: string,
79-
fundAmount: number,
8075
) => {
8176
const body: CreateJobRequest<FortuneManifest> = {
8277
chainId,
@@ -85,7 +80,7 @@ export const createFortuneJob = async (
8580
paymentAmount: Number(paymentAmount),
8681
escrowFundToken,
8782
qualifications: data.qualifications,
88-
manifest: buildFortuneManifest(data, fundAmount),
83+
manifest: buildFortuneManifest(data),
8984
};
9085
await api.post('/job', body);
9186
};

packages/apps/job-launcher/client/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type FortuneManifest = {
4343
submissionsRequired: number;
4444
requesterTitle: string;
4545
requesterDescription: string;
46-
fundAmount: number;
46+
fundAmount?: number;
4747
requestType: JobType.FORTUNE;
4848
qualifications?: string[];
4949
};

packages/apps/job-launcher/server/src/modules/job/job.service.spec.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ describe('JobService', () => {
148148
const jobManifestDto: JobManifestDto = createJobManifestDto({
149149
paymentCurrency: PaymentCurrency.USDC,
150150
escrowFundToken: EscrowFundToken.USDC,
151+
manifest: createMockFortuneManifest({
152+
fundAmount: undefined as unknown as number,
153+
}),
151154
});
152155
const fundTokenDecimals = getTokenDecimals(
153156
jobManifestDto.chainId!,
@@ -179,6 +182,10 @@ describe('JobService', () => {
179182
mul(div(1, 100), jobManifestDto.paymentAmount),
180183
).toFixed(18),
181184
);
185+
const expectedManifest = {
186+
...jobManifestDto.manifest,
187+
fundAmount: jobManifestDto.paymentAmount,
188+
};
182189

183190
expect(result).toBe(jobEntityMock.id);
184191
expect(mockWeb3Service.validateChainId).toHaveBeenCalledWith(
@@ -194,11 +201,11 @@ describe('JobService', () => {
194201
);
195202
expect(mockManifestService.validateManifest).toHaveBeenCalledWith(
196203
FortuneJobType.FORTUNE,
197-
jobManifestDto.manifest,
204+
expectedManifest,
198205
);
199206
expect(mockManifestService.uploadManifest).toHaveBeenCalledWith(
200207
jobManifestDto.chainId,
201-
jobManifestDto.manifest,
208+
expectedManifest,
202209
[
203210
jobManifestDto.exchangeOracle,
204211
jobManifestDto.reputationOracle,
@@ -238,6 +245,9 @@ describe('JobService', () => {
238245
const jobManifestDto: JobManifestDto = createJobManifestDto({
239246
paymentCurrency: PaymentCurrency.USD,
240247
escrowFundToken: EscrowFundToken.USDC,
248+
manifest: createMockFortuneManifest({
249+
fundAmount: undefined,
250+
}),
241251
});
242252

243253
const fundTokenDecimals = getTokenDecimals(
@@ -270,6 +280,16 @@ describe('JobService', () => {
270280
mul(div(1, 100), jobManifestDto.paymentAmount),
271281
).toFixed(18),
272282
);
283+
const expectedFundAmount = Number(
284+
mul(
285+
mul(jobManifestDto.paymentAmount, tokenToUsdRate),
286+
usdToTokenRate,
287+
).toFixed(6),
288+
);
289+
const expectedManifest = {
290+
...jobManifestDto.manifest,
291+
fundAmount: expectedFundAmount,
292+
};
273293

274294
expect(result).toBe(jobEntityMock.id);
275295

@@ -286,11 +306,11 @@ describe('JobService', () => {
286306
);
287307
expect(mockManifestService.validateManifest).toHaveBeenCalledWith(
288308
FortuneJobType.FORTUNE,
289-
jobManifestDto.manifest,
309+
expectedManifest,
290310
);
291311
expect(mockManifestService.uploadManifest).toHaveBeenCalledWith(
292312
jobManifestDto.chainId,
293-
jobManifestDto.manifest,
313+
expectedManifest,
294314
[
295315
jobManifestDto.exchangeOracle,
296316
jobManifestDto.reputationOracle,
@@ -315,12 +335,7 @@ describe('JobService', () => {
315335
usdToTokenRate,
316336
).toFixed(fundTokenDecimals),
317337
),
318-
fundAmount: Number(
319-
mul(
320-
mul(jobManifestDto.paymentAmount, tokenToUsdRate),
321-
usdToTokenRate,
322-
).toFixed(6),
323-
),
338+
fundAmount: expectedFundAmount,
324339
status: JobStatus.PAID,
325340
waitUntil: expect.any(Date),
326341
token: jobManifestDto.escrowFundToken,
@@ -338,6 +353,9 @@ describe('JobService', () => {
338353
exchangeOracle: null,
339354
recordingOracle: null,
340355
reputationOracle: null,
356+
manifest: createMockFortuneManifest({
357+
fundAmount: undefined,
358+
}),
341359
});
342360

343361
const fundTokenDecimals = getTokenDecimals(
@@ -379,6 +397,10 @@ describe('JobService', () => {
379397
mul(div(1, 100), jobManifestDto.paymentAmount),
380398
).toFixed(18),
381399
);
400+
const expectedManifest = {
401+
...jobManifestDto.manifest,
402+
fundAmount: jobManifestDto.paymentAmount,
403+
};
382404

383405
expect(result).toBe(jobEntityMock.id);
384406

@@ -394,11 +416,11 @@ describe('JobService', () => {
394416
).not.toHaveBeenCalled();
395417
expect(mockManifestService.validateManifest).toHaveBeenCalledWith(
396418
FortuneJobType.FORTUNE,
397-
jobManifestDto.manifest,
419+
expectedManifest,
398420
);
399421
expect(mockManifestService.uploadManifest).toHaveBeenCalledWith(
400422
jobManifestDto.chainId,
401-
jobManifestDto.manifest,
423+
expectedManifest,
402424
[
403425
mockOracles.exchangeOracle,
404426
mockOracles.reputationOracle,
@@ -593,10 +615,7 @@ describe('JobService', () => {
593615
jobQuickLaunchDto.exchangeOracle,
594616
jobQuickLaunchDto.recordingOracle,
595617
);
596-
expect(mockManifestService.downloadManifest).toHaveBeenCalledWith(
597-
jobQuickLaunchDto.manifestUrl,
598-
HCaptchaJobType.HCAPTCHA,
599-
);
618+
expect(mockManifestService.downloadManifest).not.toHaveBeenCalled();
600619
expect(mockManifestService.validateManifest).not.toHaveBeenCalled();
601620
expect(mockManifestService.uploadManifest).not.toHaveBeenCalled();
602621
expect(mockPaymentService.createWithdrawalPayment).toHaveBeenCalledWith(

packages/apps/job-launcher/server/src/modules/job/job.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,16 @@ export class JobService {
249249

250250
jobEntity.manifestUrl = dto.manifestUrl;
251251
} else if ('manifest' in dto) {
252-
await this.manifestService.validateManifest(requestType, dto.manifest);
252+
const manifest = dto.manifest;
253+
if (requestType === FortuneJobType.FORTUNE) {
254+
(manifest as FortuneManifestDto).fundAmount = fundTokenAmount;
255+
}
256+
257+
await this.manifestService.validateManifest(requestType, manifest);
253258

254259
const { url, hash } = await this.manifestService.uploadManifest(
255260
chainId,
256-
dto.manifest,
261+
manifest,
257262
[exchangeOracle, reputationOracle, recordingOracle],
258263
);
259264

0 commit comments

Comments
 (0)