From 86b4b1a9079f2806288df1e8823ee07f8b0efedf Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 14 Feb 2022 15:29:29 -0800 Subject: [PATCH] Use badges in Your Trades --- web/components/bets-list.tsx | 75 +++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 9dae42fc..dc35e523 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -123,33 +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 color = pnl === 0 ? '' : pnl > 0 ? 'text-green-500' : 'text-red-500' + const totalPnl = totalPortfolio - user.totalDeposits + const totalProfit = (totalPnl / user.totalDeposits) * 100 + const investedProfit = + ((currentBetsValue - currentInvestment) / currentInvestment) * 100 return ( -
Portfolio value
-
{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)}{' '} + +
@@ -282,21 +283,15 @@ export function MyBetsSummary(props: { const currentValue = resolution ? betsPayout : marketWinnings const pnl = currentValue - betsTotal - const totalReturn = - betsTotal === 0 - ? '0%' - : (pnl > 0 ? '+' : '') + ((pnl / betsTotal) * 100).toFixed() + '%' + const profit = (pnl / betsTotal) * 100 - const color = pnl === 0 ? '' : pnl > 0 ? 'text-green-500' : 'text-red-500' - - const mktCol = ( + const valueCol = ( -
- Market value +
+ {formatMoney(currentValue)}
-
- {formatMoney(marketWinnings)} ( - {totalReturn}) +
+
) @@ -305,7 +300,7 @@ export function MyBetsSummary(props: {
Payout
- {formatMoney(betsPayout)} ({totalReturn}) + {formatMoney(betsPayout)}
) @@ -319,7 +314,7 @@ export function MyBetsSummary(props: { )} > {onlyMKT ? ( - {resolution ? payoutCol : mktCol} + {valueCol} ) : ( @@ -496,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) + '%'} + + ) +}