Skip to content

Commit

Permalink
feat: connection to front end
Browse files Browse the repository at this point in the history
  • Loading branch information
mikarasv committed Apr 5, 2024
1 parent f1829d7 commit cdd7ffa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 83 deletions.
4 changes: 1 addition & 3 deletions napi-pallas/src/validations/babbage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ fn validate_babbage_ins_not_empty(mtx: &BabbageMintedTx) -> Validation {
}

pub fn validate_babbage(mtx_b: &BabbageMintedTx) -> Validations {
let out = Validations::new()
.add_new_validation(validate_babbage_ins_not_empty(&mtx_b))
.add_new_validation(validate_babbage_ins_not_empty(&mtx_b));
let out = Validations::new().add_new_validation(validate_babbage_ins_not_empty(&mtx_b));
out
}
35 changes: 27 additions & 8 deletions web/app/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,37 @@ export const P1 = Paragraph;
export function RootSection(props: {
data: Section;
topics: Record<string, TopicMeta>;
validations: IValidation[];
}) {
const [open, setOpen] = useState(false);
const handleClick = () => setOpen(!open);
const topic = getTopicMeta(props.data.topic, props.topics);

if (props.data.error)
return (
<div className="block mt-8 p-4 border-2 bg-red-200 border-red-700 shadow shadow-black rounded-lg text-2xl">
<h4 className="text-3xl">{topic.description}</h4>
{props.data.error}
</div>
);

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 `}
>
{open ? "▼" : "▶"}
</div>
<h4 className="text-3xl ">Tx Validations</h4>
</button>
{open && <ValidationAccordion validations={props.validations} />}
</div>
<h4 className="text-3xl">{topic.title}</h4>
{!props.data.error && topic.description}
{!!props.data.error && (
<div className="block mt-8 p-4 border-2 bg-red-200 border-red-700 shadow shadow-black rounded-lg text-2xl">
{props.data.error}
</div>
)}
{!!props.data.bytes && (
<HexBlock name="bytes (hex)" value={props.data.bytes} />
)}
Expand All @@ -74,7 +93,7 @@ export function RootSection(props: {
{props.data.children?.map((c) => (
<DataSection key={c.identity} data={c} topics={props.topics} />
))}
</>
</div>
);
}

Expand Down
81 changes: 9 additions & 72 deletions web/app/routes/tx.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { ActionFunctionArgs, json, type MetaFunction } from "@remix-run/node";
import { Form, useActionData } from "@remix-run/react";
import { useState } from "react";
import {
Button,
logCuriosity,
RootSection,
ValidationAccordion,
} from "../components";
import { Button, logCuriosity, RootSection } from "../components";
import * as server from "./tx.server";
import TOPICS from "./tx.topics";

Expand All @@ -32,8 +26,12 @@ export async function action({ request }: ActionFunctionArgs) {
const raw = formData.get("raw");

if (raw) {
const res = server.safeParseTx(raw.toString());
return json({ ...res, raw });
const { section, validations } = server.safeParseTx(raw.toString());
return json({
...section,
raw,
...validations,
});
} else {
return json({ error: "an empty value? seriously?" });
}
Expand All @@ -59,54 +57,9 @@ function ExampleCard(props: { title: string; address: string }) {
export default function Index() {
const data = useActionData();

const [open, setOpen] = useState(false);
const handleClick = () => setOpen(!open);

logCuriosity(data);

const validations: IValidation[] = [
{ name: "Non empty inputs", value: true, description: "Sucessful" },
{
name: "All inputs in utxos",
value: false,
description:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro id maiores exercitationem asperiores molestias assumenda doloremque magnam fugit. Iure dolorum fugit facilis autem incidunt vero necessitatibus consectetur ducimus recusandae blanditiis!",
},
{ name: "Validity interval", value: true, description: "Sucessful" },
{ name: "Fee", value: true, description: "Sucessful" },
{
name: "Preservation of value",
value: false,
description:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro id maiores exercitationem asperiores molestias assumenda doloremque magnam fugit. Iure dolorum fugit facilis autem incidunt vero necessitatibus consectetur ducimus recusandae blanditiis!",
},
{
name: "Min lovelace per UTxO",
value: false,
description:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro id maiores exercitationem asperiores molestias assumenda doloremque magnam fugit. Iure dolorum fugit facilis autem incidunt vero necessitatibus consectetur ducimus recusandae blanditiis!",
},
{ name: "Output value size", value: true, description: "Successful" },
{ name: "Network Id", value: true, description: "Successful" },
{ name: "Tx size", value: true, description: "Successful" },
{ name: "Tx execution units", value: true, description: "Successful" },
{ name: "Minting", value: true, description: "Successful" },
{
name: "Well formed",
value: false,
description:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro id maiores exercitationem asperiores molestias assumenda doloremque magnam fugit. Iure dolorum fugit facilis autem incidunt vero necessitatibus consectetur ducimus recusandae blanditiis!",
},
{ name: "Script witness", value: true, description: "Successful" },
{ name: "Languages", value: true, description: "Successful" },
{
name: "Auxiliary data hash",
value: false,
description:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro id maiores exercitationem asperiores molestias assumenda doloremque magnam fugit. Iure dolorum fugit facilis autem incidunt vero necessitatibus consectetur ducimus recusandae blanditiis!",
},
{ name: "Script data hash", value: true, description: "Successful" },
];
const validations: IValidation[] = data?.validations || [];

return (
<main className="mt-10 px-4">
Expand Down Expand Up @@ -146,23 +99,7 @@ export default function Index() {
)}

{!!data && (
<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 `}
>
{open ? "▼" : "▶"}
</div>
<h4 className="text-3xl ">Tx Validations</h4>
</button>
{open && <ValidationAccordion validations={validations} />}
</div>
<RootSection data={data} topics={TOPICS} />
</div>
<RootSection data={data} topics={TOPICS} validations={validations} />
)}
</main>
);
Expand Down

0 comments on commit cdd7ffa

Please sign in to comment.