Skip to content

Commit

Permalink
feat(app/search-result/role-details/escrows): add escrows table
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperKoza343 committed Jul 25, 2024
1 parent 23f9973 commit 46a5a9f
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,8 @@ 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 { getNetwork } from '@utils/config/networks';

interface RoleDetails {
escrows: {
escrowId: string;
}[];
}
//TEMPORARY INTERFACE AND DATA
const HARDCODED_ROLE_DETAILS: RoleDetails = {
escrows: [
{
escrowId:
'3qraSH39kPbdkFwQYuhwE2kZHjXnV2dhukuprkDkhnosKa89YLLhMXXmwwHhbRu9ePS2AhNm46po2RHSANjYTDhcNS1CY4',
},
{
escrowId:
'3qraSH39kPbdkFwQYuhwE2kZHjXnV2dhukuprkDkhnosKa89YLLhMXXmwwHhbRu9ePS2AhNm46po2RHSANjYTDhcNS1CY4',
},
],
};
import { useWalletSearch } from '@utils/hooks/use-wallet-search';
import { RoleDetailsEscrowsTable } from '@pages/SearchResults/RoleDetails/RoleDetailsEscrows/RoleDetailsEscrowsTable';

interface RoleInfoProps {
title: string;
Expand Down Expand Up @@ -178,6 +161,8 @@ const RoleDetails = ({
}: {
data: AddressDetailsLeader;
}) => {
const { filterParams } = useWalletSearch();

return (
<>
<Card
Expand Down Expand Up @@ -317,22 +302,18 @@ const RoleDetails = ({
>
Tokens Staked
</Typography>
{amountStaked ? (
<Typography>
{amountStaked}
<Typography
sx={{
marginLeft: 0.5,
}}
color={colorPalette.fog.main}
component="span"
>
HMT
</Typography>
<Typography>
{amountStaked}
<Typography
sx={{
marginLeft: 0.5,
}}
color={colorPalette.fog.main}
component="span"
>
HMT
</Typography>
) : (
<Typography>N/A</Typography>
)}
</Typography>
</Stack>
<Stack gap={{ xs: 1, md: 0 }} direction={{ sm: 'column', md: 'row' }}>
<Typography
Expand Down Expand Up @@ -381,48 +362,9 @@ const RoleDetails = ({
</Stack>
</Card>

<Card
sx={{
paddingX: { xs: 2, md: 8 },
paddingY: { xs: 4, md: 6 },
marginBottom: 4,
}}
>
<Box>
<Typography
sx={{
marginBottom: 3,
}}
variant="h5"
>
Escrows
</Typography>
{HARDCODED_ROLE_DETAILS.escrows.length > 1 ? (
<>
{HARDCODED_ROLE_DETAILS.escrows.map((elem) => (
<Typography
variant="h6"
component="p"
sx={{
marginBottom: 3,
'&:last-child': { marginBottom: 0 },
}}
>
{elem.escrowId}
</Typography>
))}
</>
) : (
<Typography
variant="h6"
component="p"
textAlign={{ xs: 'left', md: 'center' }}
>
No escrows launched yet
</Typography>
)}
</Box>
</Card>
{filterParams.address && filterParams.chainId ? (
<RoleDetailsEscrowsTable role={role} />
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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 TableContainer from '@mui/material/TableContainer';
import Table from '@mui/material/Table';
import { EscrowsTableBody } from '@pages/SearchResults/RoleDetails/RoleDetailsEscrows/tableComponents/EscrowsTableBody';
import TableFooter from '@mui/material/TableFooter';
import TablePagination from '@mui/material/TablePagination';
import { useEscrowDetailsDto } from '@utils/hooks/use-escrows-details-dto';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';

export const RoleDetailsEscrowsTable = ({
role,
}: {
role: AddressDetailsLeader['role'];
}) => {
const {
pagination: { page, pageSize, lastPageIndex },
setPageSize,
setNextPage,
setPrevPage,
} = useEscrowDetailsDto();

return (
<Card
sx={{
paddingX: { xs: 2, md: 8 },
paddingY: { xs: 4, md: 6 },
marginBottom: 4,
}}
>
<Box>
<Typography
sx={{
marginBottom: 3,
}}
variant="h5"
>
Escrows
</Typography>
<TableContainer>
<Table
sx={{
minWidth: 800,
'& .MuiTableCell-root': {
borderBottom: 'none',
},
}}
aria-label="simple-table"
>
<TableHead>
<TableRow></TableRow>
</TableHead>
<EscrowsTableBody role={role} />
<TableFooter>
<TablePagination
// count is unknown but required as props
count={9999}
// onPageChange is required as props
onPageChange={() => {}}
page={page}
rowsPerPage={pageSize}
onRowsPerPageChange={(event) => {
setPageSize(Number(event.target.value));
}}
rowsPerPageOptions={[5, 10]}
labelDisplayedRows={({ from, to }) => {
return `${from}${to}`;
}}
slotProps={{
actions: {
nextButton: {
onClick: () => {
setNextPage();
},
disabled:
lastPageIndex !== undefined &&
(page === lastPageIndex || lastPageIndex - 1 === page),
},
previousButton: {
onClick: () => {
setPrevPage();
},
},
},
}}
/>
</TableFooter>
</Table>
</TableContainer>
</Box>
</Card>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import TableRow from '@mui/material/TableRow';
import TableCell from '@mui/material/TableCell';
import MuiTableBody from '@mui/material/TableBody';
import { useEffect } from 'react';
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 { useEscrowDetailsDto } from '@utils/hooks/use-escrows-details-dto';

export const EscrowsTableBody = ({
role,
}: {
role: AddressDetailsLeader['role'];
}) => {
const { data, isPending, isError, error } = useEscrowDetails({ role });
const {
setLastPageIndex,
setPrevPage,
pagination: { page },
} = useEscrowDetailsDto();

useEffect(() => {
if (data?.results.length === 0) {
setLastPageIndex(page);
setPrevPage();
}
}, [data?.results, page, setLastPageIndex, setPrevPage]);

if (isPending) {
return (
<EscrowsTableBodyContainer>
<CircularProgress />
</EscrowsTableBodyContainer>
);
}

if (isError) {
return (
<EscrowsTableBodyContainer>
<div>{handleErrorMessage(error)}</div>
</EscrowsTableBodyContainer>
);
}

if (!data.results.length) {
return (
<EscrowsTableBodyContainer>
<div>No data</div>
</EscrowsTableBodyContainer>
);
}

return (
<MuiTableBody>
{data.results.map((elem, idx) => (
<TableRow key={idx}>
<TableCell
sx={{
padding: '0 0 24px 0',
}}
>
{elem.address}
</TableCell>
</TableRow>
))}
</MuiTableBody>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import MuiTableBody from '@mui/material/TableBody';
import { Grid } from '@mui/material';

export const EscrowsTableBodyContainer = ({
children,
}: {
children: JSX.Element;
}) => {
return (
<MuiTableBody sx={{ position: 'relative', height: ' 40vh' }}>
<Grid
container
sx={{
justifyContent: 'center',
alignItems: 'center',
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
}}
>
{children}
</Grid>
</MuiTableBody>
);
};
3 changes: 3 additions & 0 deletions packages/apps/dashboard/ui-2024/src/services/api-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export const apiPaths = {
transactionDetails: {
path: '/details/transactions',
},
escrowDetails: {
path: '/details/escrows',
},
} as const;
Loading

0 comments on commit 46a5a9f

Please sign in to comment.