Skip to content

Commit 44f16df

Browse files
authored
Convert roles from human readable to snake case to unify values (#3054)
* Convert roles from human readable to snake case to unify values * Fix yarn lock and reputation oracle tests * Fix human app server tests
1 parent 0774e9f commit 44f16df

File tree

18 files changed

+122
-97
lines changed

18 files changed

+122
-97
lines changed

packages/apps/dashboard/client/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@emotion/react": "^11.11.4",
1717
"@emotion/styled": "^11.11.5",
18+
"@human-protocol/sdk": "*",
1819
"@mui/icons-material": "^6.2.0",
1920
"@mui/material": "^5.15.18",
2021
"@mui/styled-engine-sc": "6.4.0",
@@ -36,6 +37,7 @@
3637
"styled-components": "^6.1.11",
3738
"swiper": "^11.1.3",
3839
"use-debounce": "^10.0.2",
40+
"vite-plugin-node-polyfills": "^0.23.0",
3941
"zod": "^3.23.8",
4042
"zustand": "^4.5.4"
4143
},

packages/apps/dashboard/client/src/features/Leaderboard/components/EntityIcon.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import HumanIcon from '@components/Icons/HumanIcon';
33
import { JobLauncher } from '@components/Icons/JobLauncher';
44
import { RecordingOracle } from '@components/Icons/RecordingOracle';
55
import { ReputationOracle } from '@components/Icons/ReputationOracle';
6+
import { Role } from '@human-protocol/sdk';
67

78
export const EntityIcon: React.FC<{ role: string }> = ({ role }) => {
89
switch (role) {
9-
case 'Job Launcher':
10+
case Role.JobLauncher:
1011
return <JobLauncher />;
11-
case 'Recording Oracle':
12+
case Role.RecordingOracle:
1213
return <RecordingOracle />;
13-
case 'Reputation Oracle':
14+
case Role.ReputationOracle:
1415
return <ReputationOracle />;
15-
case 'Exchange Oracle':
16+
case Role.ExchangeOracle:
1617
return <ExchangeOracleIcon />;
17-
case 'HUMAN App':
18-
return <HumanIcon />;
1918
default:
2019
return <HumanIcon />;
2120
}

packages/apps/dashboard/client/src/features/Leaderboard/components/RoleCell.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Launch as LaunchIcon } from '@mui/icons-material';
33
import { useBreakPoints } from '@utils/hooks/use-is-mobile';
44
import { Link } from 'react-router-dom';
55
import { EntityIcon } from './EntityIcon';
6+
import { CaseConverter } from '@utils/case-converter';
67

