diff --git a/frontend/src/components/Editor/EditorComponents/Editor.tsx b/frontend/src/components/Editor/EditorComponents/Editor.tsx index cfdf8c07..9d7d949c 100644 --- a/frontend/src/components/Editor/EditorComponents/Editor.tsx +++ b/frontend/src/components/Editor/EditorComponents/Editor.tsx @@ -53,6 +53,30 @@ const fetchWizardData = (req: string): Promise => { return request('launchpad-create-indexer', req); }; +const fetchGeneratedCode = async (contractFilter: string, selectedMethods: Method[], selectedEvents?: Event[]) => { + try { + const response = await fetch('/api/generateCode', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ contractFilter, selectedMethods, selectedEvents }), + }); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const data = await response.json(); + + if (!data.hasOwnProperty('jsCode') || !data.hasOwnProperty('sqlCode')) { + throw new Error('No code was returned from the server with properties jsCode and sqlCode'); + } + + return data; + } catch (error) { + throw error; + } +}; + const Editor: React.FC = (): ReactElement => { const { indexerDetails, isCreateNewIndexer } = useContext(IndexerDetailsContext); @@ -131,38 +155,13 @@ const Editor: React.FC = (): ReactElement => { return; }; - const generateCode = async (contractFilter: string, selectedMethods: Method[], selectedEvents?: Event[]) => { - try { - const response = await fetch('/api/generateCode', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ contractFilter, selectedMethods, selectedEvents }), - }); - if (!response.ok) { - throw new Error('Network response was not ok'); - } - const data = await response.json(); - - if (!data.hasOwnProperty('jsCode') || !data.hasOwnProperty('sqlCode')) { - throw new Error('No code was returned from the server with properties jsCode and sqlCode'); - } - - return data; - } catch (error) { - throw error; - } - }; - useEffect(() => { (async () => { try { const { wizardContractFilter, wizardMethods, wizardEvents } = await fetchWizardData(''); if (wizardContractFilter === 'noFilter') return; - - const { jsCode, sqlCode } = await generateCode(wizardContractFilter, wizardMethods, wizardEvents); + const { jsCode, sqlCode } = await fetchGeneratedCode(wizardContractFilter, wizardMethods, wizardEvents); const wrappedIndexingCode = wrapCode(jsCode) ? wrapCode(jsCode) : jsCode; const { validatedCode, validatedSchema } = reformatAll(wrappedIndexingCode, sqlCode); @@ -207,7 +206,6 @@ const Editor: React.FC = (): ReactElement => { useEffect(() => { const { error: schemaError } = validateSQLSchema(schema); const { error: codeError } = validateJSCode(indexingCode); - if (schemaError || codeError) { if (schemaError) schemaErrorHandler(schemaError); if (codeError) indexerErrorHandler(codeError); @@ -215,7 +213,7 @@ const Editor: React.FC = (): ReactElement => { } handleCodeGen(); - }, [fileName]); + }, [fileName, launchPadDefaultSchema]); useEffect(() => { cacheToLocal(); diff --git a/frontend/src/components/Editor/EditorComponents/ResizableLayoutEditor.jsx b/frontend/src/components/Editor/EditorComponents/ResizableLayoutEditor.jsx index 73b55e16..69843334 100644 --- a/frontend/src/components/Editor/EditorComponents/ResizableLayoutEditor.jsx +++ b/frontend/src/components/Editor/EditorComponents/ResizableLayoutEditor.jsx @@ -161,8 +161,10 @@ export default function ResizableLayoutEditor({ sizeThresholdFirst: 60, sizeThresholdSecond: 20, }); + const defaultCode = launchPadDefaultCode ? launchPadDefaultCode : contextCode ? contextCode : originalIndexingCode; const defaultSchema = launchPadDefaultSchema ? launchPadDefaultSchema : contextSchema ? contextSchema : originalSQLCode; + return (
{/* Code Editor */}