diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index e0c8c320..2fd8cca0 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -123,31 +123,34 @@ export function BetsList(props: { user: User }) { const totalPortfolio = currentBetsValue + user.balance - const pnl = totalPortfolio - user.totalDeposits - const totalReturn = - (pnl > 0 ? '+' : '') + ((pnl / user.totalDeposits) * 100).toFixed() + '%' + const totalPnl = totalPortfolio - user.totalDeposits + const totalProfit = (totalPnl / user.totalDeposits) * 100 + const investedProfit = + ((currentBetsValue - currentInvestment) / currentInvestment) * 100 return ( - + -
Total portfolio
-
{formatMoney(totalPortfolio)}
- - -
Total profits & losses
-
- {formatMoney(pnl)} ({totalReturn}) +
Invested
+
+ {formatMoney(currentBetsValue)}{' '} +
-
Currently invested
-
{formatMoney(currentInvestment)}
+
Balance
+
+ {formatMoney(user.balance)}{' '} +
-
Current market value
-
{formatMoney(currentBetsValue)}
+
Total portfolio
+
+ {formatMoney(totalPortfolio)}{' '} + +
@@ -187,9 +190,9 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) { )} onClick={() => setCollapsed((collapsed) => !collapsed)} > - + - + @@ -235,6 +239,14 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) { > + + + +
@@ -244,10 +256,10 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) { export function MyBetsSummary(props: { contract: Contract bets: Bet[] - showMKT?: boolean + onlyMKT?: boolean className?: string }) { - const { bets, contract, showMKT, className } = props + const { bets, contract, onlyMKT, className } = props const { resolution } = contract calculateCancelPayout @@ -269,49 +281,80 @@ export function MyBetsSummary(props: { calculatePayout(contract, bet, 'MKT') ) + const currentValue = resolution ? betsPayout : marketWinnings + const pnl = currentValue - betsTotal + const profit = (pnl / betsTotal) * 100 + + const valueCol = ( + +
+ {formatMoney(currentValue)} +
+
+ +
+ + ) + + const payoutCol = ( + +
Payout
+
+ {formatMoney(betsPayout)} +
+ + ) + return ( - -
Invested
-
{formatMoney(betsTotal)}
- - {resolution ? ( - -
Payout
-
{formatMoney(betsPayout)}
- + {onlyMKT ? ( + {valueCol} ) : (
- Payout if + Invested
-
{formatMoney(yesWinnings)}
+
{formatMoney(betsTotal)}
- -
- Payout if -
-
{formatMoney(noWinnings)}
- - {showMKT && ( - -
- Payout at{' '} - - {formatPercent(getProbability(contract.totalShares))} - -
-
- {formatMoney(marketWinnings)} -
- + {resolution ? ( + payoutCol + ) : ( + <> + +
+ Payout if +
+
+ {formatMoney(yesWinnings)} +
+ + +
+ Payout if +
+
+ {formatMoney(noWinnings)} +
+ + +
+ Payout at{' '} + + {formatPercent(getProbability(contract.totalShares))} + +
+
+ {formatMoney(marketWinnings)} +
+ + )}
)} @@ -448,3 +491,23 @@ function SellButton(props: { contract: Contract; bet: Bet }) { ) } + +function ProfitBadge(props: { profitPercent: number }) { + const { profitPercent } = props + if (!profitPercent) return null + const colors = + profitPercent > 0 + ? 'bg-green-100 text-green-800' + : 'bg-red-100 text-red-800' + + return ( + + {(profitPercent > 0 ? '+' : '') + profitPercent.toFixed(1) + '%'} + + ) +} diff --git a/web/components/contract-card.tsx b/web/components/contract-card.tsx index 1f062c89..3c644bf9 100644 --- a/web/components/contract-card.tsx +++ b/web/components/contract-card.tsx @@ -48,12 +48,13 @@ export function ContractCard(props: { -

{question}

- +

+ {question} +

+
@@ -61,12 +62,13 @@ export function ContractCard(props: { } export function ResolutionOrChance(props: { - resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL' | string - probPercent: string + contract: Contract large?: boolean className?: string }) { - const { resolution, probPercent, large, className } = props + const { contract, large, className } = props + const { resolution } = contract + const marketClosed = (contract.closeTime || Infinity) < Date.now() const resolutionColor = { @@ -77,11 +79,13 @@ export function ResolutionOrChance(props: { '': '', // Empty if unresolved }[resolution || ''] ?? 'text-primary' + const probColor = marketClosed ? 'text-gray-400' : 'text-primary' + const resolutionText = { YES: 'YES', NO: 'NO', - MKT: probPercent, + MKT: getBinaryProbPercent(contract), CANCEL: 'N/A', '': '', }[resolution || ''] ?? `#${resolution}` @@ -99,10 +103,8 @@ export function ResolutionOrChance(props: { ) : ( <> -
{probPercent}
-
+
{getBinaryProbPercent(contract)}
+
chance
diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx index 5ca67b1c..061991f5 100644 --- a/web/components/contract-feed.tsx +++ b/web/components/contract-feed.tsx @@ -342,11 +342,7 @@ function FeedQuestion(props: { contract: Contract }) { {question} {(isBinary || resolution) && ( - + )} )} @@ -74,8 +73,7 @@ export const ContractOverview = (props: { diff --git a/web/components/site-link.tsx b/web/components/site-link.tsx index d1dbca10..79f43118 100644 --- a/web/components/site-link.tsx +++ b/web/components/site-link.tsx @@ -12,9 +12,10 @@ export const SiteLink = (props: {
e.stopPropagation()} > {children} @@ -23,9 +24,10 @@ export const SiteLink = (props: { e.stopPropagation()} > {children} diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index 00c0f5ef..570aca01 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -176,12 +176,7 @@ function BetsSection(props: { {isBinary && ( <> - <MyBetsSummary - className="px-2" - contract={contract} - bets={userBets} - showMKT - /> + <MyBetsSummary className="px-2" contract={contract} bets={userBets} /> <Spacer h={6} /> </> )}