Skip to content

Commit

Permalink
Rename registrations in exchange oracles (humanprotocol#2683)
Browse files Browse the repository at this point in the history
* Rename registrations in exchange oracles

* update variable to registrationInExchangeOracleError

* rename variable to isRegistrationInExchangeOraclePending
  • Loading branch information
portuu3 authored Oct 23, 2024
1 parent 4d2c963 commit fc60052
Show file tree
Hide file tree
Showing 34 changed files with 232 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { JwtAuthGuard } from '../../common/guards/jwt.auth';
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
export class UserController {
@Post('registration')
@Post('register')
@ApiOperation({
summary: 'Register a user in Exchange Oracle',
description: 'Endpoint to register a user in Exchange Oracle.',
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/human-app/frontend/src/api/api-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export const apiPaths = {
dailyHmtSpend: {
path: '/labeling/h-captcha/daily-hmt-spent',
},
userRegistration: {
path: '/registration',
registrationInExchangeOracle: {
path: '/exchange-oracle-registration',
},
},
operator: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ const RegisteredOraclesSuccessResponseSchema = z.object({
oracle_addresses: z.array(z.string()),
});

export async function getRegisteredOracles() {
return apiClient(apiPaths.worker.userRegistration.path, {
export async function getRegistrationInExchangeOracles() {
return apiClient(apiPaths.worker.registrationInExchangeOracle.path, {
authenticated: true,
successSchema: RegisteredOraclesSuccessResponseSchema,
options: { method: 'GET' },
});
}

export function useGetRegisteredOracles() {
export function useGetRegistrationInExchangeOracles() {
return useQuery({
queryFn: () => getRegisteredOracles(),
queryKey: ['getRegisteredOracles'],
queryFn: () => getRegistrationInExchangeOracles(),
queryKey: ['getRegistrationInExchangeOracles'],
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { t } from 'i18next';
import { apiClient } from '@/api/api-client';
import { apiPaths } from '@/api/api-paths';

export const registrationDtoSchema = z.object({
export const registrationInExchangeOracleDtoSchema = z.object({
oracle_address: z
.string()
.refine(
Expand All @@ -16,23 +16,27 @@ export const registrationDtoSchema = z.object({
h_captcha_token: z.string().min(1, t('validation.captcha')).default('token'),
});

export type RegistrationDto = z.infer<typeof registrationDtoSchema>;
export type RegistrationInExchangeOracleDto = z.infer<
typeof registrationInExchangeOracleDtoSchema
>;

const UserRegistrationSuccessResponseSchema = z.unknown();
const RegistrationInExchangeOracleSuccessResponseSchema = z.unknown();

function userRegistrationMutationFn(data: RegistrationDto) {
return apiClient(apiPaths.worker.userRegistration.path, {
function registrationInExchangeOracleMutationFn(
data: RegistrationInExchangeOracleDto
) {
return apiClient(apiPaths.worker.registrationInExchangeOracle.path, {
authenticated: true,
successSchema: UserRegistrationSuccessResponseSchema,
successSchema: RegistrationInExchangeOracleSuccessResponseSchema,
options: { method: 'POST', body: JSON.stringify(data) },
});
}

export function useUserRegistrationMutation() {
export function useExchangeOracleRegistrationMutation() {
const queryClient = useQueryClient();

return useMutation({
mutationFn: userRegistrationMutationFn,
mutationFn: registrationInExchangeOracleMutationFn,
onSuccess: async () => {
await queryClient.invalidateQueries();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export const operatorDrawerBottomMenuItems: BottomMenuItem[] = [
icon: <HelpIcon />,
onClick: () => {
// @ts-expect-error -- ...
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ...
if ($zoho?.salesiq?.chat?.start) {
// @ts-expect-error -- ...
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call -- ...
$zoho.salesiq.chat.start();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ export const workerDrawerBottomMenuItems: BottomMenuItem[] = [
icon: <HelpIcon />,
onClick: () => {
// @ts-expect-error -- ...
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ...
if ($zoho?.salesiq?.chat?.start) {
// @ts-expect-error -- ...
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call -- ...
$zoho.salesiq.chat.start();
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/human-app/frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"jobsDiscovery": "Tasks",
"hcaptchaLabeling": "Labeling",
"jobs": "Tasks",
"registration": "Registration"
"registrationInExchangeOracle": "Registration in Exchange Oracle"
},
"web3ProtectedPagesHeaders": {
"profile": "Profile"
Expand Down Expand Up @@ -211,7 +211,7 @@
"seeJobs": "See tasks",
"allJobs": "All tasks"
},
"registration": {
"registrationInExchangeOracle": {
"requiredMessage": "This oracle requires a registration process. Click on the link below to see the registration tutorial:",
"completeMessage": "Click on Complete once you have finished the registration process:",
"completeButton": "Complete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { createTableDarkMode } from '@/styles/create-table-dark-mode';
import { env } from '@/shared/env';
import { useAuthenticatedUser } from '@/auth/use-authenticated-user';
import { type JobType } from '@/smart-contracts/EthKVStore/config';
import { useGetRegisteredOracles } from '@/api/services/worker/registered-oracles';
import { useGetRegistrationInExchangeOracles } from '@/api/services/worker/get-registration-in-exchange-oracles';

const getColumns = (
selectOracle: (oracle: OracleSuccessResponse) => void
Expand Down Expand Up @@ -88,16 +88,19 @@ export function OraclesTable({
const navigate = useNavigate();
const isMobile = useIsMobile();
const { user } = useAuthenticatedUser();
const { data: registeredOraclesResults } = useGetRegisteredOracles();
const { data: registrationInExchangeOraclesResult } =
useGetRegistrationInExchangeOracles();

const selectOracle = (oracle: OracleSuccessResponse) => {
if (
oracle.registrationNeeded &&
!registeredOraclesResults?.oracle_addresses.find(
!registrationInExchangeOraclesResult?.oracle_addresses.find(
(address) => address === oracle.address
)
) {
navigate(`${routerPaths.worker.registration}/${oracle.address}`);
navigate(
`${routerPaths.worker.registrationInExchangeOracle}/${oracle.address}`
);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { FormCaptcha } from '@/components/h-captcha';
import { Button } from '@/components/ui/button';
import {
type RegistrationDto,
registrationDtoSchema,
useUserRegistrationMutation,
} from '@/api/services/worker/user-registration';
type RegistrationInExchangeOracleDto,
registrationInExchangeOracleDtoSchema,
useExchangeOracleRegistrationMutation,
} from '@/api/services/worker/registration-in-exchange-oracles';
import { useRegisteredOracles } from '@/contexts/registered-oracles';
import { useGetOracles } from '@/api/services/worker/oracles';
import { routerPaths } from '@/router/router-paths';
Expand All @@ -27,27 +27,29 @@ export function RegistrationPage() {

const { registeredOracles, setRegisteredOracles } = useRegisteredOracles();

const methods = useForm<RegistrationDto>({
const methods = useForm<RegistrationInExchangeOracleDto>({
defaultValues: {
// eslint-disable-next-line camelcase
oracle_address: oracleAddress,
// eslint-disable-next-line camelcase
h_captcha_token: '',
},
resolver: zodResolver(registrationDtoSchema),
resolver: zodResolver(registrationInExchangeOracleDtoSchema),
});

const {
mutate: userRegistrationMutate,
isPending: isUserRegistrationPending,
error: userRegistrationError,
} = useUserRegistrationMutation();
isPending: isRegistrationInExchangeOraclePending,
error: registrationInExchangeOracleError,
} = useExchangeOracleRegistrationMutation();

const handleLinkClick = () => {
setHasClickedRegistrationLink(true);
};

const handleRegistrationComplete = (data: RegistrationDto) => {
const handleRegistrationComplete = (
data: RegistrationInExchangeOracleDto
) => {
userRegistrationMutate(data, {
onSuccess(_data) {
if (oracleAddress !== undefined) {
Expand Down Expand Up @@ -99,7 +101,9 @@ export function RegistrationPage() {
}}
>
<Stack maxWidth="350px" spacing={2}>
<Box>{t('worker.registration.requiredMessage')}</Box>
<Box>
{t('worker.registrationInExchangeOracle.requiredMessage')}
</Box>
<Link
href={oracleData?.registrationInstructions ?? ''}
onClick={handleLinkClick}
Expand All @@ -109,7 +113,9 @@ export function RegistrationPage() {
>
{oracleData?.registrationInstructions}
</Link>
<Box>{t('worker.registration.completeMessage')}</Box>
<Box>
{t('worker.registrationInExchangeOracle.completeMessage')}
</Box>
<FormProvider {...methods}>
<form
onSubmit={(event) =>
Expand All @@ -118,17 +124,17 @@ export function RegistrationPage() {
>
<Stack alignItems="center" spacing={2}>
<FormCaptcha
error={userRegistrationError}
error={registrationInExchangeOracleError}
name="h_captcha_token"
/>
<Button
disabled={!hasClickedRegistrationLink}
fullWidth
loading={isUserRegistrationPending}
loading={isRegistrationInExchangeOraclePending}
type="submit"
variant="contained"
>
{t('worker.registration.completeButton')}
{t('worker.registrationInExchangeOracle.completeButton')}
</Button>
</Stack>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const routerPaths = {
jobs: '/worker/jobs',
HcaptchaLabeling: '/worker/hcaptcha-labeling',
enableLabeler: '/worker/enable-labeler',
registration: '/worker/registration',
registrationInExchangeOracle: '/worker/registration-in-exchange-oracle',
},
operator: {
signIn: '/operator/sign-in',
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/human-app/frontend/src/router/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ export const protectedRoutes: {
},
{
routerProps: {
path: `${routerPaths.worker.registration}/:address`,
path: `${routerPaths.worker.registrationInExchangeOracle}/:address`,
element: <RegistrationPage />,
},
pageHeaderProps: {
headerIcon: <HomepageWorkIcon />,
headerText: t('protectedPagesHeaders.registration'),
headerText: t('protectedPagesHeaders.registrationInExchangeOracle'),
},
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class GatewayConfigService {
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[ReputationOracleEndpoints.WORKER_REGISTRATION]: {
endpoint: '/user/registration',
[ReputationOracleEndpoints.REGISTRATION_IN_EXCHANGE_ORACLE]: {
endpoint: '/user/exchange-oracle-registration',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
Expand Down Expand Up @@ -105,8 +105,8 @@ export class GatewayConfigService {
method: HttpMethod.GET,
headers: this.JSON_HEADER,
},
[ReputationOracleEndpoints.GET_REGISTERED_ORACLES]: {
endpoint: '/user/registration',
[ReputationOracleEndpoints.GET_REGISTRATION_IN_EXCHANGE_ORACLES]: {
endpoint: '/user/exchange-oracle-registration',
method: HttpMethod.GET,
headers: this.JSON_HEADER,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const gatewayConfigServiceMock = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
WORKER_REGISTRATION: {
endpoint: '/user/registration',
REGISTRATION_IN_EXCHANGE_ORACLE: {
endpoint: '/user/exchange-oracle-registration',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum ReputationOracleEndpoints {
WORKER_SIGNUP = 'WORKER_SIGNUP',
WORKER_SIGNIN = 'WORKER_SIGNIN',
WORKER_REGISTRATION = 'WORKER_REGISTRATION',
REGISTRATION_IN_EXCHANGE_ORACLE = 'REGISTRATION_IN_EXCHANGE_ORACLE',
OPERATOR_SIGNUP = 'OPERATOR_SIGNUP',
OPERATOR_SIGNIN = 'OPERATOR_SIGNIN',
EMAIL_VERIFICATION = 'EMAIL_VERIFICATION',
Expand All @@ -15,7 +15,7 @@ export enum ReputationOracleEndpoints {
REGISTER_ADDRESS = 'REGISTER_ADDRESS',
TOKEN_REFRESH = 'TOKEN_REFRESH',
KYC_ON_CHAIN = 'KYC_ON_CHAIN',
GET_REGISTERED_ORACLES = 'GET_REGISTERED_ORACLES',
GET_REGISTRATION_IN_EXCHANGE_ORACLES = 'GET_REGISTRATION_IN_EXCHANGE_ORACLES',
}
export enum HCaptchaLabelingStatsEndpoints {
USER_STATS = 'USER_STATS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import { toCleanObjParams } from '../../common/utils/gateway-common.utils';
import { KvStoreGateway } from '../kv-store/kv-store.gateway';
import { EscrowUtilsGateway } from '../escrow/escrow-utils-gateway.service';
import {
WorkerRegistrationCommand,
WorkerRegistrationData,
RegistrationInExchangeOracleCommand,
RegistrationInExchangeOracleData,
} from '../../modules/user-worker/model/worker-registration.model';

@Injectable()
Expand Down Expand Up @@ -176,18 +176,20 @@ export class ExchangeOracleGateway {
return this.callExternalHttpUtilRequest<JobsDiscoveryResponse>(options);
}

async workerRegistration(command: WorkerRegistrationCommand) {
async sendRegistrationInExchangeOracle(
command: RegistrationInExchangeOracleCommand,
) {
const data = this.mapper.map(
command,
WorkerRegistrationCommand,
WorkerRegistrationData,
RegistrationInExchangeOracleCommand,
RegistrationInExchangeOracleData,
);

const options: AxiosRequestConfig = {
method: HttpMethod.POST,
url: `${await this.kvStoreGateway.getExchangeOracleUrlByAddress(
command.oracleAddress,
)}/registration`,
)}/register`,
data: data,
headers: {
Authorization: command.token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
JobsDiscoveryParamsData,
} from '../../modules/jobs-discovery/model/jobs-discovery.model';
import {
WorkerRegistrationCommand,
WorkerRegistrationData,
RegistrationInExchangeOracleCommand,
RegistrationInExchangeOracleData,
} from '../../modules/user-worker/model/worker-registration.model';

@Injectable()
Expand Down Expand Up @@ -94,8 +94,8 @@ export class ExchangeOracleProfile extends AutomapperProfile {
);
createMap(
mapper,
WorkerRegistrationCommand,
WorkerRegistrationData,
RegistrationInExchangeOracleCommand,
RegistrationInExchangeOracleData,
namingConventions({
source: new CamelCaseNamingConvention(),
destination: new SnakeCaseNamingConvention(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export const exchangeOracleGatewayMock = {
fetchAssignedJobs: jest.fn(),
postNewJobAssignment: jest.fn(),
fetchDiscoveredJobs: jest.fn(),
workerRegistration: jest.fn(),
sendRegistrationInExchangeOracle: jest.fn(),
};
Loading

0 comments on commit fc60052

Please sign in to comment.