Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(human-app): add first oracle from envs #13

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/apps/human-app/frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ VITE_DAPP_META_URL= #string
# Dapp icons for wallet connect
VITE_DAPP_ICONS= #string => lists of icons eg.: icon1,icon2...

# This data will be use to add first oracle in the oracles table
# string
VITE_H_CAPTCHA_ORACLE_ANNOTATION_TOOL=
# string
VITE_H_CAPTCHA_ORACLE_ROLE=
# string
VITE_H_CAPTCHA_ORACLE_ADDRESS=
# job types list string
VITE_H_CAPTCHA_ORACLE_TASK_TYPES= #string => lists of job types eg.: Image labeling, BBoxes...

# network if network is equl to 'testnet' app will use first tesntet chain from .src/smart-contracts/chains.ts
# and first mainnet chain for 'mainnet'
VITE_NETWORK= # mainnet|testnet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { apiClient } from '@/api/api-client';
import { apiPaths } from '@/api/api-paths';
import { useJobsTypesOraclesFilter } from '@/hooks/use-job-types-oracles-table';
import { stringifyUrlQueryObject } from '@/shared/helpers/stringify-url-query-object';
import { env } from '@/shared/env';

const OracleSuccessSchema = z.object({
address: z.string(),
Expand All @@ -18,6 +19,13 @@ const OraclesSuccessSchema = z.array(OracleSuccessSchema);
export type OracleSuccessResponse = z.infer<typeof OracleSuccessSchema>;
export type OraclesSuccessResponse = OracleSuccessResponse[];

const H_CAPTCHA_ORACLE: OracleSuccessResponse = {
address: env.VITE_H_CAPTCHA_ORACLE_ADDRESS,
jobTypes: env.VITE_H_CAPTCHA_ORACLE_TASK_TYPES,
role: env.VITE_H_CAPTCHA_ORACLE_ROLE,
url: env.VITE_H_CAPTCHA_ORACLE_ANNOTATION_TOOL,
};

export async function getOracles({
selected_job_types,
}: {
Expand All @@ -27,10 +35,17 @@ export async function getOracles({
? `?${stringifyUrlQueryObject({ selected_job_types })}`
: '';

return apiClient(`${apiPaths.worker.oracles.path}${queryParams}`, {
successSchema: OraclesSuccessSchema,
options: { method: 'GET' },
});
const result = await apiClient(
`${apiPaths.worker.oracles.path}${queryParams}`,
{
successSchema: OraclesSuccessSchema,
options: { method: 'GET' },
}
);

result.unshift(H_CAPTCHA_ORACLE);

return result;
}

export function useGetOracles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TableButton } from '@/components/ui/table-button';
import { routerPaths } from '@/router/router-paths';
import { OraclesTableMobile } from '@/pages/worker/jobs-discovery/oracles-table/oracles-table-mobile';
import type { OraclesDataQueryResult } from '@/pages/worker/jobs-discovery/jobs-discovery.page';
import { env } from '@/shared/env';

const getColumns = (
selectOracle: (oracleAddress: string) => void
Expand Down Expand Up @@ -77,6 +78,10 @@ export function OraclesTable({
const navigate = useNavigate();
const isMobile = useIsMobile();
const selectOracle = (oracleAddress: string) => {
if (oracleAddress === env.VITE_H_CAPTCHA_ORACLE_ADDRESS) {
navigate(routerPaths.worker.HcaptchaLabeling);
return;
}
navigate(`${routerPaths.worker.jobs}/${oracleAddress}`);
};

Expand Down
7 changes: 7 additions & 0 deletions packages/apps/human-app/frontend/src/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const envSchema = z.object({
return iconsArray;
}),
VITE_NETWORK: z.enum(['mainnet', 'testnet']),
VITE_H_CAPTCHA_ORACLE_ANNOTATION_TOOL: z.string(),
VITE_H_CAPTCHA_ORACLE_ROLE: z.string(),
VITE_H_CAPTCHA_ORACLE_ADDRESS: z.string(),
VITE_H_CAPTCHA_ORACLE_TASK_TYPES: z.string().transform((value) => {
const jobTypesArray = value.split(',');
return jobTypesArray;
}),
});

let validEnvs;
Expand Down
Loading