From 8043fa515a28f9607ef60d5bb870223043559a61 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 4 Oct 2022 19:10:43 -0500 Subject: [PATCH] Show loan repaid in sell dialog --- web/components/bet-panel.tsx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index 6fcfc899..90db558d 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -838,6 +838,11 @@ export function SellPanel(props: { const sellQuantity = isSellingAllShares ? shares : amount + const loanAmount = sumBy(userBets, (bet) => bet.loanAmount ?? 0) + const soldShares = Math.min(sellQuantity ?? 0, shares) + const saleFrac = soldShares / shares + const loanPaid = saleFrac * loanAmount + async function submitSell() { if (!user || !amount) return @@ -882,6 +887,7 @@ export function SellPanel(props: { sharesOutcome, unfilledBets ) + const netProceeds = saleValue - loanPaid const resultProb = getCpmmProbability(cpmmState.pool, cpmmState.p) const getValue = getMappedValue(contract) @@ -941,9 +947,21 @@ export function SellPanel(props: { - Sale proceeds + Sale amount {formatMoney(saleValue)} + {loanPaid !== 0 && ( + <> + + Loan repaid + {formatMoney(-loanPaid)} + + + Net proceeds + {formatMoney(netProceeds)} + + + )}
{isPseudoNumeric ? 'Estimated value' : 'Probability'} @@ -960,7 +978,7 @@ export function SellPanel(props: {