fix(portfolio): satisfy manual position null-safety
This commit is contained in:
parent
0f74d7b292
commit
0db2693a20
@ -1296,19 +1296,22 @@ export const PositionsTab = ({ botState }: PositionsTabProps) => {
|
|||||||
const hasCurrentPrice = hasFiniteNumber(pos.currentPrice);
|
const hasCurrentPrice = hasFiniteNumber(pos.currentPrice);
|
||||||
const hasPnl = hasFiniteNumber(pos.pnl);
|
const hasPnl = hasFiniteNumber(pos.pnl);
|
||||||
const hasPnlPercent = hasFiniteNumber(pos.pnlPercent);
|
const hasPnlPercent = hasFiniteNumber(pos.pnlPercent);
|
||||||
|
const currentPrice: number | null = hasCurrentPrice ? Number(pos.currentPrice) : null;
|
||||||
|
const pnl: number | null = hasPnl ? Number(pos.pnl) : null;
|
||||||
|
const pnlPercent: number | null = hasPnlPercent ? Number(pos.pnlPercent) : null;
|
||||||
const displayStopLoss = (pos.stopLoss && pos.stopLoss > 0)
|
const displayStopLoss = (pos.stopLoss && pos.stopLoss > 0)
|
||||||
? pos.stopLoss
|
? pos.stopLoss
|
||||||
: (entryRisk?.stopLoss || 0);
|
: (entryRisk?.stopLoss || 0);
|
||||||
const displayTakeProfit = (pos.takeProfit && pos.takeProfit > 0)
|
const displayTakeProfit = (pos.takeProfit && pos.takeProfit > 0)
|
||||||
? pos.takeProfit
|
? pos.takeProfit
|
||||||
: (entryRisk?.takeProfit || 0);
|
: (entryRisk?.takeProfit || 0);
|
||||||
const slBreached = hasCurrentPrice && displayStopLoss > 0 && (
|
const slBreached = currentPrice !== null && displayStopLoss > 0 && (
|
||||||
(pos.side === 'BUY' && pos.currentPrice <= displayStopLoss)
|
(pos.side === 'BUY' && currentPrice <= displayStopLoss)
|
||||||
|| (pos.side === 'SELL' && pos.currentPrice >= displayStopLoss)
|
|| (pos.side === 'SELL' && currentPrice >= displayStopLoss)
|
||||||
);
|
);
|
||||||
const tpHit = hasCurrentPrice && displayTakeProfit > 0 && (
|
const tpHit = currentPrice !== null && displayTakeProfit > 0 && (
|
||||||
(pos.side === 'BUY' && pos.currentPrice >= displayTakeProfit)
|
(pos.side === 'BUY' && currentPrice >= displayTakeProfit)
|
||||||
|| (pos.side === 'SELL' && pos.currentPrice <= displayTakeProfit)
|
|| (pos.side === 'SELL' && currentPrice <= displayTakeProfit)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -1342,7 +1345,7 @@ export const PositionsTab = ({ botState }: PositionsTabProps) => {
|
|||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 text-xs font-mono text-gray-400">${pos.entryPrice.toLocaleString()}</td>
|
<td className="px-6 py-4 text-xs font-mono text-gray-400">${pos.entryPrice.toLocaleString()}</td>
|
||||||
<td className="px-6 py-4 text-xs font-mono text-white font-bold">
|
<td className="px-6 py-4 text-xs font-mono text-white font-bold">
|
||||||
{hasCurrentPrice ? `$${pos.currentPrice.toLocaleString()}` : '-'}
|
{currentPrice !== null ? `$${currentPrice.toLocaleString()}` : '-'}
|
||||||
<div className="mt-1 flex flex-wrap gap-1">
|
<div className="mt-1 flex flex-wrap gap-1">
|
||||||
{slBreached && (
|
{slBreached && (
|
||||||
<span className="px-1.5 py-0.5 rounded text-[9px] font-black uppercase tracking-wider bg-red-500/20 text-red-300 border border-red-500/20">
|
<span className="px-1.5 py-0.5 rounded text-[9px] font-black uppercase tracking-wider bg-red-500/20 text-red-300 border border-red-500/20">
|
||||||
@ -1363,10 +1366,10 @@ export const PositionsTab = ({ botState }: PositionsTabProps) => {
|
|||||||
{displayTakeProfit ? `$${displayTakeProfit.toLocaleString()}` : '-'}
|
{displayTakeProfit ? `$${displayTakeProfit.toLocaleString()}` : '-'}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 text-right">
|
<td className="px-6 py-4 text-right">
|
||||||
{hasPnl && hasPnlPercent ? (
|
{pnl !== null && pnlPercent !== null ? (
|
||||||
<div className={`text-xs font-mono font-black ${pos.pnl >= 0 ? 'text-green-400' : 'text-red-400'}`}>
|
<div className={`text-xs font-mono font-black ${pnl >= 0 ? 'text-green-400' : 'text-red-400'}`}>
|
||||||
{pos.pnl >= 0 ? '+' : ''}{pos.pnlPercent.toFixed(2)}%
|
{pnl >= 0 ? '+' : ''}{pnlPercent.toFixed(2)}%
|
||||||
<div className="text-[10px] opacity-60">${pos.pnl.toFixed(2)}</div>
|
<div className="text-[10px] opacity-60">${pnl.toFixed(2)}</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-xs font-mono text-gray-500">-</div>
|
<div className="text-xs font-mono text-gray-500">-</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user