From 4f558492d72196d3cfaad1527aa391b2e380146f Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 8 Aug 2024 15:27:31 -0400 Subject: [PATCH] feat: wrap generate code --- .../Editor/EditorComponents/Editor.tsx | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/Editor/EditorComponents/Editor.tsx b/frontend/src/components/Editor/EditorComponents/Editor.tsx index 6247e04c..1ca0de9c 100644 --- a/frontend/src/components/Editor/EditorComponents/Editor.tsx +++ b/frontend/src/components/Editor/EditorComponents/Editor.tsx @@ -15,7 +15,14 @@ import { } from '@/constants/Strings'; import { IndexerDetailsContext } from '@/contexts/IndexerDetailsContext'; import { useModal } from '@/contexts/ModalContext'; -import { defaultCode, defaultSchema, defaultSchemaTypes, formatIndexingCode, formatSQL } from '@/utils/formatters'; +import { + defaultCode, + defaultSchema, + defaultSchemaTypes, + formatIndexingCode, + formatSQL, + wrapCode, +} from '@/utils/formatters'; import { getLatestBlockHeight } from '@/utils/getLatestBlockHeight'; import IndexerRunner from '@/utils/indexerRunner'; import { PgSchemaTypeGen } from '@/utils/pgSchemaTypeGen'; @@ -141,25 +148,23 @@ const Editor: React.FC = (): ReactElement => { }; useEffect(() => { - const fetchData = async () => { + (async () => { try { - const response = await fetchWizardData(''); - const { wizardContractFilter, wizardMethods, wizardEvents } = response; + const { wizardContractFilter, wizardMethods, wizardEvents } = await fetchWizardData(''); - if (wizardContractFilter === 'noFilter') { - return; - } + if (wizardContractFilter === 'noFilter') return; + + const { jsCode, sqlCode } = await generateCode(wizardContractFilter, wizardMethods, wizardEvents); + const wrappedIndexingCode = wrapCode(jsCode) ? wrapCode(jsCode) : jsCode; + const { validatedCode, validatedSchema } = reformatAll(wrappedIndexingCode, sqlCode); - const codeResponse = await generateCode(wizardContractFilter, wizardMethods, wizardEvents); - const { validatedCode, validatedSchema } = reformatAll(codeResponse.jsCode, codeResponse.sqlCode); validatedCode && setIndexingCode(validatedCode); validatedSchema && setSchema(validatedSchema); } catch (error: unknown) { //todo: figure out best course of action for user if api fails console.error(error); } - }; - fetchData(); + })(); }, []); useEffect(() => {