Hide sell buttons in other people's profiles

This commit is contained in:
James Grugett 2022-06-01 11:28:47 -05:00
parent 59830579a9
commit 2c4aa6152e
2 changed files with 60 additions and 34 deletions

View File

@ -56,6 +56,10 @@ type BetFilter = 'open' | 'sold' | 'closed' | 'resolved' | 'all'
export function BetsList(props: { user: User; hideBetsBefore?: number }) { export function BetsList(props: { user: User; hideBetsBefore?: number }) {
const { user, hideBetsBefore } = props const { user, hideBetsBefore } = props
const signedInUser = useUser()
const isYourBets = user.id === signedInUser?.id
const allBets = useUserBets(user.id, { includeRedemptions: true }) const allBets = useUserBets(user.id, { includeRedemptions: true })
// Hide bets before 06-01-2022 if this isn't your own profile // 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. // 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 }) {
<NoBets /> <NoBets />
) : ( ) : (
displayedContracts.map((contract) => ( displayedContracts.map((contract) => (
<MyContractBets <ContractBets
key={contract.id} key={contract.id}
contract={contract} contract={contract}
bets={contractBets[contract.id] ?? []} bets={contractBets[contract.id] ?? []}
metric={sort === 'profit' ? 'profit' : 'value'} metric={sort === 'profit' ? 'profit' : 'value'}
isYourBets={isYourBets}
/> />
)) ))
)} )}
@ -242,12 +247,13 @@ const NoBets = () => {
) )
} }
function MyContractBets(props: { function ContractBets(props: {
contract: Contract contract: Contract
bets: Bet[] bets: Bet[]
metric: 'profit' | 'value' metric: 'profit' | 'value'
isYourBets: boolean
}) { }) {
const { bets, contract, metric } = props const { bets, contract, metric, isYourBets } = props
const { resolution, outcomeType } = contract const { resolution, outcomeType } = contract
const resolutionValue = (contract as NumericContract).resolutionValue const resolutionValue = (contract as NumericContract).resolutionValue
@ -337,26 +343,32 @@ function MyContractBets(props: {
> >
<Spacer h={8} /> <Spacer h={8} />
<MyBetsSummary <BetsSummary
className="mr-5 flex-1 sm:mr-8" className="mr-5 flex-1 sm:mr-8"
contract={contract} contract={contract}
bets={bets} bets={bets}
isYourBets={isYourBets}
/> />
<Spacer h={8} /> <Spacer h={8} />
<ContractBetsTable contract={contract} bets={bets} /> <ContractBetsTable
contract={contract}
bets={bets}
isYourBets={isYourBets}
/>
</div> </div>
</div> </div>
) )
} }
export function MyBetsSummary(props: { export function BetsSummary(props: {
contract: Contract contract: Contract
bets: Bet[] bets: Bet[]
isYourBets: boolean
className?: string className?: string
}) { }) {
const { contract, className } = props const { contract, isYourBets, className } = props
const { resolution, outcomeType, mechanism } = contract const { resolution, outcomeType, mechanism } = contract
const isBinary = outcomeType === 'BINARY' const isBinary = outcomeType === 'BINARY'
const isCpmm = mechanism === 'cpmm-1' const isCpmm = mechanism === 'cpmm-1'
@ -432,26 +444,31 @@ export function MyBetsSummary(props: {
<div className="whitespace-nowrap text-sm text-gray-500">Profit</div> <div className="whitespace-nowrap text-sm text-gray-500">Profit</div>
<div className="whitespace-nowrap"> <div className="whitespace-nowrap">
{formatMoney(profit)} <ProfitBadge profitPercent={profitPercent} /> {formatMoney(profit)} <ProfitBadge profitPercent={profitPercent} />
{isCpmm && isBinary && !resolution && invested > 0 && user && ( {isYourBets &&
<> isCpmm &&
<button isBinary &&
className="btn btn-sm ml-2" !resolution &&
onClick={() => setShowSellModal(true)} invested > 0 &&
> user && (
Sell <>
</button> <button
{showSellModal && ( className="btn btn-sm ml-2"
<SellSharesModal onClick={() => setShowSellModal(true)}
contract={contract} >
user={user} Sell
userBets={bets} </button>
shares={totalShares.YES || totalShares.NO} {showSellModal && (
sharesOutcome={totalShares.YES ? 'YES' : 'NO'} <SellSharesModal
setOpen={setShowSellModal} contract={contract}
/> user={user}
)} userBets={bets}
</> shares={totalShares.YES || totalShares.NO}
)} sharesOutcome={totalShares.YES ? 'YES' : 'NO'}
setOpen={setShowSellModal}
/>
)}
</>
)}
</div> </div>
</Col> </Col>
</Row> </Row>
@ -462,9 +479,10 @@ export function MyBetsSummary(props: {
export function ContractBetsTable(props: { export function ContractBetsTable(props: {
contract: Contract contract: Contract
bets: Bet[] bets: Bet[]
isYourBets: boolean
className?: string className?: string
}) { }) {
const { contract, className } = props const { contract, className, isYourBets } = props
const bets = props.bets.filter((b) => !b.isAnte) const bets = props.bets.filter((b) => !b.isAnte)
@ -533,6 +551,7 @@ export function ContractBetsTable(props: {
bet={bet} bet={bet}
saleBet={salesDict[bet.id]} saleBet={salesDict[bet.id]}
contract={contract} contract={contract}
isYourBet={isYourBets}
/> />
))} ))}
</tbody> </tbody>
@ -541,8 +560,13 @@ export function ContractBetsTable(props: {
) )
} }
function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) { function BetRow(props: {
const { bet, saleBet, contract } = props bet: Bet
contract: Contract
saleBet?: Bet
isYourBet: boolean
}) {
const { bet, saleBet, contract, isYourBet } = props
const { const {
amount, amount,
outcome, outcome,
@ -583,7 +607,8 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
return ( return (
<tr> <tr>
<td className="text-neutral"> <td className="text-neutral">
{!isCPMM && {isYourBet &&
!isCPMM &&
!isResolved && !isResolved &&
!isClosed && !isClosed &&
!isSold && !isSold &&

View File

@ -4,7 +4,7 @@ import { Comment } from 'web/lib/firebase/comments'
import { User } from 'common/user' import { User } from 'common/user'
import { useBets } from 'web/hooks/use-bets' import { useBets } from 'web/hooks/use-bets'
import { ContractActivity } from '../feed/contract-activity' import { ContractActivity } from '../feed/contract-activity'
import { ContractBetsTable, MyBetsSummary } from '../bets-list' import { ContractBetsTable, BetsSummary } from '../bets-list'
import { Spacer } from '../layout/spacer' import { Spacer } from '../layout/spacer'
import { Tabs } from '../layout/tabs' import { Tabs } from '../layout/tabs'
import { Col } from '../layout/col' import { Col } from '../layout/col'
@ -67,13 +67,14 @@ export function ContractTabs(props: {
const yourTrades = ( const yourTrades = (
<div> <div>
<MyBetsSummary <BetsSummary
className="px-2" className="px-2"
contract={contract} contract={contract}
bets={userBets ?? []} bets={userBets ?? []}
isYourBets
/> />
<Spacer h={6} /> <Spacer h={6} />
<ContractBetsTable contract={contract} bets={userBets ?? []} /> <ContractBetsTable contract={contract} bets={userBets ?? []} isYourBets />
<Spacer h={12} /> <Spacer h={12} />
</div> </div>
) )