Fix ScreenshotGallery and improve trade execution feedback

- Add keyboard ESC listener for closing enlarged screenshots
- Fix screenshot URL formatting to use /screenshots/[filename] route
- Improve trade execution error handling with detailed messages
- Show specific feedback for insufficient funds, auth issues, etc.
- Remove unused Modal import that was causing build errors
- Add click-outside-to-close functionality for enlarged images
This commit is contained in:
mindesbunister
2025-07-14 00:50:39 +02:00
parent aa8ca9846b
commit 045d4a41e3
2 changed files with 71 additions and 17 deletions

View File

@@ -1,6 +1,5 @@
"use client"
import React, { useState } from 'react'
import Modal from './Modal'
import TradeModal from './TradeModal'
import ScreenshotGallery from './ScreenshotGallery'
@@ -420,27 +419,50 @@ export default function AIAnalysisPanel() {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
symbol: tradeData.symbol,
side: 'buy', // Could be derived from analysis
size: parseFloat(tradeData.size),
side: 'BUY', // Could be derived from analysis
amount: parseFloat(tradeData.size), // Changed from 'size' to 'amount'
price: parseFloat(tradeData.entry),
stopLoss: parseFloat(tradeData.sl),
takeProfit: parseFloat(tradeData.tp),
leverage: parseInt(tradeData.leverage),
timeframe: tradeData.timeframe
timeframe: tradeData.timeframe,
orderType: 'MARKET' // Default to market order
})
})
const result = await response.json()
if (response.ok) {
// Show success message
alert(`Trade executed successfully! Order ID: ${result.orderId || 'N/A'}`)
if (response.ok && result.success) {
// Show detailed success message
let message = `Trade executed successfully!\n\n`
message += `📊 Order ID: ${result.txId}\n`
message += `💰 Symbol: ${tradeData.symbol}\n`
message += `📈 Size: ${tradeData.size}\n`
message += `💵 Entry: $${tradeData.entry}\n`
if (tradeData.sl) message += `🛑 Stop Loss: $${tradeData.sl}\n`
if (tradeData.tp) message += `🎯 Take Profit: $${tradeData.tp}\n`
if (result.conditionalOrders && result.conditionalOrders.length > 0) {
message += `\n🔄 Conditional orders: ${result.conditionalOrders.length} placed`
}
alert(message)
} else {
alert(`Trade failed: ${result.error || 'Unknown error'}`)
// Show detailed error message
const errorMsg = result.error || 'Unknown error occurred'
if (errorMsg.includes('insufficient funds') || errorMsg.includes('balance')) {
alert(`❌ Trade Failed: Insufficient Balance\n\nPlease deposit funds to your Drift account before placing trades.\n\nError: ${errorMsg}`)
} else if (errorMsg.includes('not logged in') || errorMsg.includes('Cannot execute trade')) {
alert(`❌ Trade Failed: Authentication Issue\n\nPlease check your Drift connection in the settings.\n\nError: ${errorMsg}`)
} else {
alert(`❌ Trade Failed\n\nError: ${errorMsg}`)
}
}
} catch (error) {
console.error('Trade execution failed:', error)
alert('Trade execution failed. Please check your connection.')
alert('Trade execution failed due to network error.\n\nPlease check your connection and try again.')
}
setTradeModalOpen(false)