🚀 Fix position sizing and add real wallet balance integration
Fixed Position Size Calculation: - Changed input from SOL to USD for clarity - Fixed calculation: positionSizeSOL = positionValueUSD / coinPrice - Resolved issue where entering 0.4 SOL showed incorrect 0.0025 underneath Added Real Wallet Balance Integration: - TradeModal now fetches actual wallet balance from /api/wallet/balance - Percentage buttons now calculate from real available balance (3.40) - No more impossible 1 SOL positions when only 3.40 available Enhanced Position Sizing UI: - Added slider for smooth position adjustment ( to full balance) - Percentage buttons (25%, 50%, 75%, 100%) now accurate - Real-time display shows both USD and SOL amounts - Live percentage display of balance usage Added Wallet Overview to Dashboard: - Main dashboard shows real wallet balance prominently - Trading page displays actual wallet holdings - StatusOverview component enhanced with wallet info - Accurate position sizing based on actual 3.40 balance - Intuitive slider + percentage buttons - Real-time balance updates every 30 seconds - Clear USD/SOL conversion display - No more calculation errors in trading modal
This commit is contained in:
@@ -8,7 +8,9 @@ export default function StatusOverview() {
|
||||
dailyPnL: 0,
|
||||
systemStatus: 'offline',
|
||||
bitqueryStatus: 'unknown',
|
||||
marketPrices: []
|
||||
marketPrices: [],
|
||||
walletBalance: null, // Real wallet balance
|
||||
availableCoins: [] // Available coins in wallet
|
||||
})
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
@@ -17,8 +19,25 @@ export default function StatusOverview() {
|
||||
try {
|
||||
setLoading(true)
|
||||
|
||||
// Get real wallet balance
|
||||
let walletBalance = null
|
||||
let availableCoins = []
|
||||
|
||||
try {
|
||||
const walletRes = await fetch('/api/wallet/balance')
|
||||
if (walletRes.ok) {
|
||||
const walletData = await walletRes.json()
|
||||
if (walletData.success) {
|
||||
walletBalance = walletData.balance
|
||||
availableCoins = walletData.balance.positions || []
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Could not fetch wallet balance:', e)
|
||||
}
|
||||
|
||||
// Get market data from Bitquery
|
||||
let balance = 0
|
||||
let balance = walletBalance?.totalValue || 0 // Use real wallet balance
|
||||
let bitqueryStatus = 'error'
|
||||
let marketPrices = []
|
||||
|
||||
@@ -29,15 +48,6 @@ export default function StatusOverview() {
|
||||
if (marketData.success) {
|
||||
marketPrices = marketData.data.prices || []
|
||||
bitqueryStatus = marketData.data.status?.connected ? 'online' : 'error'
|
||||
|
||||
// Calculate portfolio value from Bitquery
|
||||
const portfolioRes = await fetch('/api/trading/balance')
|
||||
if (portfolioRes.ok) {
|
||||
const portfolioData = await portfolioRes.json()
|
||||
if (portfolioData.success) {
|
||||
balance = portfolioData.balance.totalValue || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -61,7 +71,9 @@ export default function StatusOverview() {
|
||||
dailyPnL: 0, // No fake P&L
|
||||
systemStatus: systemStatus,
|
||||
bitqueryStatus: bitqueryStatus,
|
||||
marketPrices: marketPrices
|
||||
marketPrices: marketPrices,
|
||||
walletBalance: walletBalance,
|
||||
availableCoins: availableCoins
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching status:', error)
|
||||
@@ -119,6 +131,19 @@ export default function StatusOverview() {
|
||||
<p className="text-gray-400 text-sm">Portfolio Value</p>
|
||||
</div>
|
||||
|
||||
{/* Wallet Balance */}
|
||||
{status.walletBalance && (
|
||||
<div className="text-center">
|
||||
<div className="w-16 h-16 bg-emerald-500/20 rounded-full flex items-center justify-center mx-auto mb-3">
|
||||
<span className="text-emerald-400 text-2xl">🪙</span>
|
||||
</div>
|
||||
<p className="text-2xl font-bold text-emerald-400">
|
||||
{status.walletBalance.positions?.[0]?.amount?.toFixed(4) || '0.0000'} SOL
|
||||
</p>
|
||||
<p className="text-gray-400 text-sm">Wallet Balance</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-center">
|
||||
<div className="w-16 h-16 bg-purple-500/20 rounded-full flex items-center justify-center mx-auto mb-3">
|
||||
<span className="text-purple-400 text-2xl">🔄</span>
|
||||
@@ -194,6 +219,35 @@ export default function StatusOverview() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Available Coins in Wallet */}
|
||||
{status.availableCoins.length > 0 && (
|
||||
<div className="border-t border-gray-700 pt-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-semibold text-white">Available Wallet Coins</h3>
|
||||
<span className="text-xs text-gray-400">Ready for Trading</span>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-3">
|
||||
{status.availableCoins.map((coin, index) => (
|
||||
<div key={index} className="p-3 bg-gray-800 rounded-lg">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-3">
|
||||
<span className="text-lg">🪙</span>
|
||||
<div>
|
||||
<span className="text-white font-medium">{coin.symbol}</span>
|
||||
<div className="text-xs text-gray-400">${coin.price?.toFixed(2)}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-white font-bold">{coin.amount?.toFixed(4)}</div>
|
||||
<div className="text-sm text-gray-400">${coin.usdValue?.toFixed(2)}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user