Skip to content

Commit 8ce20bb

Browse files
committed
Merge branch 'develop' of github.com:humanprotocol/human-protocol into kb/3161
2 parents f29952b + ef50fc6 commit 8ce20bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2577
-382
lines changed

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

Lines changed: 700 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { NetworkSelect } from '../../../components/NetworkSelect';
66
import { IS_MAINNET } from '../../../constants/chains';
77
import { useCreateJobPageUI } from '../../../providers/CreateJobPageUIProvider';
88
import { JobType, PayMethod } from '../../../types';
9+
import { AudinoJobRequestForm } from './AudinoJobRequestForm';
910
import { CvatJobRequestForm } from './CvatJobRequestForm';
1011
import { FortuneJobRequestForm } from './FortuneJobRequestForm';
1112
import { HCaptchaJobRequestForm } from './HCaptchaJobRequestForm';
@@ -62,12 +63,13 @@ export const CreateJob = () => {
6263
}
6364
>
6465
{!IS_MAINNET && (
65-
<MenuItem value={JobType.Fortune}>Fortune</MenuItem>
66+
<MenuItem value={JobType.FORTUNE}>Fortune</MenuItem>
6667
)}
6768
<MenuItem value={JobType.CVAT}>CVAT</MenuItem>
6869
{/* {!IS_MAINNET && (
6970
<MenuItem value={JobType.HCAPTCHA}>hCaptcha</MenuItem>
7071
)} */}
72+
{!IS_MAINNET && <MenuItem value={JobType.AUDINO}>Audino</MenuItem>}
7173
</Select>
7274
</FormControl>
7375
<NetworkSelect
@@ -81,9 +83,10 @@ export const CreateJob = () => {
8183
}
8284
/>
8385
</Box>
84-
{jobRequest.jobType === JobType.Fortune && <FortuneJobRequestForm />}
86+
{jobRequest.jobType === JobType.FORTUNE && <FortuneJobRequestForm />}
8587
{jobRequest.jobType === JobType.CVAT && <CvatJobRequestForm />}
8688
{jobRequest.jobType === JobType.HCAPTCHA && <HCaptchaJobRequestForm />}
89+
{jobRequest.jobType === JobType.AUDINO && <AudinoJobRequestForm />}
8790
</Box>
8891
);
8992
};

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ export const CryptoPayForm = ({
223223
fortuneRequest,
224224
cvatRequest,
225225
hCaptchaRequest,
226+
audinoRequest,
226227
} = jobRequest;
227-
if (jobType === JobType.Fortune && fortuneRequest) {
228+
if (jobType === JobType.FORTUNE && fortuneRequest) {
228229
await jobService.createFortuneJob(
229230
chainId,
230231
fortuneRequest,
@@ -242,6 +243,14 @@ export const CryptoPayForm = ({
242243
);
243244
} else if (jobType === JobType.HCAPTCHA && hCaptchaRequest) {
244245
await jobService.createHCaptchaJob(chainId, hCaptchaRequest);
246+
} else if (jobType === JobType.AUDINO && audinoRequest) {
247+
await jobService.createAudinoJob(
248+
chainId,
249+
audinoRequest,
250+
paymentTokenSymbol,
251+
Number(amount),
252+
fundTokenSymbol,
253+
);
245254
}
246255
onFinish();
247256
} catch (err) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,9 @@ export const CvatJobRequestForm = () => {
718718
</MenuItem>
719719
))}
720720
</Select>
721-
{errors.dataRegion && (
721+
{errors.gtRegion && (
722722
<FormHelperText sx={{ mx: '14px', mt: '3px' }} error>
723-
{errors.dataRegion}
723+
{errors.gtRegion}
724724
</FormHelperText>
725725
)}
726726
</FormControl>

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { CURRENCY } from '../../../constants/payment';
2929
import { useCreateJobPageUI } from '../../../providers/CreateJobPageUIProvider';
3030
import { useSnackbar } from '../../../providers/SnackProvider';
3131
import {
32+
createAudinoJob,
3233
createCvatJob,
3334
createFortuneJob,
3435
createHCaptchaJob,
@@ -248,11 +249,17 @@ export const FiatPayForm = ({
248249
}
249250

250251
// create job
251-
const { jobType, chainId, fortuneRequest, cvatRequest, hCaptchaRequest } =
252-
jobRequest;
252+
const {
253+
jobType,
254+
chainId,
255+
fortuneRequest,
256+
cvatRequest,
257+
hCaptchaRequest,
258+
audinoRequest,
259+
} = jobRequest;
253260
if (!chainId) return;
254261

255-
if (jobType === JobType.Fortune && fortuneRequest) {
262+
if (jobType === JobType.FORTUNE && fortuneRequest) {
256263
await createFortuneJob(
257264
chainId,
258265
fortuneRequest,
@@ -270,6 +277,14 @@ export const FiatPayForm = ({
270277
);
271278
} else if (jobType === JobType.HCAPTCHA && hCaptchaRequest) {
272279
await createHCaptchaJob(chainId, hCaptchaRequest);
280+
} else if (jobType === JobType.AUDINO && audinoRequest) {
281+
await createAudinoJob(
282+
chainId,
283+
audinoRequest,
284+
CURRENCY.usd,
285+
amount,
286+
tokenSymbol,
287+
);
273288
}
274289

275290
// Update balance and finish payment

packages/apps/job-launcher/client/src/components/Jobs/Create/helpers.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
StorageProviders,
66
GCSRegions,
77
AWSRegions,
8+
AudinoJobType,
89
} from '../../../types';
910

1011
export const mapCvatFormValues = (
@@ -67,3 +68,40 @@ export const mapFortuneFormValues = (
6768
: [],
6869
};
6970
};
71+
72+
export const mapAudinoFormValues = (
73+
jobRequest: JobRequest,
74+
qualificationsOptions: Qualification[],
75+
) => {
76+
const { audinoRequest } = jobRequest;
77+
78+
return {
79+
type: audinoRequest?.type || AudinoJobType.AUDIO_TRANSCRIPTION,
80+
labels: audinoRequest?.labels?.map((label) => label.name) || [],
81+
description: audinoRequest?.description || '',
82+
qualifications: audinoRequest?.qualifications
83+
? qualificationsOptions.filter((q: Qualification) =>
84+
audinoRequest?.qualifications?.includes(q.reference),
85+
)
86+
: [],
87+
88+
dataProvider:
89+
audinoRequest?.data?.dataset?.provider || StorageProviders.AWS,
90+
dataRegion:
91+
(audinoRequest?.data?.dataset?.region as AWSRegions | GCSRegions) || '',
92+
dataBucketName: audinoRequest?.data?.dataset?.bucketName || '',
93+
dataPath: audinoRequest?.data?.dataset?.path || '',
94+
95+
gtProvider: audinoRequest?.groundTruth?.provider || StorageProviders.AWS,
96+
gtRegion:
97+
(audinoRequest?.groundTruth?.region as AWSRegions | GCSRegions) || '',
98+
gtBucketName: audinoRequest?.groundTruth?.bucketName || '',
99+
gtPath: audinoRequest?.groundTruth?.path || '',
100+
101+
userGuide: audinoRequest?.userGuide || '',
102+
accuracyTarget: audinoRequest?.accuracyTarget || 50,
103+
104+
audioDuration: audinoRequest?.audioDuration || 0,
105+
segmentDuration: audinoRequest?.segmentDuration || 0,
106+
};
107+
};

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@ import { FundingMethod } from './FundingMethod';
88
import { LaunchSuccess } from './LaunchSuccess';
99
import { PayJob } from './PayJob';
1010

11+
const supportedJobTypes = Object.values(JobType);
12+
13+
function isSupportedJobType(jobType: string): jobType is JobType {
14+
return supportedJobTypes.includes(jobType as JobType);
15+
}
16+
1117
export const CreateJobView = () => {
1218
const { step, changePayMethod, setStep, updateJobRequest } =
1319
useCreateJobPageUI();
1420
const [searchParams] = useSearchParams();
1521

1622
useEffect(() => {
17-
const jobType = searchParams.get('jobType');
18-
const supportedJobTypes = ['fortune', 'cvat', 'hcaptcha'];
23+
const jobType = searchParams.get('jobType') || '';
1924

20-
if (jobType && supportedJobTypes.includes(jobType.toLowerCase())) {
25+
if (isSupportedJobType(jobType)) {
2126
changePayMethod(PayMethod.Fiat);
2227
setStep(CreateJobStep.CreateJob);
2328

24-
updateJobRequest({
25-
jobType:
26-
jobType === 'fortune'
27-
? JobType.Fortune
28-
: jobType === 'cvat'
29-
? JobType.CVAT
30-
: JobType.HCAPTCHA,
31-
});
29+
updateJobRequest({ jobType });
3230
}
3331
// eslint-disable-next-line react-hooks/exhaustive-deps
3432
}, []);

packages/apps/job-launcher/client/src/components/Jobs/Create/schema.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,38 @@ export const HCaptchaJobRequesteValidationSchema = Yup.object().shape({
8989
images: Yup.array().of(Yup.string().url('Invalid Image URL')),
9090
qualifications: Yup.array().of(Yup.object()),
9191
});
92+
93+
export const AudinoJobRequestValidationSchema = Yup.object().shape({
94+
labels: Yup.array().of(Yup.string()).min(1, 'At least one label is required'),
95+
description: Yup.string().required('Description is required'),
96+
dataProvider: Yup.string().required('Provider is required'),
97+
dataRegion: Yup.string().required('Region is required'),
98+
dataBucketName: Yup.string().required('Bucket name is required'),
99+
dataPath: Yup.string().optional(),
100+
gtProvider: Yup.string().required('Provider is required'),
101+
gtRegion: Yup.string().required('Region is required'),
102+
gtBucketName: Yup.string().required('Bucket name is required'),
103+
gtPath: Yup.string().optional(),
104+
userGuide: Yup.string()
105+
.required('User Guide URL is required')
106+
.url('Invalid URL'),
107+
accuracyTarget: Yup.number()
108+
.required('Accuracy target is required')
109+
.moreThan(0, 'Accuracy target must be greater than 0')
110+
.max(100, 'Accuracy target must be less than or equal to 100'),
111+
qualifications: Yup.array().of(Yup.object()),
112+
113+
audioDuration: Yup.number()
114+
.required('Audio duration is required')
115+
.moreThan(0, 'Audio duration must be greater than 0')
116+
.max(31536000, 'Audio duration must be less than or equal to 31536000'), // one year in seconds
117+
segmentDuration: Yup.number()
118+
.required('Segment duration is required')
119+
.moreThan(0, 'Segment duration must be greater than 0')
120+
.when('$audioDuration', ([audioDuration], schema) => {
121+
return schema.max(
122+
audioDuration * 1000,
123+
'Segment duration should not exceed audio duration',
124+
);
125+
}),
126+
});

packages/apps/job-launcher/client/src/providers/CreateJobPageUIProvider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const initialData: CreateJobPageUIType = {
2020
step: CreateJobStep.FundingMethod,
2121
payMethod: PayMethod.Crypto,
2222
jobRequest: {
23-
jobType: JobType.Fortune,
23+
jobType: JobType.FORTUNE,
2424
chainId: undefined,
2525
},
2626
reset: () => {},
@@ -45,7 +45,7 @@ export const CreateJobPageUIProvider = ({
4545
const [step, setStep] = useState<CreateJobStep>(CreateJobStep.FundingMethod);
4646
const [payMethod, setPayMethod] = useState<PayMethod>(PayMethod.Crypto);
4747
const [jobRequest, setJobRequest] = useState<JobRequest>({
48-
jobType: IS_MAINNET ? JobType.CVAT : JobType.Fortune,
48+
jobType: IS_MAINNET ? JobType.CVAT : JobType.FORTUNE,
4949
chainId:
5050
chain?.id && SUPPORTED_CHAIN_IDS.includes(chain?.id)
5151
? chain?.id
@@ -77,7 +77,7 @@ export const CreateJobPageUIProvider = ({
7777
setStep(CreateJobStep.FundingMethod);
7878
setPayMethod(PayMethod.Crypto);
7979
setJobRequest({
80-
jobType: JobType.Fortune,
80+
jobType: JobType.FORTUNE,
8181
});
8282
};
8383

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
JobDetailsResponse,
99
HCaptchaRequest,
1010
FortuneFinalResult,
11+
AudinoRequest,
12+
CreateAudinoJobRequest,
1113
} from '../types';
1214
import api from '../utils/api';
1315
import { getFilenameFromContentDisposition } from '../utils/string';
@@ -66,6 +68,33 @@ export const createHCaptchaJob = async (
6668
});
6769
};
6870

71+
export const createAudinoJob = async (
72+
chainId: number,
73+
data: AudinoRequest,
74+
paymentCurrency: string,
75+
paymentAmount: number | string,
76+
escrowFundToken: string,
77+
) => {
78+
const body: CreateAudinoJobRequest = {
79+
chainId,
80+
requesterDescription: data.description,
81+
paymentCurrency,
82+
paymentAmount: Number(paymentAmount),
83+
escrowFundToken,
84+
data: data.data,
85+
labels: data.labels,
86+
minQuality: Number(data.accuracyTarget) / 100,
87+
groundTruth: data.groundTruth,
88+
userGuide: data.userGuide,
89+
type: data.type,
90+
qualifications: data.qualifications,
91+
audioDuration: Number(data.audioDuration),
92+
segmentDuration: Number(data.segmentDuration),
93+
};
94+
95+
await api.post('/job/audino', body);
96+
};
97+
6998
export const getJobList = async ({
7099
chainId = ChainId.ALL,
71100
status,

0 commit comments

Comments
 (0)