diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index 3ea02776..01f13caf 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -8,7 +8,7 @@ import { Col } from './layout/col' import { Row } from './layout/row' import { Spacer } from './layout/spacer' import { YesNoSelector } from './yes-no-selector' -import { formatMoney } from '../lib/util/format' +import { formatMoney, formatPercent } from '../lib/util/format' import { Title } from './title' export function BetPanel(props: { contract: Contract; className?: string }) { @@ -135,13 +135,9 @@ export function BetPanel(props: { contract: Contract; className?: string }) {
Implied probability
-
- {Math.round(initialProb * 100) + '%'} -
+
{formatPercent(initialProb)}
-
- {Math.round(resultProb * 100) + '%'} -
+
{formatPercent(resultProb)}
diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx new file mode 100644 index 00000000..68b9e59e --- /dev/null +++ b/web/components/bets-list.tsx @@ -0,0 +1,84 @@ +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' + +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 ContractBets(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) => ( + + ))} +
+
+ ) +} + +function BetCard(props: { bet: Bet }) { + const { bet } = props + const { contractId, amount, outcome, createdTime, probBefore, probAfter } = + bet + + return ( + + +
  • +
    +
    + +

    + {formatMoney(amount)} on {outcome} +

    +

    + {formatPercent(probBefore)} → {formatPercent(probAfter)} +

    +

    + {dayjs(createdTime).format('MMM D, H:mma')} +

    + +
    +
    +
  • +
    + + ) +} diff --git a/web/components/contracts-list.tsx b/web/components/contracts-list.tsx index a627a738..e3f43e0b 100644 --- a/web/components/contracts-list.tsx +++ b/web/components/contracts-list.tsx @@ -79,7 +79,7 @@ export function ContractsGrid(props: { contracts: Contract[] }) { return (