2022-05-09 13:04:36 +00:00
|
|
|
import { Bet } from 'common/bet'
|
2022-09-20 21:04:07 +00:00
|
|
|
import { Contract } from 'common/contract'
|
2022-08-19 08:06:40 +00:00
|
|
|
import { ContractComment } from 'common/comment'
|
2022-09-15 15:12:56 +00:00
|
|
|
import { PAST_BETS, User } from 'common/user'
|
2022-08-30 09:41:47 +00:00
|
|
|
import {
|
|
|
|
ContractCommentsActivity,
|
|
|
|
ContractBetsActivity,
|
|
|
|
FreeResponseContractCommentsActivity,
|
|
|
|
} 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-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-09-20 22:58:47 +00:00
|
|
|
import { useTipTxns } from 'web/hooks/use-tip-txns'
|
2022-09-15 15:57:14 +00:00
|
|
|
import { capitalize } from 'lodash'
|
2022-09-15 20:47:07 +00:00
|
|
|
import {
|
|
|
|
DEV_HOUSE_LIQUIDITY_PROVIDER_ID,
|
|
|
|
HOUSE_LIQUIDITY_PROVIDER_ID,
|
|
|
|
} from 'common/antes'
|
2022-09-16 15:28:39 +00:00
|
|
|
import { useIsMobile } from 'web/hooks/use-is-mobile'
|
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-04-08 21:13:10 +00:00
|
|
|
}) {
|
2022-09-20 22:58:47 +00:00
|
|
|
const { contract, user, bets } = props
|
2022-05-19 17:42:03 +00:00
|
|
|
const { outcomeType } = contract
|
2022-09-16 15:28:39 +00:00
|
|
|
const isMobile = useIsMobile()
|
2022-04-08 21:13:10 +00:00
|
|
|
|
2022-09-20 22:58:47 +00:00
|
|
|
const tips = useTipTxns({ contractId: contract.id })
|
2022-09-09 04:45:26 +00:00
|
|
|
const lps = useLiquidity(contract.id)
|
2022-08-30 09:41:47 +00:00
|
|
|
|
|
|
|
const userBets =
|
|
|
|
user && bets.filter((bet) => !bet.isAnte && 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-09-15 20:47:07 +00:00
|
|
|
const visibleLps = (lps ?? []).filter(
|
|
|
|
(l) =>
|
|
|
|
!l.isAnte &&
|
|
|
|
l.userId !== HOUSE_LIQUIDITY_PROVIDER_ID &&
|
|
|
|
l.userId !== DEV_HOUSE_LIQUIDITY_PROVIDER_ID &&
|
|
|
|
l.amount > 0
|
|
|
|
)
|
2022-08-11 19:53:54 +00:00
|
|
|
|
2022-09-20 22:53:35 +00:00
|
|
|
const comments = useComments(contract.id) ?? props.comments
|
2022-07-24 07:11:33 +00:00
|
|
|
|
2022-09-15 20:47:07 +00:00
|
|
|
const betActivity = lps != null && (
|
2022-08-30 09:41:47 +00:00
|
|
|
<ContractBetsActivity
|
2022-04-08 21:13:10 +00:00
|
|
|
contract={contract}
|
2022-08-30 09:41:47 +00:00
|
|
|
bets={visibleBets}
|
|
|
|
lps={visibleLps}
|
2022-04-26 21:08:50 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
2022-08-30 09:41:47 +00:00
|
|
|
const generalComments = comments.filter(
|
|
|
|
(comment) =>
|
|
|
|
comment.answerOutcome === undefined &&
|
|
|
|
(outcomeType === 'FREE_RESPONSE' ? comment.betId === undefined : true)
|
|
|
|
)
|
|
|
|
|
|
|
|
const commentActivity =
|
|
|
|
outcomeType === 'FREE_RESPONSE' ? (
|
|
|
|
<>
|
|
|
|
<FreeResponseContractCommentsActivity
|
|
|
|
contract={contract}
|
|
|
|
comments={comments}
|
|
|
|
tips={tips}
|
|
|
|
/>
|
2022-09-20 22:25:58 +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" />
|
2022-08-30 09:41:47 +00:00
|
|
|
<ContractCommentsActivity
|
2022-05-03 20:38:40 +00:00
|
|
|
contract={contract}
|
2022-08-30 09:41:47 +00:00
|
|
|
comments={generalComments}
|
2022-06-18 03:28:16 +00:00
|
|
|
tips={tips}
|
2022-05-03 20:38:40 +00:00
|
|
|
/>
|
|
|
|
</Col>
|
2022-08-30 09:41:47 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<ContractCommentsActivity
|
|
|
|
contract={contract}
|
|
|
|
comments={comments}
|
|
|
|
tips={tips}
|
|
|
|
/>
|
|
|
|
)
|
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 (
|
2022-09-20 21:04:07 +00:00
|
|
|
<Tabs
|
2022-09-20 22:53:35 +00:00
|
|
|
currentPageForAnalytics={'contract'}
|
2022-09-20 21:04:07 +00:00
|
|
|
tabs={[
|
2022-09-20 22:53:35 +00:00
|
|
|
{ title: 'Comments', content: commentActivity },
|
|
|
|
{ title: capitalize(PAST_BETS), content: betActivity },
|
2022-09-20 21:04:07 +00:00
|
|
|
...(!user || !userBets?.length
|
|
|
|
? []
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
title: isMobile ? `You` : `Your ${PAST_BETS}`,
|
|
|
|
content: yourTrades,
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
]}
|
|
|
|
/>
|
2022-04-08 21:13:10 +00:00
|
|
|
)
|
|
|
|
}
|