diff --git a/package-lock.json b/package-lock.json index 2a9796fb..14aa4f61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,8 @@ "react-toastify": "^10.0.6", "tailwind-merge": "^2.4.0", "tailwindcss-animate": "^1.0.7", - "vaul": "^0.9.1" + "vaul": "^0.9.1", + "zod": "^3.24.1" }, "devDependencies": { "@playwright/test": "^1.47.2", @@ -7419,6 +7420,15 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.24.1", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.1.tgz", + "integrity": "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index e6ef7213..c854b6a6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "react-toastify": "^10.0.6", "tailwind-merge": "^2.4.0", "tailwindcss-animate": "^1.0.7", - "vaul": "^0.9.1" + "vaul": "^0.9.1", + "zod": "^3.24.1" }, "devDependencies": { "@playwright/test": "^1.47.2", diff --git a/src/components/ProgramLoader/BinaryFileUpload.tsx b/src/components/ProgramLoader/BinaryFileUpload.tsx deleted file mode 100644 index be9cf390..00000000 --- a/src/components/ProgramLoader/BinaryFileUpload.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import { Input } from "../ui/input"; -import { ProgramUploadFileOutput } from "./types"; -import { decodeStandardProgram } from "@typeberry/pvm-debugger-adapter"; -import { RegistersArray } from "@/types/pvm.ts"; - -export const BinaryFileUpload = ({ - onFileUpload, - close, -}: { - onFileUpload: (val: ProgramUploadFileOutput) => void; - close?: () => void; -}) => { - let fileReader: FileReader; - - const handleFileRead = (e: ProgressEvent) => { - const arrayBuffer = e.target?.result; - - if (arrayBuffer instanceof ArrayBuffer) { - const uint8Array = new Uint8Array(arrayBuffer); - const { code, /*memory,*/ registers } = decodeStandardProgram(uint8Array, new Uint8Array()); - - onFileUpload({ - program: Array.from(code), - name: "custom", - initial: { - regs: Array.from(registers) as RegistersArray, - pc: 0, - pageMap: [], - // TODO: map memory properly - // memory: [...memory], - gas: 10000n, - }, - }); - } else { - console.error("Unexpected result type:", arrayBuffer); - } - }; - - const handleProgramUpload = (file: Blob) => { - fileReader = new FileReader(); - fileReader.onload = handleFileRead; - fileReader.readAsArrayBuffer(file); - }; - - return ( -
-

Upload program as a binary file

- e.stopPropagation()} - onChange={(e) => { - if (e.target.files?.length) { - handleProgramUpload(e.target.files[0]); - close?.(); - } - }} - /> -
- ); -}; diff --git a/src/components/ProgramLoader/Bytecode.tsx b/src/components/ProgramLoader/Bytecode.tsx deleted file mode 100644 index c087dd9e..00000000 --- a/src/components/ProgramLoader/Bytecode.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import { ProgramUploadFileOutput } from "./types"; -import { BinaryFileUpload } from "@/components/ProgramLoader/BinaryFileUpload.tsx"; - -export const Bytecode = ({ - onProgramLoad, -}: { - onProgramLoad: (val?: ProgramUploadFileOutput, error?: string) => void; -}) => { - const handleFileUpload = (val: ProgramUploadFileOutput) => { - onProgramLoad(val); - }; - - return ( -
- -
- ); -}; diff --git a/src/components/ProgramLoader/Examples.tsx b/src/components/ProgramLoader/Examples.tsx index 94f416ed..ad7eb111 100644 --- a/src/components/ProgramLoader/Examples.tsx +++ b/src/components/ProgramLoader/Examples.tsx @@ -106,7 +106,7 @@ const programs: { export const Examples = ({ onProgramLoad }: { onProgramLoad: (val: ProgramUploadFileOutput) => void }) => { return (
-

Load example test file

+

Load an example test file

diff --git a/src/components/ProgramLoader/Loader.tsx b/src/components/ProgramLoader/Loader.tsx index 097335c1..9b076306 100644 --- a/src/components/ProgramLoader/Loader.tsx +++ b/src/components/ProgramLoader/Loader.tsx @@ -1,8 +1,6 @@ import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; import { Button } from "../ui/button"; -import { Bytecode } from "./Bytecode"; import { Examples } from "./Examples"; -import { TextFileUpload } from "./TextFileUpload"; import { useState, useCallback, useEffect } from "react"; import { ProgramUploadFileOutput } from "./types"; import { useDebuggerActions } from "@/hooks/useDebuggerActions"; @@ -10,6 +8,7 @@ import { useAppDispatch, useAppSelector } from "@/store/hooks.ts"; import { setIsProgramEditMode } from "@/store/debugger/debuggerSlice.ts"; import { selectIsAnyWorkerLoading } from "@/store/workers/workersSlice"; import { isSerializedError } from "@/store/utils"; +import { ProgramFileUpload } from "@/components/ProgramLoader/ProgramFileUpload.tsx"; export const Loader = ({ setIsDialogOpen }: { setIsDialogOpen?: (val: boolean) => void }) => { const dispatch = useAppDispatch(); @@ -44,17 +43,19 @@ export const Loader = ({ setIsDialogOpen }: { setIsDialogOpen?: (val: boolean) = <> - JSON tests - Examples - RAW bytecode + Upload file + Start with examples
- { setProgramLoad(val); setIsSubmitted(false); }} + onParseError={(error) => { + setError(error); + }} /> @@ -65,16 +66,7 @@ export const Loader = ({ setIsDialogOpen }: { setIsDialogOpen?: (val: boolean) = }} /> - - { - setProgramLoad(val); - setIsSubmitted(false); - setError(error); - }} - /> - - {error && isSubmitted &&

{error}

} + {error && isSubmitted &&

{error}

}