From dd7966aba9e65ff48dac092daa62ef7e06272482 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 17 Oct 2023 09:57:35 +0100 Subject: [PATCH] Show errors and warnings --- apps/circuit-compiler/src/app/app.tsx | 39 ++++++++++--- .../src/app/components/container.tsx | 10 +++- .../src/app/components/feedback.tsx | 54 ++++++++++++++++++ .../src/app/components/feedbackAlert.tsx | 31 +++++++++++ .../src/app/components/versions.tsx | 23 +++----- .../src/app/reducers/state.ts | 16 +++++- .../src/app/services/circomPluginClient.ts | 55 +++++++++---------- apps/circuit-compiler/src/app/types/index.ts | 35 +++++++++++- apps/circuit-compiler/src/css/app.css | 52 +++++++++++++++++- .../helper/src/lib/remix-ui-helper.ts | 2 +- pkg/index.js | 0 11 files changed, 259 insertions(+), 58 deletions(-) create mode 100644 apps/circuit-compiler/src/app/components/feedback.tsx create mode 100644 apps/circuit-compiler/src/app/components/feedbackAlert.tsx delete mode 100644 pkg/index.js diff --git a/apps/circuit-compiler/src/app/app.tsx b/apps/circuit-compiler/src/app/app.tsx index cdb36783ee..9c1cf7af46 100644 --- a/apps/circuit-compiler/src/app/app.tsx +++ b/apps/circuit-compiler/src/app/app.tsx @@ -28,35 +28,42 @@ function App() { plugin.on('fileManager', 'currentFileChanged', (filePath) => { if (filePath.endsWith('.circom')) { dispatch({ type: 'SET_FILE_PATH', payload: filePath }) + plugin.parse(filePath) } else { dispatch({ type: 'SET_FILE_PATH', payload: '' }) } }) // @ts-ignore - plugin.on('editor', 'contentChanged', async () => { + plugin.on('editor', 'contentChanged', async (path: string, content: string) => { setIsContentChanged(true) + if (path.endsWith('.circom')) { + plugin.parse(path, content) + } }) setPlugin(plugin) }) // compiling events plugin.internalEvents.on('circuit_compiling_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'compiling' })) - plugin.internalEvents.on('circuit_compiling_done', (signalInputs) => { + plugin.internalEvents.on('circuit_compiling_done', (signalInputs: string[]) => { signalInputs = (signalInputs || []).filter(input => input) dispatch({ type: 'SET_SIGNAL_INPUTS', payload: signalInputs }) - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) + compilerSuccess() }) - plugin.internalEvents.on('circuit_compiling_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })) + plugin.internalEvents.on('circuit_compiling_errored', compilerErrored) // r1cs events plugin.internalEvents.on('circuit_generating_r1cs_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'generating' })) - plugin.internalEvents.on('circuit_generating_r1cs_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })) - plugin.internalEvents.on('circuit_generating_r1cs_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })) + plugin.internalEvents.on('circuit_generating_r1cs_done', compilerSuccess) + plugin.internalEvents.on('circuit_generating_r1cs_errored', compilerErrored) // witness events plugin.internalEvents.on('circuit_computing_witness_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'computing' })) - plugin.internalEvents.on('circuit_computing_witness_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })) - plugin.internalEvents.on('circuit_computing_witness_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })) + plugin.internalEvents.on('circuit_computing_witness_done', compilerSuccess) + plugin.internalEvents.on('circuit_computing_witness_errored', compilerErrored) + + // parsing events + plugin.internalEvents.on('circuit_parsing_done', (_, filePathToId) => dispatch({ type: 'SET_FILE_PATH_TO_ID', payload: filePathToId })) }, []) useEffect(() => { @@ -89,6 +96,22 @@ function App() { setLocale(currentLocale) } + const compilerErrored = (err: ErrorEvent) => { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' }) + try { + const report = JSON.parse(err.message) + + dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: report }) + } catch (e) { + dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: err.message }) + } + } + + const compilerSuccess = () => { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) + dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: null }) + } + const value = { appState, dispatch, diff --git a/apps/circuit-compiler/src/app/components/container.tsx b/apps/circuit-compiler/src/app/components/container.tsx index 16fce4e79e..552430adec 100644 --- a/apps/circuit-compiler/src/app/components/container.tsx +++ b/apps/circuit-compiler/src/app/components/container.tsx @@ -9,6 +9,7 @@ import { Configurations } from './configurations' import { CircuitActions } from './actions' import { WitnessToggler } from './witnessToggler' import { WitnessSection } from './witness' +import { CompilerFeedback } from './feedback' export function Container () { const circuitApp = useContext(CircuitAppContext) @@ -18,6 +19,10 @@ export function Container () { circuitApp.plugin.call('notification', 'modal', { id: 'modal_circuit_compiler_license', title: 'Compiler License', message }) } + const handleVersionSelect = (version: string) => { + circuitApp.dispatch({ type: 'SET_COMPILER_VERSION', payload: version }) + } + return (
@@ -29,7 +34,7 @@ export function Container () { showCompilerLicense()}> - + @@ -40,6 +45,9 @@ export function Container () { + + +
diff --git a/apps/circuit-compiler/src/app/components/feedback.tsx b/apps/circuit-compiler/src/app/components/feedback.tsx new file mode 100644 index 0000000000..1b9ad7aecd --- /dev/null +++ b/apps/circuit-compiler/src/app/components/feedback.tsx @@ -0,0 +1,54 @@ +import { useState } from 'react' +import { CompilerFeedbackProps } from '../types' +import { RenderIf } from '@remix-ui/helper' +import {CopyToClipboard} from '@remix-ui/clipboard' +import { FeedbackAlert } from './feedbackAlert' + +export function CompilerFeedback ({ feedback, filePathToId }: CompilerFeedbackProps) { + const [ showException, setShowException ] = useState(true) + + const handleCloseException = () => { + setShowException(false) + } + + return ( +
+
+ +
+ { feedback } +
+ +
+
+ + + +
+
+
+ + <> + { + Array.isArray(feedback) && feedback.map((response, index) => ( +
+ +
+ +
+
+ +
+ +
+
+
+ ) + ) + } + +
+
+
+ ) +} diff --git a/apps/circuit-compiler/src/app/components/feedbackAlert.tsx b/apps/circuit-compiler/src/app/components/feedbackAlert.tsx new file mode 100644 index 0000000000..5c9e092ab4 --- /dev/null +++ b/apps/circuit-compiler/src/app/components/feedbackAlert.tsx @@ -0,0 +1,31 @@ +import { useState } from 'react' +import { FeedbackAlertProps } from '../types' +import { RenderIf } from '@remix-ui/helper' +import {CopyToClipboard} from '@remix-ui/clipboard' + +export function FeedbackAlert ({ message, location }: FeedbackAlertProps) { + const [ showAlert, setShowAlert] = useState(true) + + const handleCloseAlert = () => { + setShowAlert(false) + } + + return ( + + <> + { message } + + { location } + +
+ +
+
+ + + +
+ +
+ ) +} diff --git a/apps/circuit-compiler/src/app/components/versions.tsx b/apps/circuit-compiler/src/app/components/versions.tsx index e4e095c26c..4b129d8225 100644 --- a/apps/circuit-compiler/src/app/components/versions.tsx +++ b/apps/circuit-compiler/src/app/components/versions.tsx @@ -1,28 +1,21 @@ import { RenderIf } from "@remix-ui/helper"; -import { useContext } from "react"; -import { CircuitAppContext } from "../contexts"; +import { AppState } from "../types"; -export function VersionList () { - const { appState, dispatch } = useContext(CircuitAppContext) - - const handleVersionSelect = (version: string) => { - dispatch({ type: 'SET_COMPILER_VERSION', payload: version }) - } - - const versionList = Object.keys(appState.versionList) +export function VersionList ({ currentVersion, versionList, setVersion }: { versionList: AppState['versionList'], currentVersion: string, setVersion: (version: string) => void }) { + const versionListKeys = Object.keys(versionList) return (