2022-05-09 13:04:36 +00:00
|
|
|
import { Bet } from 'common/bet'
|
|
|
|
import { Contract } from 'common/contract'
|
2022-08-19 08:06:40 +00:00
|
|
|
import { ContractComment } from 'common/comment'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { User } from 'common/user'
|
2022-04-08 21:13:10 +00:00
|
|
|
import { ContractActivity } from '../feed/contract-activity'
|
2022-06-01 16:28:47 +00:00
|
|
|
import { ContractBetsTable, BetsSummary } from '../bets-list'
|
2022-04-08 21:13:10 +00:00
|
|
|
import { Spacer } from '../layout/spacer'
|
|
|
|
import { Tabs } from '../layout/tabs'
|
2022-05-03 20:38:40 +00:00
|
|
|
import { Col } from '../layout/col'
|
2022-06-18 03:28:16 +00:00
|
|
|
import { CommentTipMap } from 'web/hooks/use-tip-txns'
|
2022-07-24 07:11:33 +00:00
|
|
|
import { useComments } from 'web/hooks/use-comments'
|
2022-08-11 19:53:54 +00:00
|
|
|
import { useLiquidity } from 'web/hooks/use-liquidity'
|
2022-04-08 21:13:10 +00:00
|
|
|
|
|
|
|
export function ContractTabs(props: {
|
|
|
|
contract: Contract
|
|
|
|
user: User | null | undefined
|
|
|
|
bets: Bet[]
|
2022-08-19 08:06:40 +00:00
|
|
|
comments: ContractComment[]
|
2022-06-18 03:28:16 +00:00
|
|
|
tips: CommentTipMap
|
2022-04-08 21:13:10 +00:00
|
|
|
}) {
|
2022-08-11 19:53:54 +00:00
|
|
|
const { contract, user, bets, tips } = props
|
2022-05-19 17:42:03 +00:00
|
|
|
const { outcomeType } = contract
|
2022-04-08 21:13:10 +00:00
|
|
|
|
|
|
|
const userBets = user && bets.filter((bet) => bet.userId === user.id)
|
2022-08-03 00:40:34 +00:00
|
|
|
const visibleBets = bets.filter(
|
|
|
|
(bet) => !bet.isAnte && !bet.isRedemption && bet.amount !== 0
|
|
|
|
)
|
2022-04-08 21:13:10 +00:00
|
|
|
|
2022-08-11 19:53:54 +00:00
|
|
|
const liquidityProvisions =
|
|
|
|
useLiquidity(contract.id)?.filter((l) => !l.isAnte && l.amount > 0) ?? []
|
|
|
|
|
2022-07-24 07:11:33 +00:00
|
|
|
// Load comments here, so the badge count will be correct
|
|
|
|
const updatedComments = useComments(contract.id)
|
|
|
|
const comments = updatedComments ?? props.comments
|
|
|
|
|
2022-04-26 21:08:50 +00:00
|
|
|
const betActivity = (
|
2022-04-08 21:13:10 +00:00
|
|
|
<ContractActivity
|
|
|
|
contract={contract}
|
|
|
|
bets={bets}
|
2022-06-27 00:00:02 +00:00
|
|
|
liquidityProvisions={liquidityProvisions}
|
2022-04-08 21:13:10 +00:00
|
|
|
comments={comments}
|
2022-06-18 03:28:16 +00:00
|
|
|
tips={tips}
|
2022-04-08 21:13:10 +00:00
|
|
|
user={user}
|
2022-04-26 21:08:50 +00:00
|
|
|
mode="bets"
|
|
|
|
betRowClassName="!mt-0 xl:hidden"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
const commentActivity = (
|
2022-05-03 20:38:40 +00:00
|
|
|
<>
|
|
|
|
<ContractActivity
|
|
|
|
contract={contract}
|
|
|
|
bets={bets}
|
2022-06-27 00:00:02 +00:00
|
|
|
liquidityProvisions={liquidityProvisions}
|
2022-05-03 20:38:40 +00:00
|
|
|
comments={comments}
|
2022-06-18 03:28:16 +00:00
|
|
|
tips={tips}
|
2022-05-03 20:38:40 +00:00
|
|
|
user={user}
|
|
|
|
mode={
|
|
|
|
contract.outcomeType === 'FREE_RESPONSE'
|
|
|
|
? 'free-response-comment-answer-groups'
|
|
|
|
: 'comments'
|
|
|
|
}
|
|
|
|
betRowClassName="!mt-0 xl:hidden"
|
|
|
|
/>
|
2022-05-19 17:42:03 +00:00
|
|
|
{outcomeType === 'FREE_RESPONSE' && (
|
2022-05-03 20:38:40 +00:00
|
|
|
<Col className={'mt-8 flex w-full '}>
|
|
|
|
<div className={'text-md mt-8 mb-2 text-left'}>General Comments</div>
|
|
|
|
<div className={'mb-4 w-full border-b border-gray-200'} />
|
|
|
|
<ContractActivity
|
|
|
|
contract={contract}
|
|
|
|
bets={bets}
|
2022-06-27 00:00:02 +00:00
|
|
|
liquidityProvisions={liquidityProvisions}
|
2022-05-03 20:38:40 +00:00
|
|
|
comments={comments}
|
2022-06-18 03:28:16 +00:00
|
|
|
tips={tips}
|
2022-05-03 20:38:40 +00:00
|
|
|
user={user}
|
|
|
|
mode={'comments'}
|
|
|
|
betRowClassName="!mt-0 xl:hidden"
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
)}
|
|
|
|
</>
|
2022-04-08 21:13:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const yourTrades = (
|
|
|
|
<div>
|
2022-06-01 16:28:47 +00:00
|
|
|
<BetsSummary
|
2022-04-09 21:34:43 +00:00
|
|
|
className="px-2"
|
|
|
|
contract={contract}
|
|
|
|
bets={userBets ?? []}
|
2022-06-01 16:28:47 +00:00
|
|
|
isYourBets
|
2022-04-09 21:34:43 +00:00
|
|
|
/>
|
2022-04-08 21:13:10 +00:00
|
|
|
<Spacer h={6} />
|
2022-06-01 16:28:47 +00:00
|
|
|
<ContractBetsTable contract={contract} bets={userBets ?? []} isYourBets />
|
2022-04-08 21:13:10 +00:00
|
|
|
<Spacer h={12} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tabs
|
2022-07-07 21:24:13 +00:00
|
|
|
currentPageForAnalytics={'contract'}
|
2022-04-08 21:13:10 +00:00
|
|
|
tabs={[
|
2022-07-24 07:11:33 +00:00
|
|
|
{
|
|
|
|
title: 'Comments',
|
|
|
|
content: commentActivity,
|
|
|
|
badge: `${comments.length}`,
|
|
|
|
},
|
2022-08-03 00:40:34 +00:00
|
|
|
{ title: 'Bets', content: betActivity, badge: `${visibleBets.length}` },
|
2022-04-09 21:34:43 +00:00
|
|
|
...(!user || !userBets?.length
|
|
|
|
? []
|
2022-04-26 14:38:28 +00:00
|
|
|
: [{ title: 'Your bets', content: yourTrades }]),
|
2022-04-08 21:13:10 +00:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|