import Link from 'next/link' import _ from 'lodash' import dayjs from 'dayjs' import { useContract } from '../hooks/use-contract' import { useUserBets } from '../hooks/use-user-bets' import { Bet } from '../lib/firebase/bets' import { User } from '../lib/firebase/users' import { formatMoney, formatPercent } from '../lib/util/format' import { Col } from './layout/col' import { ContractDetails } from './contracts-list' import { Spacer } from './layout/spacer' export function BetsList(props: { user: User }) { const { user } = props const bets = useUserBets(user?.id ?? '') if (bets === 'loading') { return <> } if (bets.length === 0) return
You have not made any bets yet!
const contractBets = _.groupBy(bets, 'contractId') return ( {Object.keys(contractBets).map((contractId) => ( ))} ) } function ContractBetsTable(props: { contractId: string; bets: Bet[] }) { const { contractId, bets } = props const contract = useContract(contractId) if (contract === 'loading' || contract === null) return <> return (

{contract.question}

{bets.map((bet) => ( ))}
Outcome Amount Probability Estimated payoff Date
) } function BetRow(props: { bet: Bet }) { const { bet } = props const { amount, outcome, createdTime, probBefore, probAfter, dpmWeight } = bet return ( {outcome} {formatMoney(amount)} {formatPercent(probBefore)} → {formatPercent(probAfter)} {formatMoney(amount + dpmWeight)} {dayjs(createdTime).format('MMM D, H:mma')} ) }