Skip to content

Commit

Permalink
updating @ethui/form
Browse files Browse the repository at this point in the history
  • Loading branch information
naps62 committed May 7, 2024
1 parent 60ded08 commit 8e9071b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 480 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"@ethui/form": "0.0.6",
"@ethui/form": "file:../app/packages/form",
"@fontsource/roboto-mono": "^5.0.18",
"@headlessui/react": "^1.7.17",
"@heroicons/react": "^2.0.18",
"@mui/icons-material": "^5.15.15",
Expand Down
1 change: 1 addition & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@import "@fontsource/roboto-mono";

body {
}
60 changes: 56 additions & 4 deletions src/app/packages/form/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import Image from "next/image";
import { AbiForm } from "@ethui/form";
import { AbiForm, type AbiFunction, Debug } from "@ethui/form";
import {
Box,
Container,
Expand All @@ -11,11 +11,36 @@ import {
TextField,
Typography,
} from "@mui/material";
import { useState } from "react";
import { useCallback, useState } from "react";

function App() {
const [item, setItem] = useState<string>(
"function transfer(uint256[] amount)",
"function transfer(string[] amount)",
);

const [parsedItem, setParsedItem] = useState<AbiFunction | undefined>();
const [value, setValue] = useState<bigint | undefined>();
const [data, setData] = useState<`0x${string}` | undefined>();
const [args, setArgs] = useState<any[] | undefined>();

const onChange = useCallback(
({
item,
value,
data,
args,
}: {
item?: AbiFunction;
value?: bigint;
data?: `0x${string}`;
args?: any[];
}) => {
setParsedItem(item);
setArgs(args);
setData(data);
setValue(value);
},
[],
);

return (
Expand Down Expand Up @@ -52,7 +77,34 @@ function App() {
onChange={(e) => setItem(e.target.value)}
/>
<Box sx={{ mt: 2 }}>
<AbiForm abiItem={item} debug={false} preview={true} />
<Grid container>
<Grid item xs={12} md={4}>
<AbiForm abiItem={item} debug={false} onChange={onChange} />
</Grid>
<Grid item xs={12} md={8}>
<Paper sx={{ width: "100%", height: "100%" }}>
<Stack spacing={1} sx={{ p: 2 }}>
{parsedItem &&
args &&
parsedItem.inputs.map((input, i) => (
<div key={i}>
<Typography fontWeight="bold">
{input.name || i.toString()}:
</Typography>
<Debug value={args[i]} />
</div>
))}
<Typography fontWeight="bold">calldata:</Typography>
<Typography
fontFamily="monospace"
sx={{ overflowWrap: "break-word" }}
>
{data}
</Typography>
</Stack>
</Paper>
</Grid>
</Grid>
</Box>
</Paper>
</Stack>
Expand Down
Loading

0 comments on commit 8e9071b

Please sign in to comment.