Odds Selector Adapter (Mr. Doge SDK)
mrdoge-ui/mrdoge-odds-selector-adapterFreeUtility
Pairs Over/Under markets into OddsLine[] and picks a representative line, for Odds Selector's lines prop.
Install it
npx shadcn@latest add https://mrdoge.co/r/mrdoge-odds-selector-adapter.jsonSource
1import type { Market } from "@mrdoge/protocol"2import type { OddsLine } from "@/registry/mrdoge-ui/odds-selector/odds-selector"34// Over/Under outcomes only carry a generic "O"/"U" code, no threshold in5// it. The threshold lives in the caption instead ("Over 1.5", "Under6// 1.5"), so that's what has to be parsed to sort lines and label them.7function parseThreshold(caption: string | null | undefined): number {8 const match = caption?.match(/[\d.]+/)9 return match ? parseFloat(match[0]) : NaN10}1112/**13 * Some bet types post one market per line instead of one market total.14 * SOCCER_UNDER_OVER posts a separate market for each Over/Under threshold15 * (0.5, 1.5, 2.5, ...). Pairs each market's two outcomes into one OddsLine16 * row and sorts by threshold, for OddsSelector's `lines` prop.17 */18export function toOddsLines(markets: Market[]): OddsLine[] {19 const lines: (OddsLine & { threshold: number })[] = []20 for (const market of markets) {21 const over = market.lines.find((line) => line.code.startsWith("O"))22 const under = market.lines.find((line) => line.code.startsWith("U"))23 if (!over || !under) continue24 const threshold = parseThreshold(over.caption ?? under.caption)25 // Can't sort or label a line without a real threshold. Drop it26 // rather than showing a broken "NaN" row.27 if (Number.isNaN(threshold)) continue28 lines.push({29 id: market.id,30 threshold,31 label: String(threshold),32 over: {33 id: over.id,34 label: over.caption ?? over.code,35 price: over.price.toFixed(2),36 suspended: !over.isAvailable,37 },38 under: {39 id: under.id,40 label: under.caption ?? under.code,41 price: under.price.toFixed(2),42 suspended: !under.isAvailable,43 },44 })45 }46 return lines.sort((a, b) => a.threshold - b.threshold)47}4849/**50 * Picks the line closest to an even split: the Over/Under prices closest51 * to each other, e.g. Over 1.90 / Under 2.00 rather than a lopsided Over52 * 1.18 / Under 4.50. A reasonable single-market pick when there's only53 * room to show one Total Goals line, e.g. alongside other markets on a54 * board. The first market in the snapshot is otherwise arbitrary.55 */56export function pickMostBalancedMarket(markets: Market[]): Market | undefined {57 let best: Market | undefined58 let bestSpread = Infinity59 for (const market of markets) {60 const over = market.lines.find((line) => line.code.startsWith("O"))61// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from mrdoge-ui
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Bet Slip Adapter (Mr. Doge SDK)mrdoge-bet-slip-adapter | mrdoge-ui | Utilities | Free | 1 dep | |
| Mr. Doge Clientmrdoge-client | mrdoge-ui | Utilities | Free | 1 dep | |
| Conflict Adapter (Mr. Doge SDK)mrdoge-conflict-adapter | mrdoge-ui | Utilities | Free | 1 dep | |
| Match Card Adapter (Mr. Doge SDK)mrdoge-match-card-adapter | mrdoge-ui | Utilities | Free | 1 dep | |
| Match Highlight Adapter (Mr. Doge SDK)mrdoge-match-highlight-adapter | mrdoge-ui | Utilities | Free | 1 dep | |
| Match Timeline Adapter (Mr. Doge SDK)mrdoge-match-timeline-adapter | mrdoge-ui | Utilities | Free | 1 dep | |
| Stats List Adapter (Mr. Doge SDK)mrdoge-stats-list-adapter | mrdoge-ui | Utilities | Free | 1 dep | |
| Rate Limitrate-limit | mrdoge-ui | Utilities | Free | no deps |
