Skip to content

Commit

Permalink
feat: context and ui validations configurations added
Browse files Browse the repository at this point in the history
  • Loading branch information
mikarasv committed Apr 23, 2024
1 parent 1482c83 commit a19b718
Show file tree
Hide file tree
Showing 13 changed files with 541 additions and 310 deletions.
8 changes: 6 additions & 2 deletions web/app/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InputHTMLAttributes } from "react";
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
name: string;
className?: string;
inputSize?: "small" | "medium";
}

export const Input = ({
Expand All @@ -14,6 +15,7 @@ export const Input = ({
onChange,
placeholder,
className: customClassName,
inputSize = "medium",
}: InputProps) => {
return (
<input
Expand All @@ -24,8 +26,10 @@ export const Input = ({
value={value}
onChange={onChange}
placeholder={placeholder}
className={`block w-full px-4 py-2 mt-1 border-2 bg-white border-black h-16 shadow shadow-black rounded-lg rounded-b-xl border-b-8
appearance-none text-black placeholder-gray-400 text-2xl outline-none ${customClassName}`}
className={`block w-full border-2 bg-white border-black h-16 shadow shadow-black rounded-lg rounded-b-xl border-b-8
appearance-none text-black placeholder-gray-400 outline-none text-2xl ${customClassName} ${
inputSize == "small" ? "px-2 py-1 h-14 mt-0.5" : "px-4 py-2 mt-1"
}`}
/>
);
};
63 changes: 43 additions & 20 deletions web/app/components/RootSection.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useLocation } from "@remix-run/react";
import { Section } from "napi-pallas";
import { useState } from "react";
import { IValidation } from "../interfaces";
import { getTopicMeta } from "../utils";
import { SearchParams, getTopicMeta } from "../utils";
import { HexBlock, PropBlock, TopicMeta } from "./constructors";
import { DataSection, ValidationAccordion } from "./index";
import { DataSection, ValidationInformation } from "./index";

export function RootSection(props: {
data: Section;
topics: Record<string, TopicMeta>;
validations: IValidation[];
era: string;
}) {
const [open, setOpen] = useState(false);
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const initialOpen = searchParams.get(SearchParams.OPEN) === "true";
const goesBeginning = searchParams.get(SearchParams.BEGINNING) === "true";
const [open, setOpen] = useState<boolean | undefined>(undefined);
const handleClick = () => setOpen(!open);
const topic = getTopicMeta(props.data.topic, props.topics);

Expand All @@ -25,22 +28,24 @@ export function RootSection(props: {

return (
<div className="flex flex-col">
<div className="mb-14">
<button
className={`flex items-center w-full text-left select-none duration-300`}
onClick={handleClick}
>
<div
className={`h-8 w-8 inline-flex items-center justify-center duration-300 `}
{goesBeginning && (
<div className="mb-14">
<button
className={`flex items-center w-full text-left select-none duration-300`}
onClick={handleClick}
>
{open ? "▼" : "▶"}
</div>
<div className="flex justify-between w-full">
<h4 className="text-3xl ">Tx Validations - {props.era}</h4>
</div>
</button>
{open && <ValidationAccordion validations={props.validations} />}
</div>
<div
className={`h-8 w-8 inline-flex items-center justify-center duration-300 `}
>
{open ?? initialOpen ? "▼" : "▶"}
</div>
<div className="flex justify-between w-full">
<h4 className="text-3xl ">Tx Validations - {props.era}</h4>
</div>
</button>
{open ?? (initialOpen && <ValidationInformation />)}
</div>
)}
<h4 className="text-3xl">{topic.title}</h4>
{!!props.data.bytes && (
<HexBlock name="bytes (hex)" value={props.data.bytes} />
Expand All @@ -51,6 +56,24 @@ export function RootSection(props: {
{props.data.children?.map((c) => (
<DataSection key={c.identity} data={c} topics={props.topics} />
))}
{!goesBeginning && (
<div className="mb-14">
<button
className={`flex items-center w-full text-left select-none duration-300`}
onClick={handleClick}
>
<div
className={`h-8 w-8 inline-flex items-center justify-center duration-300 `}
>
{open ?? initialOpen ? "▼" : "▶"}
</div>
<div className="flex justify-between w-full">
<h4 className="text-3xl ">Tx Validations - {props.era}</h4>
</div>
</button>
{open ?? (initialOpen && <ValidationInformation />)}
</div>
)}
</div>
);
}
28 changes: 6 additions & 22 deletions web/app/components/Validations/Configurations/Configurations.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { useEffect } from "react";
import { Button } from "../../../components";
import { IContext, ProtocolType } from "../../../interfaces";
import { Tabs } from "./Tabs";

export function ConfigsModal({
closeModal,
protocolParams,
changeParam,
otherContext,
setOtherContext,
}: {
interface ConfigsModalProps {
closeModal: () => void;
protocolParams: ProtocolType[];
changeParam: (
index: number
) => (e: React.ChangeEvent<HTMLInputElement>) => void;
otherContext: IContext;
setOtherContext: (c: IContext) => void;
}) {
}

export function ConfigsModal({ closeModal }: ConfigsModalProps) {
// To close config modal on esc press
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
Expand All @@ -44,14 +33,9 @@ export function ConfigsModal({
>
+
</button>
<Tabs
otherContext={otherContext}
protocolParams={protocolParams}
changeParam={changeParam}
setOtherContext={setOtherContext}
/>
<Tabs />
<Button type="submit" color="pink" className="hover:bg-pink-400 mt-3">
Submit & Dissect
Submit
</Button>
</div>
</div>
Expand Down
136 changes: 136 additions & 0 deletions web/app/components/Validations/Configurations/ContextTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { useContext } from "react";
import { Button } from "../../../components/Button";
import { Input } from "../../../components/Input";
import { ValidationsContext } from "../../../contexts/validations.context";
import { EraType, Eras, NetworkType, Networks } from "../../../interfaces";
import { ByronPptParams } from "../../../utils";

export const ContextTab = () => {
const { context, setContext } = useContext(ValidationsContext);
const isByron = context.selectedEra === Eras.Byron;
const paramsList = isByron ? ByronPptParams : context.pptParams;
const networks: NetworkType[] = [
Networks.Mainnet,
Networks.Preprod,
Networks.Preview,
];
const eras = [
Eras.Byron,
Eras.ShelleyMA,
Eras.Alonzo,
Eras.Babbage,
Eras.Conway,
];
const changeParam =
(index: number) => (e: React.ChangeEvent<HTMLInputElement>) => {
setContext((prev) => {
const updatedParams = [...prev.pptParams];
updatedParams[index] = {
...updatedParams[index],
value:
Number(e.target.value) >= 0
? Number(e.target.value)
: updatedParams[index].value,
};
return { ...prev, pptParams: updatedParams };
});
};
const changeNetwork = (value: NetworkType) => () =>
setContext({ ...context, selectedNetwork: value });
const changeEra = (value: EraType) => () =>
setContext({ ...context, selectedEra: value });
const changeBlockSlot = (e: React.ChangeEvent<HTMLInputElement>) => {
setContext({ ...context, blockSlot: Number(e.target.value) });
};
return (
<div className="flex flex-col overflow-y-auto h-96">
<div className="text-left text-3xl mb-3">Protocol Parameters</div>
<div className="grid xl:grid-cols-5 lg:grid-cols-2 gap-3 text-left w-full p-2">
{paramsList.map((param, index) => (
<div key={param.name}>
<label htmlFor={param.name} className="">
{param.name.replace(/_/g, " ")}
</label>
<Input
id={param.name}
name={param.name}
type="number"
disabled={isByron}
value={Number(param.value).toString() ?? 0}
onChange={changeParam(index)}
className={`block w-full px-4 py-2 mt-1 border-2 bg-white border-black h-16 shadow shadow-black rounded-lg rounded-b-xl border-b-8 appearance-none text-black placeholder-gray-400 text-2xl outline-none
${
isByron
? "bg-slate-300 cursor-not-allowed"
: "focus:bg-pink-200 hover:bg-pink-200"
}`}
inputSize="small"
/>
</div>
))}
</div>
<hr className="border-2 border-black my-4" />
<div>
<div className="text-left text-3xl mt-3">Select a Network</div>
{/* To get the network from the form*/}
<input
defaultValue={context.selectedNetwork}
name="Network"
className="hidden"
/>
<div className="md:flex gap-4 p-2 grid grid-cols-2">
{networks.map((net) => (
<Button
key={net}
type="button"
onClick={changeNetwork(net as NetworkType)}
color="pink"
className={`${
context.selectedNetwork === net ? "bg-pink-400" : ""
}`}
>
{net}
</Button>
))}
</div>
</div>
<hr className="border-2 border-black my-4" />
<div>
<div className="text-left text-3xl mt-3">Select an Era</div>
{/* To get the era from the form*/}
<input
defaultValue={context.selectedEra}
name="Era"
className="hidden"
/>
<div className="xl:flex gap-4 p-2 grid grid-cols-2">
{eras.map((era) => (
<Button
key={era}
type="button"
onClick={changeEra(era as EraType)}
color="pink"
className={`
${context.selectedEra === era ? "bg-pink-400" : ""}
`}
>
{era}
</Button>
))}
</div>
</div>
<hr className="border-2 border-black my-4" />
<div>
<div className="text-left text-3xl mt-3">Select a Block Slot</div>
<Input
type="number"
name="Block_slot"
value={context.blockSlot}
onChange={changeBlockSlot}
className="focus:bg-pink-200"
inputSize="small"
/>
</div>
</div>
);
};
Loading

0 comments on commit a19b718

Please sign in to comment.