Add profit amount to sell dialog.

This commit is contained in:
James Grugett 2022-10-04 19:35:29 -05:00
parent 8043fa515a
commit d8ef363f06

View File

@ -25,7 +25,7 @@ import {
NoLabel, NoLabel,
YesLabel, YesLabel,
} from './outcome-label' } from './outcome-label'
import { getProbability } from 'common/calculate' import { getContractBetMetrics, getProbability } from 'common/calculate'
import { useFocus } from 'web/hooks/use-focus' import { useFocus } from 'web/hooks/use-focus'
import { useUserContractBets } from 'web/hooks/use-user-bets' import { useUserContractBets } from 'web/hooks/use-user-bets'
import { calculateCpmmSale, getCpmmProbability } from 'common/calculate-cpmm' import { calculateCpmmSale, getCpmmProbability } from 'common/calculate-cpmm'
@ -843,6 +843,9 @@ export function SellPanel(props: {
const saleFrac = soldShares / shares const saleFrac = soldShares / shares
const loanPaid = saleFrac * loanAmount const loanPaid = saleFrac * loanAmount
const { invested } = getContractBetMetrics(contract, userBets)
const costBasis = invested * saleFrac
async function submitSell() { async function submitSell() {
if (!user || !amount) return if (!user || !amount) return
@ -888,6 +891,7 @@ export function SellPanel(props: {
unfilledBets unfilledBets
) )
const netProceeds = saleValue - loanPaid const netProceeds = saleValue - loanPaid
const profit = saleValue - costBasis
const resultProb = getCpmmProbability(cpmmState.pool, cpmmState.p) const resultProb = getCpmmProbability(cpmmState.pool, cpmmState.p)
const getValue = getMappedValue(contract) const getValue = getMappedValue(contract)
@ -950,18 +954,10 @@ export function SellPanel(props: {
Sale amount Sale amount
<span className="text-neutral">{formatMoney(saleValue)}</span> <span className="text-neutral">{formatMoney(saleValue)}</span>
</Row> </Row>
{loanPaid !== 0 && (
<>
<Row className="items-center justify-between gap-2 text-gray-500"> <Row className="items-center justify-between gap-2 text-gray-500">
Loan repaid Profit
<span className="text-neutral">{formatMoney(-loanPaid)}</span> <span className="text-neutral">{formatMoney(profit)}</span>
</Row> </Row>
<Row className="items-center justify-between gap-2 text-gray-500">
Net proceeds
<span className="text-neutral">{formatMoney(netProceeds)}</span>
</Row>
</>
)}
<Row className="items-center justify-between"> <Row className="items-center justify-between">
<div className="text-gray-500"> <div className="text-gray-500">
{isPseudoNumeric ? 'Estimated value' : 'Probability'} {isPseudoNumeric ? 'Estimated value' : 'Probability'}
@ -972,20 +968,32 @@ export function SellPanel(props: {
{format(resultProb)} {format(resultProb)}
</div> </div>
</Row> </Row>
{loanPaid !== 0 && (
<>
<Row className="mt-6 items-center justify-between gap-2 text-gray-500">
Loan repaid
<span className="text-neutral">{formatMoney(-loanPaid)}</span>
</Row>
<Row className="items-center justify-between gap-2 text-gray-500">
Net proceeds
<span className="text-neutral">{formatMoney(netProceeds)}</span>
</Row>
</>
)}
</Col> </Col>
<Spacer h={8} /> <Spacer h={8} />
<WarningConfirmationButton <WarningConfirmationButton
marketType="binary" marketType="binary"
amount={netProceeds} amount={undefined}
warning={warning} warning={warning}
isSubmitting={isSubmitting} isSubmitting={isSubmitting}
onSubmit={betDisabled ? undefined : submitSell} onSubmit={betDisabled ? undefined : submitSell}
disabled={!!betDisabled} disabled={!!betDisabled}
size="xl" size="xl"
color="blue" color="blue"
actionLabel="Sell" actionLabel={`Sell ${Math.floor(soldShares)} shares`}
/> />
{wasSubmitted && <div className="mt-4">Sell submitted!</div>} {wasSubmitted && <div className="mt-4">Sell submitted!</div>}