From 083cf600ef82f0f0aa6df2640cb6dfd853643a91 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Mon, 26 Sep 2022 12:44:04 -0400 Subject: [PATCH] show position, expected value, profit instead of "invested" --- web/components/bets-list.tsx | 132 +++++++++++++++-------------------- 1 file changed, 56 insertions(+), 76 deletions(-) diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 97d11758..4e2f60e0 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -33,12 +33,12 @@ import { getContractBetMetrics, resolvedPayout, getContractBetNullMetrics, + getProbability, } from 'common/calculate' import { NumericContract } from 'common/contract' import { formatNumericProbability } from 'common/pseudo-numeric' import { useUser } from 'web/hooks/use-user' import { useUserBets } from 'web/hooks/use-user-bets' -import { SellSharesModal } from './sell-modal' import { useUnfilledBets } from 'web/hooks/use-bets' import { LimitBet } from 'common/bet' import { floatingEqual } from 'common/util/math' @@ -46,6 +46,7 @@ import { Pagination } from './pagination' import { LimitOrderTable } from './limit-bets' import { UserLink } from 'web/components/user-link' import { useUserBetContracts } from 'web/hooks/use-contracts' +import { InfoTooltip } from './info-tooltip' type BetSort = 'newest' | 'profit' | 'closeTime' | 'value' type BetFilter = 'open' | 'limit_bet' | 'sold' | 'closed' | 'resolved' | 'all' @@ -379,16 +380,15 @@ export function BetsSummary(props: { isYourBets: boolean className?: string }) { - const { contract, isYourBets, className } = props - const { resolution, closeTime, outcomeType, mechanism } = contract + const { contract, className } = props + const { resolution, outcomeType } = contract const isBinary = outcomeType === 'BINARY' - const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC' - const isCpmm = mechanism === 'cpmm-1' - const isClosed = closeTime && Date.now() > closeTime const bets = props.bets.filter((b) => !b.isAnte) - const { hasShares, invested, profitPercent, payout, profit, totalShares } = - getContractBetMetrics(contract, bets) + const { profitPercent, payout, profit, totalShares } = getContractBetMetrics( + contract, + bets + ) const excludeSales = bets.filter((b) => !b.isSold && !b.sale) const yesWinnings = sumBy(excludeSales, (bet) => @@ -398,62 +398,19 @@ export function BetsSummary(props: { calculatePayout(contract, bet, 'NO') ) - const [showSellModal, setShowSellModal] = useState(false) - const user = useUser() + const prob = isBinary ? getProbability(contract) : 0 + const expectation = prob * yesWinnings + (1 - prob) * noWinnings - const sharesOutcome = floatingEqual(totalShares.YES ?? 0, 0) - ? floatingEqual(totalShares.NO ?? 0, 0) - ? undefined - : 'NO' - : 'YES' - - const canSell = - isYourBets && - isCpmm && - (isBinary || isPseudoNumeric) && - !isClosed && - !resolution && - hasShares && - sharesOutcome && - user + if ( + isBinary && + floatingEqual(totalShares.YES ?? 0, 0) && + floatingEqual(totalShares.NO ?? 0, 0) + ) + return <> return ( - -
- Invested -
-
{formatMoney(invested)}
- - -
Profit
-
- {formatMoney(profit)} -
- - {canSell && ( - <> - - {showSellModal && ( - - )} - - )} -
- {resolution ? (
Payout
@@ -463,31 +420,54 @@ export function BetsSummary(props: { ) : isBinary ? ( - <> - -
- Payout if -
-
- {formatMoney(yesWinnings)} -
- - -
- Payout if -
-
{formatMoney(noWinnings)}
- - + +
+ Position{' '} + +
+
+ {yesWinnings > 0 ? ( + <> + {formatWithCommas(yesWinnings)} + + ) : ( + <> + {formatWithCommas(noWinnings)} + + )} +
+ ) : (
- Expected value + Expected value {''} +
{formatMoney(payout)}
)} + + {isBinary && ( + +
+ Expected value{' '} + +
+
{formatMoney(expectation)}
+ + )} + + +
+ Profit{' '} + +
+
+ {formatMoney(profit)} +
+
+ ) }