import { useState } from 'react'; import { api, EventDetail, eventPath, EventSummary, feeLabel, FeeTiming, MarketData, Mechanism, mechanismLabel, money, num, OrderBook, same, SEP, Status, } from './api'; import type { Act } from './App'; import { LineChart, priceSeries } from './Chart'; import { Equalizer } from './graphics'; const STATUS_PILL: Record = { DRAFT: ['', 'IDLE'], ACTIVE: ['active', 'ACTIVE'], SETTLED: ['closed', 'CLOSED'], }; function Filter(props: { label: string; value: T | null; options: [T, string][]; onChange: (value: T | null) => void; }) { return (
{props.label} {props.options.map(([value, text]) => ( ))}
); } export function Events(props: { data: MarketData; user: string; selected: EventSummary | undefined; onSelect: (key: string) => void; act: Act; onTrade: () => void; onResolve: () => void; }) { const { data, selected } = props; const [method, setMethod] = useState(null); const [status, setStatus] = useState(null); const [fee, setFee] = useState(null); const shown = data.events.filter( (e) => (method === null || e.mechanism === method) && (status === null || e.status === status) && (fee === null || e.commissionTiming === fee), ); const detail = selected && data.details[selected.key]; return ( <>
{shown.map((e) => ( ))}
{shown.length} of {data.events.length} events shown
{detail ? ( ) : (
)} ); } function EventView(props: { detail: EventDetail; user: string; act: Act; onTrade: () => void; onResolve: () => void }) { const { detail, user, act } = props; const e = detail.summary; const markets = detail.state.markets; const isMm = same(e.marketMaker, user); const live = e.status === 'ACTIVE' ? 'LIVE' : e.status === 'SETTLED' ? 'ENDED' : 'IDLE'; const yes = priceSeries(detail); return (

{e.displayId}. {e.name}

{e.description}

{/* Open = go trade on an active event, or the Market Maker starting their own */} {e.status === 'ACTIVE' && ( )} {e.status === 'DRAFT' && isMm && ( )} {e.status === 'ACTIVE' && isMm && ( )}
{live} Method {mechanismLabel(e.mechanism)} Status {e.status} Market Maker {e.marketMaker} Fee {feeLabel(e)} Contract {money(e.accountBalance)}
{e.status === 'SETTLED' && (
RESOLVED Winning option: {detail.settledMarket} {SEP} contract emptied to its holders
)} {e.mechanism === 'LMSR' ? ( <>
{markets.map((m, i) => (
{i === 0 ? 'YES' : 'NO'} {m.name} {money(m.price)}
{m.volume} shares {SEP} p = {num(m.price).toFixed(2)}
))}
Share price over time YES / NO {SEP} LMSR
[t, 1 - v]), tone: 'no' }, ]} />
) : ( <>
{detail.orderBooks.map((book, i) => ( ))}
Last trade price over time last trade YES
)}
Trade history newest first
# User Option Shares Paid
{detail.history.map((t, i) => (
#{detail.history.length - i} {t.userName} {t.optionName} {t.quantity} shares {money(t.pricePaid)}
))} {detail.history.length === 0 &&
No trades yet
}
Participants
User YES NO Value Fees paid
{detail.participants.map((p) => (
{p.user} {p.tag && ` (${p.tag})`} {p.yes} {p.no} {p.value} {p.fees}
))} {detail.participants.length === 0 &&
Nobody yet
}
); } function Book({ book, last, side }: { book: OrderBook; last: string | undefined; side: string }) { const mid = book.bestBid && book.bestAsk ? money((num(book.bestBid) + num(book.bestAsk)) / 2) : '—'; return (
{side} Order Book {book.optionName} {book.orders.length} orders
{[ ['Last', money(last)], ['Best bid', book.bestBid ?? '—'], ['Best ask', book.bestAsk ?? '—'], ['Mid', mid], ['Spread', book.spread ?? '—'], ].map(([label, value]) => ( {label} {value} ))}
Price Side Qty User
{book.orders.map((o, i) => (
{o.price} {o.side} {o.quantity} {o.user}
))} {book.orders.length === 0 &&
No resting orders
}
); }