From d081f5215da68773f9f0147731a237a5c0d2fa90 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 17 Aug 2022 15:57:37 -0500 Subject: [PATCH] Show current user profit on bets page --- web/components/bets-list.tsx | 48 ++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 18349597..9e407f57 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -6,7 +6,7 @@ import clsx from 'clsx' import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/solid' import { Bet } from 'web/lib/firebase/bets' -import { User } from 'web/lib/firebase/users' +import { getFirstDayProfit, User } from 'web/lib/firebase/users' import { formatLargeNumber, formatMoney, @@ -73,6 +73,7 @@ export function BetsList(props: { const [sort, setSort] = useState('newest') const [filter, setFilter] = useState('open') + const [firstDayProfit, setFirstDayProfit] = useState(0) const [page, setPage] = useState(0) const start = page * CONTRACTS_PER_PAGE const end = start + CONTRACTS_PER_PAGE @@ -84,6 +85,12 @@ export function BetsList(props: { } }, [signedInUser, bets, contractsById, getTime]) + useEffect(() => { + if (signedInUser && signedInUser.id === user.id) { + getFirstDayProfit(signedInUser.id).then(setFirstDayProfit) + } + }, [signedInUser, user]) + if (!bets || !contractsById) { return } @@ -157,30 +164,33 @@ export function BetsList(props: { (c) => contractsMetrics[c.id].netPayout ) - const totalPnl = user.profitCached.allTime - const totalProfitPercent = (totalPnl / user.totalDeposits) * 100 + const totalPnl = (signedInUser?.profitCached.allTime ?? 0) - firstDayProfit + const totalProfitPercent = + (totalPnl / (signedInUser?.totalDeposits ?? 1000)) * 100 const investedProfitPercent = ((currentBetsValue - currentInvested) / (currentInvested + 0.1)) * 100 return ( - - -
Investment value
-
- {formatMoney(currentNetInvestment)}{' '} - -
- - -
Total profit
-
- {formatMoney(totalPnl)}{' '} - -
- -
+ {user.id === signedInUser?.id && ( + + +
Investment value
+
+ {formatMoney(currentNetInvestment)}{' '} + +
+ + +
Total profit
+
+ {formatMoney(totalPnl)}{' '} + +
+ +
+ )}