From e38a9c9bc8896614bb3f266a52f9d2f47242b737 Mon Sep 17 00:00:00 2001 From: Sara <88407794+mikarasv@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:37:55 -0300 Subject: [PATCH] feat: introduce tx validation design (#8) --- web/app/components.tsx | 127 +++++++++++++++++++++++++++++++++-------- web/app/routes/tx.tsx | 91 +++++++++++++++++++++++++++-- 2 files changed, 188 insertions(+), 30 deletions(-) diff --git a/web/app/components.tsx b/web/app/components.tsx index 33bf159..aad70cb 100644 --- a/web/app/components.tsx +++ b/web/app/components.tsx @@ -1,5 +1,6 @@ -import { PropsWithChildren } from "react"; import { Attribute, type Section } from "napi-pallas"; +import { PropsWithChildren, useState } from "react"; +import { IValidation } from "./routes/tx"; export type TopicMeta = { title: string; @@ -43,7 +44,7 @@ export function HexBlock(props: { name: string; value: string }) { ); } -export function Paragraph(props: PropsWithChildren<{}>) { +export function Paragraph(props: PropsWithChildren) { return
{props.children}
; } @@ -59,13 +60,11 @@ export function RootSection(props: { <>-{topic.title}
- {topic.description} - {!!props.data.error && ( -- {props.data.error} + + {open && ( + <> + {topic.description} + {!!props.data.error && ( ++ {props.data.error} ++ )} + {props.data.attributes?.map((c) => ( ++ ))} + {props.data.children?.map((c) => ( + + ))} + {!props.data.attributes?.length && !props.data.children?.length && ( + + )} + {!!props.data.bytes && ( + + )} + > )} ); @@ -145,7 +160,7 @@ export function TextArea(props: { name: string; placeholder?: string }) { } export function logCuriosity(data: any) { - if (!!data) { + if (data) { console.group("CURIOUS FELLOW, EH?"); console.log("hello there! want to learn how we parse the data?"); console.log( @@ -159,3 +174,65 @@ export function logCuriosity(data: any) { console.groupEnd(); } } + +export function AccordionItem({ validation }: { validation: IValidation }) { + const [open, setOpen] = useState(false); + const handleClick = () => setOpen(!open); + return ( + ++ ); +} + +export function ValidationAccordion(props: { validations: IValidation[] }) { + return ( ++ +++ + +++ {open && ( ++{validation.description}
+ )} ++ {props.validations.map((v) => ( ++ ); +} diff --git a/web/app/routes/tx.tsx b/web/app/routes/tx.tsx index d88b14b..bc4b149 100644 --- a/web/app/routes/tx.tsx +++ b/web/app/routes/tx.tsx @@ -1,9 +1,25 @@ import { ActionFunctionArgs, json, type MetaFunction } from "@remix-run/node"; import { Form, useActionData } from "@remix-run/react"; -import { Button, logCuriosity, RootSection } from "~/components"; +import { useState } from "react"; +import { + Button, + logCuriosity, + RootSection, + ValidationAccordion, +} from "../components"; import * as server from "./tx.server"; import TOPICS from "./tx.topics"; +export interface IValidation { + name: string; + value: boolean; + description: string; +} + +export interface IValidations { + validations: IValidation[]; +} + export const meta: MetaFunction = () => { return [ { title: "Cardano Tx - Lovelace Anatomy" }, @@ -13,9 +29,9 @@ export const meta: MetaFunction = () => { export async function action({ request }: ActionFunctionArgs) { const formData = await request.formData(); - let raw = formData.get("raw"); + const raw = formData.get("raw"); - if (!!raw) { + if (raw) { const res = server.safeParseTx(raw.toString()); return json({ ...res, raw }); } else { @@ -41,10 +57,57 @@ function ExampleCard(props: { title: string; address: string }) { } export default function Index() { - const data: any = useActionData(); + 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" }, + ]; + return (+ ))} + ); } Cardano Tx
@@ -82,7 +145,25 @@ export default function Index() { > )} - {!!data &&} + {!!data && ( + ++ )}+ + {open &&+} + +