import { sumBy } from 'lodash' import clsx from 'clsx' import { Bet } from 'web/lib/firebase/bets' import { formatMoney, formatWithCommas } from 'common/util/format' import { Col } from './layout/col' import { Contract } from 'web/lib/firebase/contracts' import { Row } from './layout/row' import { YesLabel, NoLabel } from './outcome-label' import { calculatePayout, getContractBetMetrics, getProbability, } from 'common/calculate' import { InfoTooltip } from './info-tooltip' import { ProfitBadge } from './profit-badge' export function BetsSummary(props: { contract: Contract userBets: Bet[] className?: string }) { const { contract, className } = props const { resolution, outcomeType } = contract const isBinary = outcomeType === 'BINARY' const bets = props.userBets.filter((b) => !b.isAnte) const { profitPercent, payout, profit, invested } = getContractBetMetrics( contract, bets ) const excludeSales = bets.filter((b) => !b.isSold && !b.sale) const yesWinnings = sumBy(excludeSales, (bet) => calculatePayout(contract, bet, 'YES') ) const noWinnings = sumBy(excludeSales, (bet) => calculatePayout(contract, bet, 'NO') ) const position = yesWinnings - noWinnings const prob = isBinary ? getProbability(contract) : 0 const expectation = prob * yesWinnings + (1 - prob) * noWinnings if (bets.length === 0) return <>> return (