@@ -34,7 +34,7 @@ export default function MonthDetailsScreen() {
3434
3535 // Use trade P&L when trades exist
3636 const hasTrades = monthTrades . length > 0 ;
37- const tradePnL = hasTrades ? monthTrades . reduce ( ( sum , t ) => sum + t . pnl , 0 ) : 0 ;
37+ const tradePnL = hasTrades ? monthTrades . reduce ( ( sum , t ) => sum + ( t . pnl ?? 0 ) , 0 ) : 0 ;
3838 const effectivePnL = hasTrades ? tradePnL : ( month ?. netProfitLoss ?? 0 ) ;
3939 const effectiveReturn = hasTrades && month && month . startingCapital > 0
4040 ? ( tradePnL / month . startingCapital ) * 100
@@ -78,7 +78,7 @@ export default function MonthDetailsScreen() {
7878 const with_ = parseCurrency ( withdrawals ) ;
7979
8080 if ( start > 0 && end >= 0 ) {
81- return calculateMonthMetrics ( start , end , dep , with_ ) ;
81+ return calculateMonthMetrics ( start , end , with_ , dep ) ;
8282 }
8383 return null ;
8484 } , [ startingCapital , endingCapital , deposits , withdrawals ] ) ;
@@ -138,7 +138,7 @@ export default function MonthDetailsScreen() {
138138 return ;
139139 }
140140
141- const validation = validateMonthForm ( start , end , dep , with_ , month . month ) ;
141+ const validation = validateMonthForm ( start , end , with_ , dep , month . month ) ;
142142 if ( ! validation . isValid ) {
143143 Alert . alert ( 'Validation Error' , validation . error ) ;
144144 return ;
@@ -147,12 +147,12 @@ export default function MonthDetailsScreen() {
147147 setIsSubmitting ( true ) ;
148148
149149 try {
150- const metrics = calculateMonthMetrics ( start , end , dep , with_ ) ;
150+ const metrics = calculateMonthMetrics ( start , end , with_ , dep ) ;
151151 await updateMonth ( month . id , {
152152 startingCapital : start ,
153153 endingCapital : end ,
154- deposits : dep ,
155- withdrawals : with_ ,
154+ deposits : with_ ,
155+ withdrawals : dep ,
156156 notes,
157157 ...metrics ,
158158 } ) ;
@@ -453,29 +453,29 @@ export default function MonthDetailsScreen() {
453453 width : 32 ,
454454 height : 32 ,
455455 borderRadius : 8 ,
456- backgroundColor : trade . pnl >= 0 ? 'rgba(16, 185, 95, 0.1)' : 'rgba(239, 68, 68, 0.1)' ,
456+ backgroundColor : ( trade . pnl ?? 0 ) >= 0 ? 'rgba(16, 185, 95, 0.1)' : 'rgba(239, 68, 68, 0.1)' ,
457457 justifyContent : 'center' ,
458458 alignItems : 'center' ,
459459 } } >
460460 < Ionicons
461- name = { trade . pnl >= 0 ? 'trending-up' : 'trending-down' }
461+ name = { ( trade . pnl ?? 0 ) >= 0 ? 'trending-up' : 'trending-down' }
462462 size = { 16 }
463- color = { trade . pnl >= 0 ? colors . profit : colors . loss }
463+ color = { ( trade . pnl ?? 0 ) >= 0 ? colors . profit : colors . loss }
464464 />
465465 </ View >
466466 < View >
467467 < Text style = { { fontFamily : fonts . semiBold , fontSize : 14 , color : colors . text } } > { trade . symbol } </ Text >
468468 < Text style = { { fontFamily : fonts . regular , fontSize : 12 , color : colors . textMuted } } >
469- { new Date ( trade . exitDate ) . toLocaleDateString ( 'en-US' , { month : 'short' , day : 'numeric' } ) }
469+ { trade . exitDate ? new Date ( trade . exitDate ) . toLocaleDateString ( 'en-US' , { month : 'short' , day : 'numeric' } ) : 'Open' }
470470 </ Text >
471471 </ View >
472472 </ View >
473473 < View style = { { alignItems : 'flex-end' } } >
474- < Text style = { { fontFamily : fonts . bold , fontSize : 14 , color : trade . pnl >= 0 ? colors . profit : colors . loss } } >
475- { trade . pnl >= 0 ? '+' : '' } ${ Math . abs ( trade . pnl ) . toFixed ( 2 ) }
474+ < Text style = { { fontFamily : fonts . bold , fontSize : 14 , color : ( trade . pnl ?? 0 ) >= 0 ? colors . profit : colors . loss } } >
475+ { ( trade . pnl ?? 0 ) >= 0 ? '+' : '' } ${ Math . abs ( trade . pnl ?? 0 ) . toFixed ( 2 ) }
476476 </ Text >
477477 < Text style = { { fontFamily : fonts . regular , fontSize : 12 , color : colors . textMuted } } >
478- { trade . returnPercentage >= 0 ? '+' : '' } { trade . returnPercentage . toFixed ( 1 ) } %
478+ { ( trade . returnPercentage ?? 0 ) >= 0 ? '+' : '' } { ( trade . returnPercentage ?? 0 ) . toFixed ( 1 ) } %
479479 </ Text >
480480 </ View >
481481 </ TouchableOpacity >
0 commit comments