Prediction Market Trade Ticket

Buy or sell an outcome with a rolling amount and quick add chips.

Preview

"use client";

import { useState } from "react";
import {
  PredictionMarket,
  type PredictionMarketOrderValue,
} from "@/components/motion/prediction-market";

const outcomes = [
  {
    id: "yes",
    label: "Yes",
    price: 0.167,
  },
  {
    id: "no",
    label: "No",
    price: 0.834,
  },
];

export function PredictionMarketPreview() {
  const [order, setOrder] = useState<PredictionMarketOrderValue>({
    mode: "buy",
    outcomeId: "yes",
    amount: "115",
  });

  return (
    <div className="flex w-full items-center justify-center">
      <PredictionMarket
        outcomes={outcomes}
        value={order}
        onValueChange={setOrder}
        balance={500}
        positions={{ yes: 125, no: 48 }}
        quickAmounts={[1, 5, 10, 100]}
      />
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/prediction-market

API Reference

outcomes?
PredictionMarketOutcome[]

Outcomes to trade, each with a price from 0 to 1. Default: Up and Down

Default[ { id: "up", label: "Up", price: 0.09 }, { id: "down", label: "Down", price: 0.91 }, ]
value?
PredictionMarketOrderValue

The order's mode, outcome and amount, for controlled use.

Default—
defaultValue?
Partial<PredictionMarketOrderValue>

The initial order when uncontrolled. Missing fields start as buy, the first outcome and empty.

Default—
onValueChange?
((value: PredictionMarketOrderValue) => void)

Called with the full order when the mode, outcome or amount changes.

Default—
onTrade?
((order: PredictionMarketOrderValue, quote: PredictionMarketQuote) => void)

Called with the order and its quote once a valid trade fills.

Default—
onSignIn?
(() => void)

Called when the connect button is pressed while signed out.

Default—
authenticated?
boolean

Whether the user is signed in. When false, a connect button replaces the trade footer. Default: true

Defaulttrue
orderTypeLabel?
string

Text beside the buy and sell tabs. Default: "Market"

Default—
balance?
number

Cash available to buy with, in dollars. Default: 500

Default500
positions?
Record<string, number>

Shares held per outcome id, which caps how much can be sold.

Default{ up: 24, down: 16 }
quickAmounts?
number[]

Amounts the quick chips add to the input. Default: [10, 50, 100, 500]

Default[10, 50, 100, 500]
minTrade?
number

Smallest buy amount, in dollars. Default: 1

Default1
labels?
Partial<{ buy: string; sell: string; orderType: string; amount: string; shares: string; max: string; toWin: string; toReceive: string; avgPrice: string; trade: string; trading: string; tradeFilled: string; ... 4 more ...; notEnoughShares: string; }>

Override any built-in string. `{price}` fills `avgPrice`, `{amount}` fills `minimum`.

Default—
className?
string

Classes merged onto the root element.

Default—
classNames?
PredictionMarketClassNames

Classes for each inner part, keyed by slot.

Default—

More in Prediction Market

Keep in mind

Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.

Updated