From 135f0c91a1f7e3998f463f1c91f5981c995d692a Mon Sep 17 00:00:00 2001 From: Valtteri Karesto Date: Wed, 22 Jun 2022 11:06:15 +0300 Subject: [PATCH] Fixes #213 and fixes #200 --- components/DeployEditor.tsx | 17 ++++++++++++++--- components/SetHookDialog.tsx | 13 ++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/components/DeployEditor.tsx b/components/DeployEditor.tsx index e891c25..d387a20 100644 --- a/components/DeployEditor.tsx +++ b/components/DeployEditor.tsx @@ -34,7 +34,9 @@ const DeployEditor = () => { const [showContent, setShowContent] = useState(false); - const activeFile = snap.files[snap.active]; + const activeFile = snap.files[snap.active]?.compiledContent + ? snap.files[snap.active] + : snap.files.filter((file) => file.compiledContent)[0]; const compiledSize = activeFile?.compiledContent?.byteLength || 0; const color = compiledSize > FILESIZE_BREAKPOINTS[1] @@ -60,12 +62,21 @@ const DeployEditor = () => { {activeFile?.lastCompiled && ( )} + {activeFile.compiledContent?.byteLength && ( ({filesize(activeFile.compiledContent.byteLength)}) )} + {activeFile.compiledContent?.byteLength && + activeFile.compiledContent?.byteLength >= 64000 && ( + + + File size is larger than 64kB, cannot set hook! + + + )} @@ -119,8 +130,8 @@ const DeployEditor = () => { className="hooks-editor" defaultLanguage={"wat"} language={"wat"} - path={`file://tmp/c/${snap.files?.[snap.active]?.name}.wat`} - value={snap.files?.[snap.active]?.compiledWatContent || ""} + path={`file://tmp/c/${activeFile?.name}.wat`} + value={activeFile?.compiledWatContent || ""} beforeMount={(monaco) => { monaco.languages.register({ id: "wat" }); monaco.languages.setLanguageConfiguration("wat", wat.config); diff --git a/components/SetHookDialog.tsx b/components/SetHookDialog.tsx index bdaf04c..263cafa 100644 --- a/components/SetHookDialog.tsx +++ b/components/SetHookDialog.tsx @@ -140,6 +140,16 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo( return null; } + const tooLargeFile = () => { + const activeFile = snap.files[snap.active].compiledContent + ? snap.files[snap.active] + : snap.files.filter((file) => file.compiledContent)[0]; + return Boolean( + activeFile?.compiledContent?.byteLength && + activeFile?.compiledContent?.byteLength >= 64000 + ); + }; + const onSubmit: SubmitHandler = async (data) => { const currAccount = state.accounts.find( (acc) => acc.address === account.address @@ -164,7 +174,8 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo( variant={"secondary"} disabled={ account.isLoading || - !snap.files.filter((file) => file.compiledWatContent).length + !snap.files.filter((file) => file.compiledWatContent).length || + tooLargeFile() } > Set Hook