import React, { Component, ReactNode } from 'react'; import { HiExclamationTriangle } from 'react-icons/hi2'; import { Card, CardContent } from '../../../ui/Card'; import { Button } from '../../../ui/Button'; import Typography from '../../../ui/Typography'; import { useBlockTesterStore } from '../../../../stores/blockTesterStore'; import { Logger } from '@hashgraphonline/standards-sdk'; const logger = new Logger({ module: 'ErrorBoundary' }); interface ErrorBoundaryProps { children: ReactNode; fallback?: React.ComponentType<{ error: Error; resetError: () => void }>; } interface ErrorBoundaryState { hasError: boolean; error: Error | null; } class BlockTesterErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { logger.error('Block Tester Error Boundary caught an error', { error: error.message, errorInfo }); if (typeof window !== 'undefined' && (window as any).electronAPI?.logError) { (window as any).electronAPI.logError('BlockTester', { error: error.message, stack: error.stack, componentStack: errorInfo.componentStack }); } try { useBlockTesterStore.getState().addError({ type: 'runtime', source: 'preview', message: `Component error: ${error.message}` }); } catch (storeError) { logger.error('Failed to add error to store', { error: storeError.message }); } } resetError = () => { this.setState({ hasError: false, error: null }); }; render() { if (this.state.hasError && this.state.error) { if (this.props.fallback) { const FallbackComponent = this.props.fallback; return ; } return ; } return this.props.children; } } interface DefaultErrorFallbackProps { error: Error; resetError: () => void; } const DefaultErrorFallback: React.FC = ({ error, resetError }) => (
Something went wrong The Block Tester encountered an error: {error.message}
{process.env.NODE_ENV === 'development' && (
Error Details (Development)
            {error.stack}
          
)}
); export default BlockTesterErrorBoundary;