From f1e0be8c7943c8bfe16685b121408bc12635e9c3 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Mon, 14 Jul 2025 15:45:10 +0200 Subject: [PATCH] feat: Fine-tune trading UI with coin dropdown selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove simulation mode and quick USDC swap sections - Replace trading pairs with two dropdown fields (From → To) - Add coin selection for perpetuals with leverage - Enhanced UX with coin swap button and dynamic labels - Always use real Jupiter DEX execution - 7 supported coins: SOL, USDC, USDT, BTC, ETH, RAY, ORCA - Intuitive From/To dropdowns for spot trading - Dedicated perpetual coin selection - Real-time label updates based on selection - Removed confusing simulation/real toggle - Streamlined execution always via Jupiter DEX - Cleaner UI focused on real trading - Better risk warnings for actual trades Tested: - Real SOL→USDC swap: TX 59QpmZWFnuHFNCVKujaq9tyJThy3fFTHpPSrug2vPQHYnE1Mk33wfwgHbc3oaW8E6m7kH8K7xpExESdV73LSqLT9 - Perpetual position: SOL 5x leverage simulation ready - All APIs working correctly in Docker Compose v2 --- components/TradeExecutionPanel.js | 343 +++++++++++------------------- 1 file changed, 125 insertions(+), 218 deletions(-) diff --git a/components/TradeExecutionPanel.js b/components/TradeExecutionPanel.js index 25a1867..0978f40 100644 --- a/components/TradeExecutionPanel.js +++ b/components/TradeExecutionPanel.js @@ -10,24 +10,32 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) { const [executionResult, setExecutionResult] = useState(null) const [balance, setBalance] = useState(null) - // Trading mode and pair selection + // Trading mode and coin selection const [tradingMode, setTradingMode] = useState('SPOT') // 'SPOT' or 'PERP' - const [tradingPair, setTradingPair] = useState('SOL/USDC') // SOL/USDC or USDC/SOL + const [fromCoin, setFromCoin] = useState('SOL') + const [toCoin, setToCoin] = useState('USDC') + const [perpCoin, setPerpCoin] = useState('SOL') // For perpetuals // TP/SL functionality const [enableStopLoss, setEnableStopLoss] = useState(false) const [stopLoss, setStopLoss] = useState('') const [enableTakeProfit, setEnableTakeProfit] = useState(false) const [takeProfit, setTakeProfit] = useState('') - const [useRealDEX, setUseRealDEX] = useState(false) // Perp trading settings const [leverage, setLeverage] = useState(1) const [perpSize, setPerpSize] = useState('') - // USDC stablecoin features - const [quickSwapMode, setQuickSwapMode] = useState(false) - const [usdcSwapAmount, setUsdcSwapAmount] = useState('') + // Available coins for trading + const availableCoins = [ + { symbol: 'SOL', name: 'Solana', icon: '🟣' }, + { symbol: 'USDC', name: 'USD Coin', icon: '💵' }, + { symbol: 'USDT', name: 'Tether', icon: '💶' }, + { symbol: 'BTC', name: 'Bitcoin', icon: '₿' }, + { symbol: 'ETH', name: 'Ethereum', icon: '🔷' }, + { symbol: 'RAY', name: 'Raydium', icon: '⚡' }, + { symbol: 'ORCA', name: 'Orca', icon: '🐋' } + ] // Auto-fill TP/SL from AI analysis useEffect(() => { @@ -76,62 +84,6 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) { } } - const executeQuickUSDCSwap = async () => { - if (!usdcSwapAmount || parseFloat(usdcSwapAmount) <= 0) { - alert('Please enter a valid USDC swap amount') - return - } - - setIsExecuting(true) - setExecutionResult(null) - - try { - const swapData = { - symbol: 'SOL', - side: 'SELL', // Sell SOL for USDC - amount: parseFloat(usdcSwapAmount), - tradingPair: 'SOL/USDC', - tradingMode: 'SPOT', - useRealDEX: true, - quickSwap: true - } - - const response = await fetch('/api/trading/execute-dex', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(swapData) - }) - - const result = await response.json() - - if (result.success) { - setExecutionResult({ - success: true, - trade: result.trade, - message: `✅ Quick swapped ${usdcSwapAmount} SOL to USDC` - }) - await fetchBalance() - setUsdcSwapAmount('') - } else { - setExecutionResult({ - success: false, - error: result.error, - message: result.message - }) - } - } catch (error) { - setExecutionResult({ - success: false, - error: 'Network error', - message: 'Failed to execute USDC swap. Please try again.' - }) - } finally { - setIsExecuting(false) - } - } - const executeTrade = async () => { if (!amount || parseFloat(amount) <= 0) { alert('Please enter a valid amount') @@ -148,14 +100,16 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) { // Prepare trade data based on trading mode let tradeData = { - symbol, + symbol: tradingMode === 'PERP' ? perpCoin : fromCoin, side: tradeType, amount: parseFloat(amount), price: tradePrice, orderType: tradePrice ? 'limit' : 'market', - useRealDEX: useRealDEX, + useRealDEX: true, // Always use real DEX tradingMode: tradingMode, - tradingPair: tradingPair + tradingPair: tradingMode === 'PERP' ? `${perpCoin}-PERP` : `${fromCoin}/${toCoin}`, + fromCoin: fromCoin, + toCoin: toCoin } // Add TP/SL if enabled @@ -170,15 +124,14 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) { if (tradingMode === 'PERP') { tradeData.leverage = leverage tradeData.perpSize = perpSize ? parseFloat(perpSize) : parseFloat(amount) + tradeData.perpCoin = perpCoin } // Determine API endpoint based on trading mode - let apiEndpoint = '/api/trading/execute' + let apiEndpoint = '/api/trading/execute-dex' if (tradingMode === 'PERP') { apiEndpoint = '/api/trading/execute-perp' - } else if (useRealDEX || quickSwapMode) { - apiEndpoint = '/api/trading/execute-dex' } const response = await fetch(apiEndpoint, { @@ -319,59 +272,107 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) { - {/* Trading Pair Selection (for Spot) */} + {/* Coin Selection for Spot Trading */} {tradingMode === 'SPOT' && (
- -
- - + +
+ {/* From Coin */} +
+ + +
+ + {/* Swap Arrow */} +
+ +
+ + {/* To Coin */} +
+ + +
-
- {tradingPair === 'SOL/USDC' ? 'Swap SOL for USDC stablecoin' : 'Buy SOL with USDC'} +
+ Swap {fromCoin} → {toCoin} via Jupiter DEX
)} - {/* Leverage Selection (for Perps) */} + {/* Coin Selection and Leverage for Perpetuals */} {tradingMode === 'PERP' && ( -
- -
- {[1, 2, 5, 10].map(lev => ( - - ))} +
+ {/* Perpetual Coin Selection */} +
+ + +
+ Choose the asset you want to trade with leverage +
-
- ⚠️ Higher leverage = Higher risk. Max 10x for safety. + + {/* Leverage Selection */} +
+ +
+ {[1, 2, 5, 10].map(lev => ( + + ))} +
+
+ ⚠️ Higher leverage = Higher risk. Max 10x for safety. +
)} @@ -403,7 +404,10 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) { {/* Amount Input */}
+
+ {tradingMode === 'PERP' + ? `Enter the ${perpCoin} position size to trade with ${leverage}x leverage` + : `Enter the amount of ${fromCoin} to swap for ${toCoin}` + } +
{/* Price Selection */} @@ -522,116 +532,13 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
- {/* DEX Selection */} -
-

Execution Method

- -
- - -
- -
- {useRealDEX - ? '⚠️ Real DEX trading uses your actual SOL/USDC and costs gas fees' - : '🎮 Simulation mode for testing strategies without real trades' - } -
-
- - {/* Quick USDC Swap - Spot mode only */} - {tradingMode === 'SPOT' && ( -
-

- 💱 Quick USDC Swap - STABLE -

- -
- Instantly convert SOL to USDC stablecoin to lock in profits or avoid volatility -
- -
- setUsdcSwapAmount(e.target.value)} - placeholder="SOL amount" - step="0.01" - min="0" - className="flex-1 px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500" - /> - -
- -
- Real-time swap via Jupiter DEX • Low slippage • Instant execution -
-
- )} - - {/* Jupiter Perpetuals Integration - Perp mode only */} - {tradingMode === 'PERP' && ( -
-

- ⚡ Jupiter Perpetuals - LEVERAGE -

- -
- Trade with leverage on Jupiter's perpetual DEX • Long or Short any asset -
- -
-
-
Leverage:
-
{leverage}x
-
-
-
Liquidation Risk:
-
- {leverage <= 2 ? 'Low' : leverage <= 5 ? 'Medium' : 'High'} -
-
-
- -
- 🚧 Jupiter Perpetuals integration in development. Currently using simulation mode. -
-
- )} - {/* Execute Button */} {/* Execution Result */} @@ -655,7 +562,7 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) { {/* Risk Warning */}
- ⚠️ Trading involves significant risk. This is a simulated trading environment using Bitquery data. + ⚠️ Trading involves significant risk of loss. Real trades executed via Jupiter DEX using your actual wallet funds.
)