From 2c4aa6152ead6a8b5022e2c1579ff9055aadccea Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 1 Jun 2022 11:28:47 -0500 Subject: [PATCH] Hide sell buttons in other people's profiles --- web/components/bets-list.tsx | 87 +++++++++++++++-------- web/components/contract/contract-tabs.tsx | 7 +- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 9ccaf204..2d3380ca 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -56,6 +56,10 @@ type BetFilter = 'open' | 'sold' | 'closed' | 'resolved' | 'all' export function BetsList(props: { user: User; hideBetsBefore?: number }) { const { user, hideBetsBefore } = props + + const signedInUser = useUser() + const isYourBets = user.id === signedInUser?.id + const allBets = useUserBets(user.id, { includeRedemptions: true }) // Hide bets before 06-01-2022 if this isn't your own profile // NOTE: This means public profits also begin on 06-01-2022 as well. @@ -218,11 +222,12 @@ export function BetsList(props: { user: User; hideBetsBefore?: number }) { ) : ( displayedContracts.map((contract) => ( - )) )} @@ -242,12 +247,13 @@ const NoBets = () => { ) } -function MyContractBets(props: { +function ContractBets(props: { contract: Contract bets: Bet[] metric: 'profit' | 'value' + isYourBets: boolean }) { - const { bets, contract, metric } = props + const { bets, contract, metric, isYourBets } = props const { resolution, outcomeType } = contract const resolutionValue = (contract as NumericContract).resolutionValue @@ -337,26 +343,32 @@ function MyContractBets(props: { > - - + ) } -export function MyBetsSummary(props: { +export function BetsSummary(props: { contract: Contract bets: Bet[] + isYourBets: boolean className?: string }) { - const { contract, className } = props + const { contract, isYourBets, className } = props const { resolution, outcomeType, mechanism } = contract const isBinary = outcomeType === 'BINARY' const isCpmm = mechanism === 'cpmm-1' @@ -432,26 +444,31 @@ export function MyBetsSummary(props: {
Profit
{formatMoney(profit)} - {isCpmm && isBinary && !resolution && invested > 0 && user && ( - <> - - {showSellModal && ( - - )} - - )} + {isYourBets && + isCpmm && + isBinary && + !resolution && + invested > 0 && + user && ( + <> + + {showSellModal && ( + + )} + + )}
@@ -462,9 +479,10 @@ export function MyBetsSummary(props: { export function ContractBetsTable(props: { contract: Contract bets: Bet[] + isYourBets: boolean className?: string }) { - const { contract, className } = props + const { contract, className, isYourBets } = props const bets = props.bets.filter((b) => !b.isAnte) @@ -533,6 +551,7 @@ export function ContractBetsTable(props: { bet={bet} saleBet={salesDict[bet.id]} contract={contract} + isYourBet={isYourBets} /> ))} @@ -541,8 +560,13 @@ export function ContractBetsTable(props: { ) } -function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) { - const { bet, saleBet, contract } = props +function BetRow(props: { + bet: Bet + contract: Contract + saleBet?: Bet + isYourBet: boolean +}) { + const { bet, saleBet, contract, isYourBet } = props const { amount, outcome, @@ -583,7 +607,8 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) { return ( - {!isCPMM && + {isYourBet && + !isCPMM && !isResolved && !isClosed && !isSold && diff --git a/web/components/contract/contract-tabs.tsx b/web/components/contract/contract-tabs.tsx index 887a3200..4384b390 100644 --- a/web/components/contract/contract-tabs.tsx +++ b/web/components/contract/contract-tabs.tsx @@ -4,7 +4,7 @@ import { Comment } from 'web/lib/firebase/comments' import { User } from 'common/user' import { useBets } from 'web/hooks/use-bets' import { ContractActivity } from '../feed/contract-activity' -import { ContractBetsTable, MyBetsSummary } from '../bets-list' +import { ContractBetsTable, BetsSummary } from '../bets-list' import { Spacer } from '../layout/spacer' import { Tabs } from '../layout/tabs' import { Col } from '../layout/col' @@ -67,13 +67,14 @@ export function ContractTabs(props: { const yourTrades = (
- - +
)