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:
@@ -20,7 +20,7 @@ export default function AutomationPageV2() {
|
||||
timeframe: '1h', // Primary timeframe for backwards compatibility
|
||||
selectedTimeframes: ['60'], // Multi-timeframe support
|
||||
tradingAmount: 100,
|
||||
maxLeverage: 5,
|
||||
maxLeverage: 20, // Maximum allowed leverage for AI calculations
|
||||
stopLossPercent: 2,
|
||||
takeProfitPercent: 6,
|
||||
riskPercentage: 2
|
||||
@@ -172,7 +172,7 @@ export default function AutomationPageV2() {
|
||||
<h3 className="text-xl font-bold text-white mb-6">Configuration</h3>
|
||||
|
||||
{/* Trading Mode */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-1 gap-6 mb-6">
|
||||
<div className="space-y-3">
|
||||
<label className="block text-sm font-bold text-blue-400">Trading Mode</label>
|
||||
<div className="space-y-2">
|
||||
@@ -199,23 +199,16 @@ export default function AutomationPageV2() {
|
||||
<span className="text-white font-semibold">Live Trading</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<label className="block text-sm font-bold text-purple-400">Leverage</label>
|
||||
<select
|
||||
className="w-full p-3 bg-gray-700 border border-gray-600 rounded-lg text-white focus:border-purple-400"
|
||||
value={config.maxLeverage}
|
||||
onChange={(e) => setConfig({...config, maxLeverage: parseInt(e.target.value)})}
|
||||
disabled={status?.isActive}
|
||||
>
|
||||
<option value="1">1x - Spot</option>
|
||||
<option value="2">2x</option>
|
||||
<option value="3">3x</option>
|
||||
<option value="5">5x</option>
|
||||
<option value="10">10x</option>
|
||||
<option value="20">20x</option>
|
||||
</select>
|
||||
<div className="mt-2 p-3 bg-blue-900/20 border border-blue-700 rounded-lg">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-blue-400">🧠</span>
|
||||
<span className="text-sm text-blue-300 font-medium">AI-Driven Leverage</span>
|
||||
</div>
|
||||
<p className="text-xs text-blue-200 mt-1">
|
||||
Leverage is now calculated automatically by AI based on account balance, market conditions, and risk assessment.
|
||||
The system optimizes between 1x-20x for maximum profit while maintaining liquidation safety.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -254,11 +247,9 @@ export default function AutomationPageV2() {
|
||||
Available: ${parseFloat(balance.availableBalance).toFixed(2)} • Using {((config.tradingAmount / balance.availableBalance) * 100).toFixed(1)}% of balance
|
||||
</p>
|
||||
)}
|
||||
{balance && config.maxLeverage > 1 && (
|
||||
<p className="text-xs text-green-400 mt-1">
|
||||
With {config.maxLeverage}x leverage: ${(config.tradingAmount * config.maxLeverage).toFixed(2)} position size
|
||||
</p>
|
||||
)}
|
||||
<p className="text-xs text-cyan-400 mt-1">
|
||||
💡 AI will apply optimal leverage automatically based on market conditions
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -484,8 +475,8 @@ export default function AutomationPageV2() {
|
||||
<span className="text-white font-semibold">{status.symbol}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Leverage:</span>
|
||||
<span className="text-yellow-400 font-semibold">{config.maxLeverage}x</span>
|
||||
<span className="text-gray-300">AI Leverage:</span>
|
||||
<span className="text-cyan-400 font-semibold">Auto-Calculated</span>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
@@ -505,9 +496,9 @@ export default function AutomationPageV2() {
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-blue-400">
|
||||
{balance ? parseFloat(balance.leverage || 0).toFixed(1) : '0.0'}%
|
||||
{balance && balance.actualLeverage ? parseFloat(balance.actualLeverage).toFixed(1) : 'AI'}x
|
||||
</div>
|
||||
<div className="text-xs text-gray-400">Leverage Used</div>
|
||||
<div className="text-xs text-gray-400">Current Leverage</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-red-400">
|
||||
|
||||
Reference in New Issue
Block a user