diff --git a/components/Tracer/index.tsx b/components/Tracer/index.tsx index f87915f..3403dd2 100644 --- a/components/Tracer/index.tsx +++ b/components/Tracer/index.tsx @@ -153,7 +153,7 @@ export const Tracer = () => { {debugMode === ProgramDebugMode.Execution ? ( - trace === undefined ? ( + compilationState !== ProgramCompilationState.CompilationSuccess ? (
{compilationState === ProgramCompilationState.Idle ? 'Run the app to get debug info' @@ -187,7 +187,7 @@ export const Tracer = () => { ) ) ) : debugMode === ProgramDebugMode.Sierra ? ( - trace === undefined ? ( + compilationState !== ProgramCompilationState.CompilationSuccess ? (
{compilationState === ProgramCompilationState.Idle ? 'Run the app to get debug info' @@ -212,6 +212,7 @@ export const Tracer = () => { {debugMode !== ProgramDebugMode.Proof ? (
void debugMode: ProgramDebugMode + compilationState: ProgramCompilationState }) { return (
- {trace && ( -
- {debugMode === ProgramDebugMode.Execution && ( -
-
-
- Registers -
-
- - - -
+ {trace && + compilationState === ProgramCompilationState.CompilationSuccess && ( +
+ {debugMode === ProgramDebugMode.Execution && ( +
+
+
+ Registers +
+
+ + + +
+
+
+
+ Execution steps +
+
+
+ Current: {executionTraceStepNumber + 1}, Total:{' '} + {trace?.length} +
+
+
-
-
- Execution steps -
-
-
- Current: {executionTraceStepNumber + 1}, Total:{' '} - {trace?.length} -
-
-
-
- )} -
-
- Callstack -
-
- - - - {debugMode === ProgramDebugMode.Execution && ( - <> - - - - - )} - - - - - - {currentCallstackEntry?.map((callstackEntry, index) => { - if ( - callstackEntry.fn_name || - debugMode === ProgramDebugMode.Execution - ) { - return ( - - {debugMode === ProgramDebugMode.Execution && ( - <> - - - - - )} - - + + + ) + } + })} + +
FP - CALL PC - - RET PC - - FN NAME - - PARAMETERS -
- {callstackEntry.fp} - - {callstackEntry.call_pc} - - {callstackEntry.ret_pc} - - {callstackEntry.fn_name} - - {callstackEntry?.params?.map( - ( - param: { type_name: string; value: number[] }, - index, - array, - ) => ( -
-
- {param.value.length > 1 - ? `[${param.value.join(', ')}]` - : param.value[0]} - - -
- - {index < array.length - 1 ? ',\u00A0' : ''} - -
- ), + )} +
+
+ Callstack +
+
+ + + + {debugMode === ProgramDebugMode.Execution && ( + <> + + + + + )} + + + + + + {currentCallstackEntry?.map((callstackEntry, index) => { + if ( + callstackEntry.fn_name || + debugMode === ProgramDebugMode.Execution + ) { + return ( + + {debugMode === ProgramDebugMode.Execution && ( + <> + + + + )} - - - ) - } - })} - -
FP + CALL PC + + RET PC + + FN NAME + + PARAMETERS +
+ {callstackEntry.fp} + + {callstackEntry.call_pc} + + {callstackEntry.ret_pc} +
-
-
- - )} +
+ {callstackEntry.fn_name} + + {callstackEntry?.params?.map( + ( + param: { + type_name: string + value: number[] + }, + index, + array, + ) => ( +
+
+ {param.value.length > 1 + ? `[${param.value.join(', ')}]` + : param.value[0]} + + +
+ + {index < array.length - 1 + ? ',\u00A0' + : ''} + +
+ ), + )} +
+
+
+
+ )}
) } diff --git a/components/ui/MultiButton.tsx b/components/ui/MultiButton.tsx index 8ac68a8..7859d06 100644 --- a/components/ui/MultiButton.tsx +++ b/components/ui/MultiButton.tsx @@ -4,7 +4,7 @@ import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/20/solid' import { ReadyState } from 'react-use-websocket' -import { AppUiContext } from 'context/appUiContext' +import { AppUiContext, LogType } from 'context/appUiContext' import { CairoVMApiContext, ProgramCompilationState, @@ -21,7 +21,7 @@ interface MultiButtonProps { const MultiButton = ({ onCompileRun }: MultiButtonProps) => { const [selected, setSelected] = useState('run') - const { addToConsoleLog } = useContext(AppUiContext) + const { addToConsoleLog, consoleLog } = useContext(AppUiContext) const { compilationState, readyState, @@ -29,12 +29,43 @@ const MultiButton = ({ onCompileRun }: MultiButtonProps) => { proof, executionState, proofRequired, + provingIsNotSupported, } = useContext(CairoVMApiContext) + useEffect(() => { + let timeoutId: NodeJS.Timeout + if (readyState === ReadyState.OPEN) { - addToConsoleLog('App initialised') + const hasInitMessage = consoleLog.some( + (item) => item.message === 'App initialised', + ) + const lastMessageIsError = + consoleLog[consoleLog.length - 1]?.message === + 'Error: Connection closed' + + if (!hasInitMessage) { + addToConsoleLog('App initialised') + } else if (lastMessageIsError) { + addToConsoleLog('App reconnected') + } + } else if (readyState === ReadyState.CLOSED) { + timeoutId = setTimeout(() => { + const lastMessage = consoleLog[consoleLog.length - 1]?.message + if ( + readyState === ReadyState.CLOSED && + lastMessage !== 'Error: Connection closed' + ) { + addToConsoleLog('Error: Connection closed', LogType.Error) + } + }, 10000) + } + + return () => { + if (timeoutId) { + clearTimeout(timeoutId) + } } - }, [readyState]) + }, [readyState, consoleLog, addToConsoleLog]) const handleMainButtonClick = () => { switch (selected) { @@ -57,7 +88,8 @@ const MultiButton = ({ onCompileRun }: MultiButtonProps) => { disabled={ readyState !== ReadyState.OPEN || compilationState === ProgramCompilationState.Compiling || - (proofRequired && + (!provingIsNotSupported && + proofRequired && !proof && (executionState === ProgramExecutionState.Executing || executionState === ProgramExecutionState.Success)) @@ -74,7 +106,8 @@ const MultiButton = ({ onCompileRun }: MultiButtonProps) => { disabled={ readyState !== ReadyState.OPEN || compilationState === ProgramCompilationState.Compiling || - (proofRequired && + (!provingIsNotSupported && + proofRequired && !proof && (executionState === ProgramExecutionState.Executing || executionState === ProgramExecutionState.Success)) diff --git a/context/cairoVMApiContext.tsx b/context/cairoVMApiContext.tsx index 92eadf6..3587444 100644 --- a/context/cairoVMApiContext.tsx +++ b/context/cairoVMApiContext.tsx @@ -337,6 +337,7 @@ export const CairoVMApiProvider: React.FC = ({ { share: false, shouldReconnect: () => true, + onError: (event) => console.error('WebSocket error:', event), }, ) @@ -451,7 +452,6 @@ export const CairoVMApiProvider: React.FC = ({ setExecutionState(ProgramExecutionState.Executing) setProofRequired(isProofRequired) setProof(undefined) - sendJsonMessage({ cairo_program_code: cairoCode, program_arguments: programArguments,