Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(cli): keep price visible when outcomes are missing
- Preserve market list price display when outcomePrices is present but outcomes is absent\n- Fallback to unlabeled first outcome price instead of rendering an em dash\n- Add regression test for outcomes-missing case
  • Loading branch information
morluto committed Feb 24, 2026
commit 4ecd009e883ea7b009bab8c2ea0899ec30607ead
40 changes: 28 additions & 12 deletions src/output/markets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ fn market_status(m: &Market) -> &'static str {

fn market_to_row(m: &Market) -> MarketRow {
let question = m.question.as_deref().unwrap_or("—");
let price_yes = primary_outcome_price(m).map_or_else(
|| "—".into(),
|(outcome, price)| format!("{outcome}: {:.2}¢", price * Decimal::from(100)),
);
let price_yes =
primary_outcome_price(m).map_or_else(
|| "—".into(),
|(outcome, price)| match outcome {
Some(outcome) => format!("{outcome}: {:.2}¢", price * Decimal::from(100)),
None => format!("{:.2}¢", price * Decimal::from(100)),
},
);

MarketRow {
question: truncate(question, 60),
Expand All @@ -45,16 +49,19 @@ fn market_to_row(m: &Market) -> MarketRow {
}
}

fn primary_outcome_price(m: &Market) -> Option<(String, Decimal)> {
let outcomes = m.outcomes.as_ref()?;
fn primary_outcome_price(m: &Market) -> Option<(Option<String>, Decimal)> {
let prices = m.outcome_prices.as_ref()?;

outcomes
.iter()
.zip(prices.iter())
.find(|(outcome, _)| outcome.eq_ignore_ascii_case("yes"))
.or_else(|| outcomes.iter().zip(prices.iter()).next())
.map(|(outcome, price)| (outcome.clone(), *price))
if let Some(outcomes) = m.outcomes.as_ref() {
outcomes
.iter()
.zip(prices.iter())
.find(|(outcome, _)| outcome.eq_ignore_ascii_case("yes"))
.or_else(|| outcomes.iter().zip(prices.iter()).next())
.map(|(outcome, price)| (Some(outcome.clone()), *price))
} else {
prices.first().map(|price| (None, *price))
}
}

pub fn print_markets_table(markets: &[Market]) {
Expand Down Expand Up @@ -245,6 +252,15 @@ mod tests {
assert_eq!(market_to_row(&m).price_yes, "Long: 58.00¢");
}

#[test]
fn row_shows_unlabeled_price_when_outcomes_missing() {
let m = make_market(json!({
"id": "1",
"outcomePrices": "[\"0.65\",\"0.35\"]"
}));
assert_eq!(market_to_row(&m).price_yes, "65.00¢");
}

#[test]
fn row_truncates_long_question() {
let long_q = "a".repeat(100);
Expand Down