From c263497ec8b05bc0f9254ed2f7ecb4dba6f67d4e Mon Sep 17 00:00:00 2001 From: Kostya Date: Thu, 15 Oct 2026 19:35:48 +0300 Subject: ui-web: add browser client for the Ex4 bonus A React + TypeScript single-page client served by Vite, working against the same servlets as the desktop client: login, the events screen with filters, details, order books and trading, and the account screen with deposit, holdings, ledger rows and the user directory. No file upload, as the exercise specifies. It looks like the desktop client on purpose: the three skins of theme.css as CSS variables, the four animations redone with SVG and keyframes, and the desktop's Nerd Fonts, which npm run dev copies from ui-fx instead of keeping a second copy in the repo. The shared chat sits in a drawer above the status bar, as on the desktop, on its own poll because chat lines don't move the market version. Vite forwards /guess-market to Tomcat on 8080, so the page and the API share an origin and the session cookie needs no CORS. The client polls /api/sync once a second and reloads only when the version moved. run-web.bat installs the packages and starts it on localhost:5173. package.sh stages the sources under build/dist/ex4, without node_modules. --- ui-web/src/Events.tsx | 370 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 370 insertions(+) create mode 100644 ui-web/src/Events.tsx (limited to 'ui-web/src/Events.tsx') diff --git a/ui-web/src/Events.tsx b/ui-web/src/Events.tsx new file mode 100644 index 0000000..e33b4e2 --- /dev/null +++ b/ui-web/src/Events.tsx @@ -0,0 +1,370 @@ +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
} +
+ ); +} -- cgit v1.2.3