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 diff --git a/state/actions/deployHook.tsx b/state/actions/deployHook.tsx index b1eaaf8..fd8d276 100644 --- a/state/actions/deployHook.tsx +++ b/state/actions/deployHook.tsx @@ -54,15 +54,15 @@ export const prepareDeployHookTx = async ( account: IAccount & { name?: string }, data: SetHookData ) => { - if ( - !state.files || - state.files.length === 0 || - !state.files?.[state.active]?.compiledContent - ) { + const activeFile = state.files[state.active]?.compiledContent + ? state.files[state.active] + : state.files.filter((file) => file.compiledContent)[0]; + + if (!state.files || state.files.length === 0) { return; } - if (!state.files?.[state.active]?.compiledContent) { + if (!activeFile?.compiledContent) { return; } if (!state.client) { @@ -99,7 +99,7 @@ export const prepareDeployHookTx = async ( { Hook: { CreateCode: arrayBufferToHex( - state.files?.[state.active]?.compiledContent + activeFile?.compiledContent ).toUpperCase(), HookOn: calculateHookOn(hookOnValues), HookNamespace,