Skip to content

Commit

Permalink
Rename Leader to Operator to unify the name
Browse files Browse the repository at this point in the history
  • Loading branch information
flopez7 committed Jan 31, 2025
1 parent 0ebfaf8 commit e936002
Show file tree
Hide file tree
Showing 60 changed files with 1,012 additions and 953 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import HumanAppIcon from '@assets/icons/human-app.svg';
import JobLauncherIcon from '@assets/icons/job-launcher.svg';
import RecordingOracleIcon from '@assets/icons/recording-oracle.svg';
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
import { AddressDetailsLeader, Roles } from '@services/api/use-address-details';
import {
AddressDetailsOperator,
Roles,
} from '@services/api/use-address-details';
import { getNetwork } from '@utils/config/networks';
import { useWalletSearch } from '@utils/hooks/use-wallet-search';
import { RoleDetailsEscrowsTable } from '@pages/SearchResults/RoleDetails/RoleDetailsEscrows/RoleDetailsEscrowsTable';
Expand Down Expand Up @@ -48,7 +51,7 @@ const RoleInformation = ({ title, points }: RoleInfoProps) => {
const RenderRoleDetailsInfo = ({
role,
}: {
role: AddressDetailsLeader['role'];
role: AddressDetailsOperator['role'];
}) => {
if (!role) {
return null;
Expand Down Expand Up @@ -151,7 +154,7 @@ const renderReputationTitle = (reputation: Reputation) => {
);
};

const renderRoleIcon = (role: AddressDetailsLeader['role']) => {
const renderRoleIcon = (role: AddressDetailsOperator['role']) => {
if (!role) return null;
const roleIcons = {
[Roles.reputationOracle]: <ReputationOracleIcon />,
Expand All @@ -174,7 +177,7 @@ const RoleDetails = ({
amountLocked,
},
}: {
data: AddressDetailsLeader;
data: AddressDetailsOperator;
}) => {
const { filterParams } = useWalletSearch();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Card from '@mui/material/Card';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import { AddressDetailsLeader } from '@services/api/use-address-details';
import { AddressDetailsOperator } from '@services/api/use-address-details';
import TableContainer from '@mui/material/TableContainer';
import Table from '@mui/material/Table';
import { EscrowsTableBody } from '@pages/SearchResults/RoleDetails/RoleDetailsEscrows/tableComponents/EscrowsTableBody';
Expand All @@ -15,7 +15,7 @@ import { Stack } from '@mui/material';
export const RoleDetailsEscrowsTable = ({
role,
}: {
role: AddressDetailsLeader['role'];
role: AddressDetailsOperator['role'];
}) => {
const { data } = useEscrowDetails({ role });
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handleErrorMessage } from '@services/handle-error-message';
import CircularProgress from '@mui/material/CircularProgress';
import { EscrowsTableBodyContainer } from '@pages/SearchResults/RoleDetails/RoleDetailsEscrows/tableComponents/EscrowsTableBodyContainer';
import { useEscrowDetails } from '@services/api/use-escrows-details';
import { AddressDetailsLeader } from '@services/api/use-address-details';
import { AddressDetailsOperator } from '@services/api/use-address-details';
import { useEscrowDetailsDto } from '@utils/hooks/use-escrows-details-dto';
import { useWalletSearch } from '@utils/hooks/use-wallet-search';
import { useNavigate } from 'react-router-dom';
Expand All @@ -15,7 +15,7 @@ import Link from '@mui/material/Link';
export const EscrowsTableBody = ({
role,
}: {
role: AddressDetailsLeader['role'];
role: AddressDetailsOperator['role'];
}) => {
const navigate = useNavigate();
const { filterParams } = useWalletSearch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const renderCurrentResultType = (
keyof AddressDetails,
{ title: string; icon: JSX.Element }
> = {
leader: {
operator: {
title: 'Wallet Address',
icon: <WalletIcon />,
},
Expand Down Expand Up @@ -86,7 +86,7 @@ const Results = () => {

const selectedWalletData: AddressDetailsWallet | undefined =
data.wallet ||
(data.leader && data.leader.role === null ? data.leader : undefined);
(data.operator && data.operator.role === null ? data.operator : undefined);

return (
<>
Expand All @@ -99,8 +99,8 @@ const Results = () => {
{renderCurrentResultType(data, filterParams.address)}
</Stack>

{data.leader && data.leader.role ? (
<RoleDetails data={data.leader} />
{data.operator && data.operator.role ? (
<RoleDetails data={data.operator} />
) : null}
{selectedWalletData ? <WalletAddress data={selectedWalletData} /> : null}
{data.escrow ? <EscrowAddress data={data.escrow} /> : null}
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/dashboard/client/src/services/api-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const apiPaths = {
path: '/stats/hcaptcha/daily',
},
leaderboardDetails: {
path: '/details/leaders',
path: '/details/operators',
},
addressDetails: {
path: '/details',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export enum Roles {
reputationOracle = 'Reputation Oracle',
}

const leaderSchema = z.object({
const operatorSchema = z.object({
chainId: z.number(),
address: z.string(),
balance: z.string().transform(transformOptionalTokenAmount),
Expand All @@ -87,12 +87,12 @@ const leaderSchema = z.object({
amountJobsProcessed: z.string(),
});

export type AddressDetailsLeader = z.infer<typeof leaderSchema>;
export type AddressDetailsOperator = z.infer<typeof operatorSchema>;

const addressDetailsResponseSchema = z.object({
wallet: z.optional(walletSchema),
escrow: z.optional(escrowSchema),
leader: z.optional(leaderSchema),
operator: z.optional(operatorSchema),
});

export type AddressDetails = z.infer<typeof addressDetailsResponseSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { apiPaths } from '../api-paths';
import { useWalletSearch } from '@utils/hooks/use-wallet-search';
import { validateResponse } from '@services/validate-response';
import { useEscrowDetailsDto } from '@utils/hooks/use-escrows-details-dto';
import { AddressDetailsLeader } from '@services/api/use-address-details';
import { AddressDetailsOperator } from '@services/api/use-address-details';

const escrowDetailsSuccessResponseSchema = z.object({
chainId: z.number(),
Expand Down Expand Up @@ -33,13 +33,13 @@ export interface PaginatedEscrowsDetailsDto {
skip: number;
first: number;
chainId: number;
role: AddressDetailsLeader['role'];
role: AddressDetailsOperator['role'];
}

export function useEscrowDetails({
role,
}: {
role: AddressDetailsLeader['role'];
role: AddressDetailsOperator['role'];
}) {
const { filterParams } = useWalletSearch();
const {
Expand Down
23 changes: 22 additions & 1 deletion packages/apps/dashboard/client/src/utils/config/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,28 @@ import { env } from '@helpers/env';
const ENABLED_CHAIN_IDS = env.VITE_ENABLED_CHAIN_IDS;
const chainIdsList = ENABLED_CHAIN_IDS.split(',').map((id) => parseInt(id, 10));

const viemChains = Object.values(chains);
const LOCALHOST = {
id: 1338,
name: 'Localhost',
network: 'localhost',
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: ['http://127.0.0.1:8545'],
},
public: {
http: ['http://127.0.0.1:8545'],
},
},
};

const viemChains = Object.values(chains).map((chain) =>
chain.id === 1338 ? LOCALHOST : chain
);

export const getNetwork = (chainId: number): Chain | undefined =>
viemChains.find((network) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/dashboard/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { NetworksModule } from './modules/networks/networks.module';
PORT: Joi.number().port().default(3000),
REDIS_HOST: Joi.string(),
REDIS_PORT: Joi.number(),
SUBGRAPH_API_KEY: Joi.string().required(),
SUBGRAPH_API_KEY: Joi.string(),
HCAPTCHA_API_KEY: Joi.string().required(),
CACHE_HMT_PRICE_TTL: Joi.number(),
CACHE_HMT_GENERAL_STATS_TTL: Joi.number(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class EnvironmentConfigService {
);
}
get subgraphApiKey(): string {
return this.configService.getOrThrow<string>('SUBGRAPH_API_KEY');
return this.configService.get<string>('SUBGRAPH_API_KEY', '');
}
get hmtPriceSource(): string {
return this.configService.get<string>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum LeadersOrderBy {
export enum OperatorsOrderBy {
ROLE = 'role',
AMOUNT_STAKED = 'amountStaked',
REPUTATION = 'reputation',
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/dashboard/server/src/common/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './leader';
export * from './operator';
8 changes: 0 additions & 8 deletions packages/apps/dashboard/server/src/common/types/leader.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/apps/dashboard/server/src/common/types/operator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { OrderDirection } from '@human-protocol/sdk';
import { OperatorsOrderBy } from '../enums/operator';

export type GetOperatorsPaginationOptions = {
orderBy?: OperatorsOrderBy;
orderDirection?: OrderDirection;
first?: number;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import {
import {
DetailsTransactionsPaginationDto,
DetailsEscrowsPaginationDto,
LeadersPaginationDto,
OperatorsPaginationDto,
} from './dto/details-pagination.dto';
import { WalletDto } from './dto/wallet.dto';
import { EscrowDto, EscrowPaginationDto } from './dto/escrow.dto';
import { LeaderDto } from './dto/leader.dto';
import { OperatorDto } from './dto/operator.dto';
import { TransactionPaginationDto } from './dto/transaction.dto';

@ApiTags('Details')
Expand All @@ -33,22 +33,22 @@ import { TransactionPaginationDto } from './dto/transaction.dto';
export class DetailsController {
constructor(private readonly detailsService: DetailsService) {}

@Get('/leaders')
@Get('/operators')
@HttpCode(200)
@ApiOperation({
summary: 'Get leaders',
description: 'Returns leaders for the given filters.',
summary: 'Get operators',
description: 'Returns operators for the given filters.',
})
@ApiResponse({
status: 200,
description: 'Leaders retrieved successfully',
type: LeaderDto,
description: 'Operators retrieved successfully',
type: OperatorDto,
isArray: true,
})
public async leaders(
@Query() query: LeadersPaginationDto,
): Promise<LeaderDto[]> {
return this.detailsService.getLeaders(query.chainId, {
public async operators(
@Query() query: OperatorsPaginationDto,
): Promise<OperatorDto[]> {
return this.detailsService.getOperators(query.chainId, {
orderBy: query.orderBy,
orderDirection: query.orderDirection,
first: query.first,
Expand All @@ -71,7 +71,7 @@ export class DetailsController {
@Param('address', AddressValidationPipe) address: string,
@Query('chainId') chainId: ChainId,
): Promise<DetailsResponseDto> {
const details: WalletDto | EscrowDto | LeaderDto =
const details: WalletDto | EscrowDto | OperatorDto =
await this.detailsService.getDetails(chainId, address);
if (details instanceof WalletDto) {
const response: DetailsResponseDto = {
Expand All @@ -85,9 +85,9 @@ export class DetailsController {
};
return response;
}
if (details instanceof LeaderDto) {
if (details instanceof OperatorDto) {
const response: DetailsResponseDto = {
leader: details,
operator: details,
};
return response;
}
Expand Down
Loading

0 comments on commit e936002

Please sign in to comment.