Handle bets table for loans. Sell dialog explains how you will repay your loan.

This commit is contained in:
James Grugett 2022-03-01 17:12:29 -08:00
parent 1da30812ad
commit 1d73f6e863

View File

@ -457,6 +457,7 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
shares, shares,
isSold, isSold,
isAnte, isAnte,
loanAmount,
} = bet } = bet
const { isResolved, closeTime } = contract const { isResolved, closeTime } = contract
@ -464,7 +465,7 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
const saleAmount = saleBet?.sale?.amount const saleAmount = saleBet?.sale?.amount
const saleDisplay = bet.isAnte ? ( const saleDisplay = isAnte ? (
'ANTE' 'ANTE'
) : saleAmount !== undefined ? ( ) : saleAmount !== undefined ? (
<>{formatMoney(saleAmount)} (sold)</> <>{formatMoney(saleAmount)} (sold)</>
@ -491,7 +492,10 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
<td> <td>
<OutcomeLabel outcome={outcome} /> <OutcomeLabel outcome={outcome} />
</td> </td>
<td>{formatMoney(amount)}</td> <td>
{formatMoney(amount)}
{loanAmount ? ` (${formatMoney(loanAmount ?? 0)} loan)` : ''}
</td>
<td>{saleDisplay}</td> <td>{saleDisplay}</td>
{!isResolved && <td>{payoutIfChosenDisplay}</td>} {!isResolved && <td>{payoutIfChosenDisplay}</td>}
<td> <td>
@ -510,18 +514,19 @@ function SellButton(props: { contract: Contract; bet: Bet }) {
}, []) }, [])
const { contract, bet } = props const { contract, bet } = props
const isBinary = contract.outcomeType === 'BINARY' const { outcome, shares, loanAmount } = bet
const [isSubmitting, setIsSubmitting] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false)
const initialProb = getOutcomeProbability( const initialProb = getOutcomeProbability(
contract.totalShares, contract.totalShares,
bet.outcome === 'NO' ? 'YES' : bet.outcome outcome === 'NO' ? 'YES' : outcome
) )
const outcomeProb = getProbabilityAfterSale( const outcomeProb = getProbabilityAfterSale(
contract.totalShares, contract.totalShares,
bet.outcome, outcome,
bet.shares shares
) )
const saleAmount = calculateSaleAmount(contract, bet) const saleAmount = calculateSaleAmount(contract, bet)
@ -544,14 +549,19 @@ function SellButton(props: { contract: Contract; bet: Bet }) {
Sell <OutcomeLabel outcome={bet.outcome} /> Sell <OutcomeLabel outcome={bet.outcome} />
</div> </div>
<div> <div>
Do you want to sell {formatWithCommas(bet.shares)} shares of{' '} Do you want to sell {formatWithCommas(shares)} shares of{' '}
<OutcomeLabel outcome={bet.outcome} /> for {formatMoney(saleAmount)}? <OutcomeLabel outcome={outcome} /> for {formatMoney(saleAmount)}?
</div> </div>
{!!loanAmount && (
<div className="mt-2">
You will also pay back {formatMoney(loanAmount)} of your loan for a
net of {formatMoney(saleAmount - loanAmount)}.
</div>
)}
<div className="mt-2 mb-1 text-sm text-gray-500"> <div className="mt-2 mb-1 text-sm">
({isBinary ? 'Updated' : <OutcomeLabel outcome={bet.outcome} />}{' '} (Updated probability: {formatPercent(initialProb)} {' '}
probability: {formatPercent(initialProb)} {formatPercent(outcomeProb)} {formatPercent(outcomeProb)})
)
</div> </div>
</ConfirmationButton> </ConfirmationButton>
) )