Skip to content

Commit

Permalink
card refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
fmtabbara committed Dec 19, 2024
1 parent 67adcce commit 5a17618
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
CURRENT_EPOCH_REWARDS,
HARBOURMASTER_API_MIXNODES_STATS,
} from "@/app/api/urls";
import { formatBigNum } from "@/app/utils/formatBigNumbers";
import { formatBigNum } from "@/utils/formatBigNumbers";
import { Box, Stack, Typography } from "@mui/material";
import ExplorerCard from "../cards/ExplorerCard";
import { LineChart } from "../lineChart";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IPacketsAndStakingData } from "@/app/api";
import { HARBOURMASTER_API_MIXNODES_STATS } from "@/app/api/urls";
import { formatBigNum } from "@/app/utils/formatBigNumbers";
import { formatBigNum } from "@/utils/formatBigNumbers";
import { Box, Stack, Typography } from "@mui/material";
import ExplorerCard from "../cards/ExplorerCard";
import { LineChart } from "../lineChart";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatBigNum } from "@/app/utils/formatBigNumbers";
import { formatBigNum } from "@/utils/formatBigNumbers";
import { Stack, Typography } from "@mui/material";
import ExplorerCard from "../cards/ExplorerCard";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
NodeDescription,
RewardingDetails,
} from "@/app/api/types";
import { formatBigNum } from "@/utils/formatBigNumbers";
import { Stack, Typography } from "@mui/material";
import { format } from "date-fns";
import ExplorerCard from "../cards/ExplorerCard";
Expand All @@ -23,7 +24,7 @@ export const BasicInfoCard = (props: IBasicInfoCardProps) => {
"dd/MM/yyyy",
);

const selfBond = Number(rewardDetails.operator) / 1_000_000;
const selfBond = formatBigNum(Number(rewardDetails.operator) / 1_000_000);
const selfBondFormated = `${selfBond} NYM`;
return (
<ExplorerCard label="Basic info">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NodeDescription } from "@/app/api/types";
import { Box, Chip, Stack, Typography } from "@mui/material";
import ExplorerCard from "../cards/ExplorerCard";
import ExplorerListItem from "../list/ListItem";
import StarRating from "../starRating/StarRating";
Expand All @@ -7,44 +8,48 @@ interface IQualityIndicatorsCardProps {
nodeDescription: NodeDescription;
}

interface IDeclaredRoles {
declared_role: {
entry: boolean;
exit_ipr: boolean;
exit_nr: boolean;
mixnode: boolean;
};
}

function getNodeRoles(rolesObject: IDeclaredRoles): string {
const roleMapping: { [key: string]: string } = {
entry: "Entry Node",
exit_ipr: "Exit IPR Node",
exit_nr: "Exit NR Node",
mixnode: "Mix Node",
};
type DelcaredRoleKey = keyof NodeDescription["declared_role"];
type RoleString = "Entry Node" | "Exit IPR Node" | "Exit NR Node" | "Mix Node";

const { declared_role } = rolesObject;
const roleMapping: Record<DelcaredRoleKey, RoleString> = {
entry: "Entry Node",
exit_ipr: "Exit IPR Node",
exit_nr: "Exit NR Node",
mixnode: "Mix Node",
};

const activeRoles = Object.entries(declared_role)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([_, value]) => value) // Filter keys where value is true
.map(([key]) => roleMapping[key]) // Map keys to their corresponding strings
.join(", "); // Join with commas
function getNodeRoles(
declaredRoles: NodeDescription["declared_role"],
): RoleString[] {
const activeRoles = Object.entries(declaredRoles)
.filter(([, isActive]) => isActive)
.map(([role]) => roleMapping[role as DelcaredRoleKey]);

return activeRoles;
}

export const QualityIndicatorsCard = (props: IQualityIndicatorsCardProps) => {
const { nodeDescription } = props;

const nodeRoles = getNodeRoles({
declared_role: nodeDescription.declared_role,
});
const nodeRoles = getNodeRoles(nodeDescription.declared_role);
const NodeRoles = nodeRoles.map((role) => (
<Stack key={role} direction="row" gap={1}>
<Chip key={role} label={role} size="small" />
</Stack>
));

return (
<ExplorerCard label="Quality indicatiors" sx={{ height: "100%" }}>
<ExplorerListItem row divider label="Role" value={nodeRoles} />
<ExplorerListItem
row
divider
label="Role"
value={
<Stack direction="row" gap={1}>
{NodeRoles}
</Stack>
}
/>
<ExplorerListItem
row
divider
Expand Down

0 comments on commit 5a17618

Please sign in to comment.