78
const Wrapper = ({
89
children,
@@ -40,7 +41,7 @@ export const RoleCell = ({
4041
const {
4142
mobile: { isMobile },
4243
} = useBreakPoints();
43-
44+
const humanReadableRole = CaseConverter.convertSnakeToHumanReadable(role);
4445
return (
4546
<Box display="flex" alignItems="center" gap={1} height="100%">
4647
<Wrapper websiteUrl={websiteUrl}>
@@ -56,7 +57,7 @@ export const RoleCell = ({
5657
whiteSpace: isMobile ? 'wrap' : 'nowrap',
5758
}}
5859
>
59-
{name ?? role}
60+
{name ?? humanReadableRole}
6061
</Typography>
6162
{websiteUrl ? <LaunchIcon fontSize="small" /> : null}
6263
</Box>
@@ -69,7 +70,7 @@ export const RoleCell = ({
6970
whiteSpace: isMobile ? 'wrap' : 'nowrap',
7071
}}
7172
>
72-
{role}
73+
{humanReadableRole}
7374
</Typography>
7475
) : null}
7576
</Box>

packages/apps/dashboard/client/src/pages/SearchResults/RoleDetails/RoleDetails.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import Stack from '@mui/material/Stack';
66
import IconButton from '@mui/material/IconButton';
77
import ReputationOracleIcon from '@assets/icons/reputation-oracle.svg';
88
import ExchangeOracleIcon from '@assets/icons/exchange-oracle.svg';
9-
import HumanAppIcon from '@assets/icons/human-app.svg';
109
import JobLauncherIcon from '@assets/icons/job-launcher.svg';
1110
import RecordingOracleIcon from '@assets/icons/recording-oracle.svg';
1211
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
13-
import { AddressDetailsLeader, Roles } from '@services/api/use-address-details';
12+
import { AddressDetailsLeader } from '@services/api/use-address-details';
1413
import { getNetwork } from '@utils/config/networks';
1514
import { useWalletSearch } from '@utils/hooks/use-wallet-search';
1615
import { RoleDetailsEscrowsTable } from '@pages/SearchResults/RoleDetails/RoleDetailsEscrows/RoleDetailsEscrowsTable';
1716
import { Reputation } from '@services/api/use-leaderboard-details';
1817
import { env } from '@helpers/env';
1918
import { FormatNumberWithDecimals } from '@components/Home/FormatNumber';
2019
import CustomTooltip from '@components/CustomTooltip';
20+
import { Role } from '@human-protocol/sdk';
2121

2222
interface RoleInfoProps {
2323
title: string;
@@ -55,32 +55,32 @@ const RenderRoleDetailsInfo = ({
5555
}
5656

5757
const roleDetailsInfo: Partial<
58-
Record<Roles, { title: string; points: string[] }>
58+
Record<string, { title: string; points: string[] }>
5959
> = {
60-
[Roles.reputationOracle]: {
60+
[Role.ReputationOracle]: {
6161
title: 'Reputation Oracle',
6262
points: [
6363
'The Reputation Oracle is the trust engine of HUMAN Protocol.',
6464
'It cross-checks validated solutions from the Recording Oracle, adjusts reputation scores, and manages payments.',
6565
"It's the final seal of quality and trust within the ecosystem.",
6666
],
6767
},
68-
[Roles.recordingOracle]: {
68+
[Role.RecordingOracle]: {
6969
title: 'Recording Oracle',
7070
points: [
7171
'The Recording Oracle is where task solutions get the green light.',
7272
'It is storing, and recording task solutions on the blockchain.',
7373
"From quality checks to reputation adjustments, it's the assurance you need for dependable results.",
7474
],
7575
},
76-
[Roles.exchangeOracle]: {
76+
[Role.ExchangeOracle]: {
7777
title: 'Exchange Oracle',
7878
points: [
7979
"The Exchange Oracle is the HUMAN Protocol's powerhouse, directing tasks to skilled workers and ensuring smooth communication.",
8080
'It validates solutions, provides job updates, and handles cancellations, streamlining the job lifecycle.',
8181
],
8282
},
83-
[Roles.jobLauncher]: {
83+
[Role.JobLauncher]: {
8484
title: 'Job Launcher',
8585
points: [
8686
'The Job Launcher is a tool that allows anybody to create and launch jobs, to be distributed as tasks through the HUMAN App.',
@@ -154,11 +154,10 @@ const renderReputationTitle = (reputation: Reputation) => {
154154
const renderRoleIcon = (role: AddressDetailsLeader['role']) => {
155155
if (!role) return null;
156156
const roleIcons = {
157-
[Roles.reputationOracle]: <ReputationOracleIcon />,
158-
[Roles.exchangeOracle]: <ExchangeOracleIcon />,
159-
[Roles.humanApp]: <HumanAppIcon />,
160-
[Roles.jobLauncher]: <JobLauncherIcon />,
161-
[Roles.recordingOracle]: <RecordingOracleIcon />,
157+
[Role.ReputationOracle]: <ReputationOracleIcon />,
158+
[Role.ExchangeOracle]: <ExchangeOracleIcon />,
159+
[Role.JobLauncher]: <JobLauncherIcon />,
160+
[Role.RecordingOracle]: <RecordingOracleIcon />,
162161
};
163162

164163
return roleIcons[role];

packages/apps/dashboard/client/src/services/api/use-address-details.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { apiPaths } from '../api-paths';
55
import { useWalletSearch } from '@utils/hooks/use-wallet-search';
66
import { validateResponse } from '../validate-response';
77
import { reputationSchema } from '@services/api/use-leaderboard-details';
8+
import { Role } from '@human-protocol/sdk';
89

910
const transformOptionalTokenAmount = (
1011
value: string | undefined | null,
@@ -63,19 +64,18 @@ const escrowSchema = z.object({
6364

6465
export type AddressDetailsEscrowSchema = z.infer<typeof escrowSchema>;
6566

66-
export enum Roles {
67-
jobLauncher = 'Job Launcher',
68-
exchangeOracle = 'Exchange Oracle',
69-
humanApp = 'Human App',
70-
recordingOracle = 'Recording Oracle',
71-
reputationOracle = 'Reputation Oracle',
72-
}
73-
7467
const leaderSchema = z.object({
7568
chainId: z.number(),
7669
address: z.string(),
7770
balance: z.string().transform(transformOptionalTokenAmount),
78-
role: z.nativeEnum(Roles).nullable(),
71+
role: z
72+
.enum([
73+
Role.JobLauncher,
74+
Role.ExchangeOracle,
75+
Role.RecordingOracle,
76+
Role.ReputationOracle,
77+
])
78+
.nullable(),
7979
amountStaked: z.string().optional().transform(transformOptionalTokenAmount),
8080
amountLocked: z.string().optional().transform(transformOptionalTokenAmount),
8181
lockedUntilTimestamp: z.string().optional(),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class CaseConverter {
2+
static convertSnakeToHumanReadable(string: string): string {
3+
return string
4+
.split('_')
5+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
6+
.join(' ');
7+
}
8+
}

packages/apps/dashboard/client/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
33
import * as path from 'path';
44
import svgr from 'vite-plugin-svgr';
5+
import { nodePolyfills } from 'vite-plugin-node-polyfills';
56

67
// https://vitejs.dev/config/
78
export default defineConfig({
@@ -11,6 +12,9 @@ export default defineConfig({
1112
include: '**/*.svg',
1213
exclude: 'src/assets/icons/excluded/**/*.svg',
1314
}),
15+
nodePolyfills({
16+
protocolImports: true,
17+
}),
1418
],
1519
resolve: {
1620
alias: {
@@ -23,6 +27,9 @@ export default defineConfig({
2327
'@services': path.resolve(__dirname, './src/services'),
2428
},
2529
},
30+
optimizeDeps: {
31+
include: ['@human-protocol/sdk'],
32+
},
2633
server: {
2734
port: 3001,
2835
},

packages/apps/dashboard/server/src/common/enums/roles.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/apps/dashboard/server/src/modules/details/details.service.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { firstValueFrom } from 'rxjs';
2323
import { HMToken__factory } from '@human-protocol/core/typechain-types';
2424
import { ethers } from 'ethers';
2525
import { NetworkConfigService } from '../../common/config/network-config.service';
26-
import { OracleRole, SubgraphOracleRole } from '../../common/enums/roles';
2726
import { LeadersOrderBy } from '../../common/enums/leader';
2827
import { ReputationLevel } from '../../common/enums/reputation';
2928
import {
@@ -210,10 +209,10 @@ export class DetailsService {
210209
chainId,
211210
minAmountStaked: MIN_AMOUNT_STAKED,
212211
roles: [
213-
SubgraphOracleRole.JOB_LAUNCHER,
214-
SubgraphOracleRole.EXCHANGE_ORACLE,
215-
SubgraphOracleRole.RECORDING_ORACLE,
216-
SubgraphOracleRole.REPUTATION_ORACLE,
212+
Role.JobLauncher,
213+
Role.ExchangeOracle,
214+
Role.RecordingOracle,
215+
Role.ReputationOracle,
217216
],
218217
};
219218

@@ -242,10 +241,10 @@ export class DetailsService {
242241
params: {
243242
chain_id: chainId,
244243
roles: [
245-
OracleRole.JOB_LAUNCHER,
246-
OracleRole.EXCHANGE_ORACLE,
247-
OracleRole.RECORDING_ORACLE,
248-
OracleRole.REPUTATION_ORACLE,
244+
Role.JobLauncher,
245+
Role.ExchangeOracle,
246+
Role.RecordingOracle,
247+
Role.ReputationOracle,
249248
],
250249
},
251250
},
@@ -272,10 +271,10 @@ export class DetailsService {
272271
params: {
273272
chain_id: chainId,
274273
roles: [
275-
OracleRole.JOB_LAUNCHER,
276-
OracleRole.EXCHANGE_ORACLE,
277-
OracleRole.RECORDING_ORACLE,
278-
OracleRole.REPUTATION_ORACLE,
274+
Role.JobLauncher,
275+
Role.ExchangeOracle,
276+
Role.RecordingOracle,
277+
Role.ReputationOracle,
279278
],
280279
...(orderBy &&
281280
orderBy === LeadersOrderBy.REPUTATION && {

packages/apps/fortune/exchange-oracle/client/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link rel="icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#000000" />
8-
<meta name="description" content="Human Protocol Job Launcher" />
8+
<meta name="description" content="Human Protocol Exchange Oracle" />
99
<link rel="apple-touch-icon" href="/logo192.png" />
1010
<!--
1111
manifest.json provides metadata used when your web app is installed on a

0 commit comments

Comments
 (0)