fix: add null checks to prevent 'Cannot read properties of null' error on automation page

- Added proper null checks for status object before accessing selectedTimeframes
- Fixed timeframes display to handle null status gracefully
- Fixed analysis interval calculation with optional chaining
- Resolved 500 internal server error on /automation-v2 page
This commit is contained in:
mindesbunister
2025-07-24 15:04:25 +02:00
parent e1d8c0c65a
commit 1505bc04cd
6 changed files with 2381 additions and 249 deletions

View File

@@ -364,7 +364,7 @@ export default function AutomationPageV2() {
<div className="p-2 bg-gray-800/30 rounded-lg mb-3">
<div className="text-xs text-gray-400">
Selected: <span className="text-cyan-400">
{(status.selectedTimeframes || [status.timeframe]).map(tf => timeframes.find(t => t.value === tf)?.label || tf).filter(Boolean).join(', ')}
{config.selectedTimeframes.map(tf => timeframes.find(t => t.value === tf)?.label || tf).filter(Boolean).join(', ')}
</span>
</div>
<div className="text-xs text-gray-500 mt-1">
@@ -499,7 +499,12 @@ export default function AutomationPageV2() {
<div className="flex justify-between">
<span className="text-gray-300">Timeframes:</span>
<span className="text-cyan-400 font-semibold text-xs">
{(status.selectedTimeframes || [status.timeframe]).map(tf => timeframes.find(t => t.value === tf)?.label || tf).filter(Boolean).join(', ')}
{status && status.selectedTimeframes ?
status.selectedTimeframes.map(tf => timeframes.find(t => t.value === tf)?.label || tf).filter(Boolean).join(', ') :
status && status.timeframe ?
(timeframes.find(t => t.value === status.timeframe)?.label || status.timeframe) :
'N/A'
}
</span>
</div>
</div>
@@ -620,7 +625,7 @@ export default function AutomationPageV2() {
<div
className="bg-blue-500 h-2 rounded-full transition-all duration-1000"
style={{
width: status.analysisInterval > 0 ?
width: status?.analysisInterval > 0 ?
`${Math.max(0, 100 - (nextAnalysisCountdown / status.analysisInterval) * 100)}%` :
'0%'
}}
@@ -628,11 +633,11 @@ export default function AutomationPageV2() {
</div>
<div className="text-xs text-gray-400 text-center">
Analysis Interval: {(() => {
const intervalSec = status.analysisInterval || 0
const intervalSec = status?.analysisInterval || 0
const intervalMin = Math.floor(intervalSec / 60)
// Determine strategy type for display
if (status.selectedTimeframes) {
if (status?.selectedTimeframes) {
const timeframes = status.selectedTimeframes
const isScalping = timeframes.includes('5') || timeframes.includes('3') ||
(timeframes.length > 1 && timeframes.every(tf => ['1', '3', '5', '15', '30'].includes(tf)))