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

[HUM-162]: chore: simplify operator profile page #3158

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Link } from 'react-router-dom';
import Snackbar from '@mui/material/Snackbar';
import { Button } from '@/shared/components/ui/button';
import { useWalletConnect } from '@/shared/contexts/wallet-connect';
import { useWeb3SignIn } from '@/modules/operator/hooks/use-web3-signin';
import { useWeb3Auth } from '@/modules/auth-web3/hooks/use-web3-auth';
import { routerPaths } from '@/router/router-paths';
import { getErrorMessageForError } from '@/shared/errors';
import { PrepareSignatureType } from '@/api/hooks/use-prepare-signature';
import { useWeb3SignIn } from '../hooks';

export function OperatorSignIn() {
const { isConnected, openModal, address } = useWalletConnect();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './use-web3-signin';
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './profile-disable-button';
export * from './profile-enable-button';
export * from './operator-info';
export * from './operator-stats';
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { Paper, Typography, Stack, List, Grid } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { useWeb3AuthenticatedUser } from '@/modules/auth-web3/hooks/use-web3-authenticated-user';
import { CheckmarkIcon, LockerIcon } from '@/shared/components/ui/icons';
import { ProfileListItem } from '@/shared/components/ui/profile';
import { useColorMode } from '@/shared/contexts/color-mode';
import { useIsMobile } from '@/shared/hooks/use-is-mobile';
import { type GetEthKVStoreValuesSuccessResponse } from '../../hooks/use-get-keys';
import { ProfileDisableButton } from './profile-disable-button';
import { ProfileEnableButton } from './profile-enable-button';

export function OperatorInfo({
keysData,
}: Readonly<{ keysData: GetEthKVStoreValuesSuccessResponse }>) {
const { colorPalette } = useColorMode();
const { t } = useTranslation();
const { user } = useWeb3AuthenticatedUser();
const isMobile = useIsMobile('lg');

const isOperatorActive = user.status === 'active';

return (
<Paper
sx={{
height: '100%',
boxShadow: 'none',
padding: isMobile ? '40px 20px' : '40px 40px',
borderRadius: '20px',
}}
>
<Typography
color={colorPalette.text.primary}
sx={{
fontWeight: 600,
}}
variant="h5"
>
{t('operator.profile.about.header')}
</Typography>
<Stack flexDirection="row">
<List sx={{ overflow: 'hidden' }}>
<ProfileListItem
header={t('operator.profile.about.role')}
paragraph={
keysData.role ?? t('operator.addKeysPage.existingKeys.noValue')
}
/>
<Grid
sx={{
display: 'flex',
flexDirection: 'column',
gap: '10px',
}}
>
<Typography
component="span"
sx={{
overflow: 'hidden',
}}
variant="subtitle2"
>
{t('operator.profile.about.status.statusHeader')}
</Typography>
{isOperatorActive ? (
<Grid
sx={{
display: 'flex',

alignItems: 'center',
gap: '0.4rem',
}}
>
{t('operator.profile.about.status.statusActivated')}
<CheckmarkIcon />
</Grid>
) : (
<Grid
sx={{
display: 'flex',
alignItems: 'center',
gap: '0.4rem',
}}
>
{t('operator.profile.about.status.statusDeactivated')}
<LockerIcon />
</Grid>
)}
<div>
{isOperatorActive ? (
<ProfileDisableButton />
) : (
<ProfileEnableButton />
)}
</div>
</Grid>
<ProfileListItem
header={t('operator.profile.about.fee')}
paragraph={
`${keysData.fee ?? ''}${t('inputMasks.percentSuffix')}` ||
t('operator.addKeysPage.existingKeys.noValue')
}
/>
<ProfileListItem
header={t('operator.profile.about.publicKey')}
paragraph={
keysData.public_key ??
t('operator.addKeysPage.existingKeys.noValue')
}
/>
<ProfileListItem
header={t('operator.profile.about.url')}
paragraph={
keysData.url ?? t('operator.addKeysPage.existingKeys.url')
}
/>
<ProfileListItem
header={t('operator.profile.about.webhookUrl')}
paragraph={
keysData.webhook_url ??
t('operator.addKeysPage.existingKeys.noValue')
}
/>
</List>
</Stack>
</Paper>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Paper, Typography, Stack, List } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { ProfileListItem } from '@/shared/components/ui/profile';
import { useColorMode } from '@/shared/contexts/color-mode';
import { useIsMobile } from '@/shared/hooks/use-is-mobile';
import { type OperatorStatsResponse } from '../hooks';

export function OperatorStats({
statsData,
}: Readonly<{
statsData: OperatorStatsResponse;
}>) {
const isMobile = useIsMobile('lg');
const { colorPalette } = useColorMode();
const { t } = useTranslation();

return (
<Paper
sx={{
height: '100%',
boxShadow: 'none',
width: '100%',
display: 'flex',
flexDirection: 'column',
padding: isMobile ? '20px' : '40px',
borderRadius: '20px',
}}
>
<Typography
color={colorPalette.text.primary}
sx={{
fontWeight: 600,
width: '100%',
}}
variant="h5"
>
{t('operator.profile.statistics.header')}
</Typography>
<Stack flexDirection="row" justifyContent="space-between">
<List>
<ProfileListItem
header={t('operator.profile.statistics.escrowsProcessed')}
paragraph={statsData.escrows_processed.toString()}
/>
<ProfileListItem
header={t('operator.profile.statistics.escrowsActive')}
paragraph={statsData.escrows_active.toString()}
/>
<ProfileListItem
header={t('operator.profile.statistics.escrowsCancelled')}
paragraph={statsData.escrows_cancelled.toString()}
/>
<ProfileListItem
header={t('operator.profile.statistics.workersAmount')}
paragraph={statsData.workers_total.toString()}
/>
</List>
<List>
<ProfileListItem
header={t('operator.profile.statistics.assignmentsCompleted')}
paragraph={statsData.assignments_completed.toString()}
/>
<ProfileListItem
header={t('operator.profile.statistics.assignmentsRejected')}
paragraph={statsData.assignments_rejected.toString()}
/>
<ProfileListItem
header={t('operator.profile.statistics.assignmentsExpired')}
paragraph={statsData.assignments_expired.toString()}
/>
</List>
</Stack>
</Paper>
);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { t } from 'i18next';
import { Typography } from '@mui/material';
import { useDisableWeb3Operator } from '@/modules/operator/hooks/use-disable-operator';
import { useConnectedWallet } from '@/shared/contexts/wallet-connect';
import { Button } from '@/shared/components/ui/button';
import type { SignatureData } from '@/api/hooks/use-prepare-signature';
import {
PrepareSignatureType,
usePrepareSignature,
} from '@/api/hooks/use-prepare-signature';
import { useDisableWeb3Operator } from '../hooks';

export function ProfileDisableButton() {
const { address, signMessage } = useConnectedWallet();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './use-get-stats';
export * from './use-disable-operator';
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ const operatorStatsSuccessResponseSchema = z.object({
escrows_cancelled: z.number(),
});

export type OperatorStatsSuccessResponse = z.infer<
typeof operatorStatsSuccessResponseSchema
>;

const failedResponse = {
workers_total: '-',
assignments_completed: '-',
Expand All @@ -28,6 +24,16 @@ const failedResponse = {
escrows_cancelled: '-',
};

type OperatorStatsSuccessResponse = z.infer<
typeof operatorStatsSuccessResponseSchema
>;

type OperatorStatsFailedResponse = typeof failedResponse;

export type OperatorStatsResponse =
| OperatorStatsSuccessResponse
| OperatorStatsFailedResponse;

export function useGetOperatorStats() {
const { data: keysData } = useGetKeys();

Expand Down
Loading