← back to Govarbitrage

apps/mobile/lib/pnl.ts

14 lines

/**
 * Shared profit/loss color helper — used by any screen that tints a financial
 * value green/red by its sign. Respects the same finite guard as the formatters
 * in lib/format.ts: a missing or non-finite value is NEUTRAL, never a misleading
 * red (a null value would otherwise imply a loss) or green. Color each field by
 * its OWN value — do not drive one metric's color from another's sign.
 */
import { Colors } from "../constants/theme";

export function pnlColor(value: number | null | undefined): string {
  if (value == null || !Number.isFinite(value)) return Colors.neutral;
  return value >= 0 ? Colors.profit : Colors.loss;
}