cpmm ContractBetsTable display

This commit is contained in:
mantikoros 2022-03-09 23:17:13 -06:00
parent 3145966a3c
commit b81742cd02

View File

@ -412,28 +412,46 @@ export function ContractBetsTable(props: {
const { contract, bets, className } = props
const [sales, buys] = _.partition(bets, (bet) => bet.sale)
const salesDict = _.fromPairs(
sales.map((sale) => [sale.sale?.betId ?? '', sale])
)
const { isResolved } = contract
const [redemptions, normalBets] = _.partition(buys, (b) => b.isRedemption)
const amountRedeemed = Math.floor(
-0.5 * _.sumBy(redemptions, (b) => b.shares)
)
const { isResolved, mechanism } = contract
const isCPMM = mechanism === 'cpmm-1'
return (
<div className={clsx('overflow-x-auto', className)}>
{amountRedeemed > 0 && (
<>
<div className="text-gray-500 text-sm pl-2">
{amountRedeemed} YES shares and {amountRedeemed} NO shares
automatically redeemed for {formatMoney(amountRedeemed)}.
</div>
<Spacer h={4} />
</>
)}
<table className="table-zebra table-compact table w-full text-gray-500">
<thead>
<tr className="p-2">
<th></th>
<th>Outcome</th>
<th>Amount</th>
<th>{isResolved ? <>Payout</> : <>Sale price</>}</th>
{!isResolved && <th>Payout if chosen</th>}
<th>Probability</th>
{!isCPMM && <th>{isResolved ? <>Payout</> : <>Sale price</>}</th>}
{!isCPMM && !isResolved && <th>Payout if chosen</th>}
<th>Shares</th>
<th>Probability</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{buys.map((bet) => (
{normalBets.map((bet) => (
<BetRow
key={bet.id}
bet={bet}
@ -458,12 +476,17 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
shares,
isSold,
isAnte,
isLiquidityProvision,
isRedemption,
loanAmount,
} = bet
const { isResolved, closeTime } = contract
const { isResolved, closeTime, mechanism } = contract
const isClosed = closeTime && Date.now() > closeTime
const isCPMM = mechanism === 'cpmm-1'
const saleAmount = saleBet?.sale?.amount
const saleDisplay = isAnte ? (
@ -486,9 +509,12 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
return (
<tr>
<td className="text-neutral">
{!isResolved && !isClosed && !isSold && !isAnte && (
{!isCPMM && !isResolved && !isClosed && !isSold && !isAnte && (
<SellButton contract={contract} bet={bet} />
)}
{/* {isAnte && 'ANTE'}
{isLiquidityProvision && !isAnte && 'LIQD'}
{isRedemption && 'REDEEM'} */}
</td>
<td>
<OutcomeLabel outcome={outcome} />
@ -497,12 +523,12 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
{formatMoney(amount)}
{loanAmount ? ` (${formatMoney(loanAmount ?? 0)} loan)` : ''}
</td>
<td>{saleDisplay}</td>
{!isResolved && <td>{payoutIfChosenDisplay}</td>}
{!isCPMM && <td>{saleDisplay}</td>}
{!isCPMM && !isResolved && <td>{payoutIfChosenDisplay}</td>}
<td>{formatWithCommas(shares)}</td>
<td>
{formatPercent(probBefore)} {formatPercent(probAfter)}
</td>
<td>{formatWithCommas(shares)}</td>
<td>{dayjs(createdTime).format('MMM D, h:mma')}</td>
</tr>
)