2022-01-02 19:09:01 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import Link from 'next/link'
|
2022-04-07 21:15:51 +00:00
|
|
|
import { Row } from '../layout/row'
|
2022-05-20 19:25:32 +00:00
|
|
|
import { formatLargeNumber, formatPercent } from 'common/util/format'
|
2022-06-01 02:42:35 +00:00
|
|
|
import { contractPath, getBinaryProbPercent } from 'web/lib/firebase/contracts'
|
2022-04-07 21:15:51 +00:00
|
|
|
import { Col } from '../layout/col'
|
2022-04-18 23:02:40 +00:00
|
|
|
import {
|
2022-06-01 02:42:35 +00:00
|
|
|
BinaryContract,
|
2022-07-26 01:27:43 +00:00
|
|
|
Contract,
|
2022-04-18 23:02:40 +00:00
|
|
|
FreeResponseContract,
|
2022-07-28 02:40:33 +00:00
|
|
|
MultipleChoiceContract,
|
2022-05-19 17:42:03 +00:00
|
|
|
NumericContract,
|
2022-07-02 19:37:59 +00:00
|
|
|
PseudoNumericContract,
|
2022-05-09 13:04:36 +00:00
|
|
|
} from 'common/contract'
|
2022-04-18 23:02:40 +00:00
|
|
|
import {
|
2022-04-19 02:44:31 +00:00
|
|
|
AnswerLabel,
|
2022-04-18 23:02:40 +00:00
|
|
|
BinaryContractOutcomeLabel,
|
2022-05-26 14:39:06 +00:00
|
|
|
CancelLabel,
|
2022-04-18 23:02:40 +00:00
|
|
|
FreeResponseOutcomeLabel,
|
|
|
|
} from '../outcome-label'
|
2022-07-02 19:37:59 +00:00
|
|
|
import {
|
|
|
|
getOutcomeProbability,
|
|
|
|
getProbability,
|
|
|
|
getTopAnswer,
|
|
|
|
} from 'common/calculate'
|
2022-06-23 17:12:57 +00:00
|
|
|
import { AvatarDetails, MiscDetails, ShowTime } from './contract-details'
|
2022-05-19 17:42:03 +00:00
|
|
|
import { getExpectedValue, getValueFromBucket } from 'common/calculate-dpm'
|
2022-09-11 02:57:50 +00:00
|
|
|
import { getColor, ProbBar, QuickBet } from './quick-bet'
|
2022-05-24 06:44:16 +00:00
|
|
|
import { useContractWithPreload } from 'web/hooks/use-contract'
|
2022-05-28 20:36:16 +00:00
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { track } from '@amplitude/analytics-browser'
|
|
|
|
import { trackCallback } from 'web/lib/service/analytics'
|
2022-08-02 23:24:59 +00:00
|
|
|
import { getMappedValue } from 'common/pseudo-numeric'
|
2022-08-12 19:04:23 +00:00
|
|
|
import { Tooltip } from '../tooltip'
|
2022-01-02 19:09:01 +00:00
|
|
|
|
2022-01-09 21:21:30 +00:00
|
|
|
export function ContractCard(props: {
|
|
|
|
contract: Contract
|
2022-06-23 17:12:57 +00:00
|
|
|
showTime?: ShowTime
|
2022-01-14 06:55:35 +00:00
|
|
|
className?: string
|
2022-08-26 17:31:25 +00:00
|
|
|
questionClass?: string
|
2022-06-05 00:00:13 +00:00
|
|
|
onClick?: () => void
|
2022-06-22 16:35:50 +00:00
|
|
|
hideQuickBet?: boolean
|
2022-07-26 01:27:43 +00:00
|
|
|
hideGroupLink?: boolean
|
2022-08-29 05:15:21 +00:00
|
|
|
trackingPostfix?: string
|
2022-01-09 21:21:30 +00:00
|
|
|
}) {
|
2022-07-26 01:27:43 +00:00
|
|
|
const {
|
|
|
|
showTime,
|
|
|
|
className,
|
2022-08-26 17:31:25 +00:00
|
|
|
questionClass,
|
2022-07-26 01:27:43 +00:00
|
|
|
onClick,
|
|
|
|
hideQuickBet,
|
|
|
|
hideGroupLink,
|
2022-08-29 05:15:21 +00:00
|
|
|
trackingPostfix,
|
2022-07-26 01:27:43 +00:00
|
|
|
} = props
|
2022-05-24 06:44:16 +00:00
|
|
|
const contract = useContractWithPreload(props.contract) ?? props.contract
|
2022-05-16 23:15:22 +00:00
|
|
|
const { question, outcomeType } = contract
|
2022-05-25 13:13:33 +00:00
|
|
|
const { resolution } = contract
|
2022-01-02 19:09:01 +00:00
|
|
|
|
2022-05-28 20:36:16 +00:00
|
|
|
const user = useUser()
|
|
|
|
|
|
|
|
const marketClosed =
|
|
|
|
(contract.closeTime || Infinity) < Date.now() || !!resolution
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
const showQuickBet =
|
|
|
|
user &&
|
|
|
|
!marketClosed &&
|
2022-07-10 18:05:44 +00:00
|
|
|
(outcomeType === 'BINARY' || outcomeType === 'PSEUDO_NUMERIC') &&
|
2022-06-22 16:35:50 +00:00
|
|
|
!hideQuickBet
|
2022-05-12 23:28:21 +00:00
|
|
|
|
2022-01-02 19:09:01 +00:00
|
|
|
return (
|
2022-08-14 08:05:17 +00:00
|
|
|
<Row
|
|
|
|
className={clsx(
|
2022-08-26 23:17:15 +00:00
|
|
|
'group relative gap-3 rounded-lg bg-white shadow-md hover:cursor-pointer hover:bg-gray-100',
|
2022-08-14 08:05:17 +00:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
2022-08-26 23:17:15 +00:00
|
|
|
<Col className="relative flex-1 gap-3 py-4 pb-12 pl-6">
|
2022-08-15 19:49:33 +00:00
|
|
|
<AvatarDetails
|
|
|
|
contract={contract}
|
2022-08-27 05:59:00 +00:00
|
|
|
className={'hidden md:inline-flex'}
|
2022-08-15 19:49:33 +00:00
|
|
|
/>
|
2022-08-14 08:05:17 +00:00
|
|
|
<p
|
2022-08-26 17:31:25 +00:00
|
|
|
className={clsx(
|
2022-08-26 21:23:06 +00:00
|
|
|
'break-anywhere font-semibold text-indigo-700 group-hover:underline group-hover:decoration-indigo-400 group-hover:decoration-2',
|
2022-08-26 17:31:25 +00:00
|
|
|
questionClass
|
|
|
|
)}
|
2022-08-14 08:05:17 +00:00
|
|
|
>
|
|
|
|
{question}
|
|
|
|
</p>
|
2022-05-24 06:44:16 +00:00
|
|
|
|
2022-08-14 08:05:17 +00:00
|
|
|
{(outcomeType === 'FREE_RESPONSE' ||
|
|
|
|
outcomeType === 'MULTIPLE_CHOICE') &&
|
|
|
|
(resolution ? (
|
|
|
|
<FreeResponseOutcomeLabel
|
2022-05-24 06:44:16 +00:00
|
|
|
contract={contract}
|
2022-08-14 08:05:17 +00:00
|
|
|
resolution={resolution}
|
|
|
|
truncate={'long'}
|
2022-05-19 17:42:03 +00:00
|
|
|
/>
|
2022-05-24 06:44:16 +00:00
|
|
|
) : (
|
2022-08-20 20:05:33 +00:00
|
|
|
<FreeResponseTopAnswer contract={contract} />
|
2022-08-14 08:05:17 +00:00
|
|
|
))}
|
|
|
|
</Col>
|
|
|
|
{showQuickBet ? (
|
2022-09-11 02:57:50 +00:00
|
|
|
<QuickBet contract={contract} user={user} className="z-10" />
|
2022-08-14 08:05:17 +00:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{outcomeType === 'BINARY' && (
|
|
|
|
<BinaryResolutionOrChance
|
|
|
|
className="items-center self-center pr-5"
|
|
|
|
contract={contract}
|
|
|
|
/>
|
|
|
|
)}
|
2022-05-24 23:38:43 +00:00
|
|
|
|
2022-08-14 08:05:17 +00:00
|
|
|
{outcomeType === 'PSEUDO_NUMERIC' && (
|
|
|
|
<PseudoNumericResolutionOrExpectation
|
|
|
|
className="items-center self-center pr-5"
|
|
|
|
contract={contract}
|
|
|
|
/>
|
|
|
|
)}
|
2022-07-02 19:37:59 +00:00
|
|
|
|
2022-08-14 08:05:17 +00:00
|
|
|
{outcomeType === 'NUMERIC' && (
|
|
|
|
<NumericResolutionOrExpectation
|
|
|
|
className="items-center self-center pr-5"
|
|
|
|
contract={contract}
|
|
|
|
/>
|
|
|
|
)}
|
2022-05-24 23:38:43 +00:00
|
|
|
|
2022-08-14 08:05:17 +00:00
|
|
|
{(outcomeType === 'FREE_RESPONSE' ||
|
|
|
|
outcomeType === 'MULTIPLE_CHOICE') && (
|
|
|
|
<FreeResponseResolutionOrChance
|
|
|
|
className="items-center self-center pr-5 text-gray-600"
|
|
|
|
contract={contract}
|
|
|
|
truncate="long"
|
|
|
|
/>
|
2022-05-19 17:42:03 +00:00
|
|
|
)}
|
2022-08-14 08:05:17 +00:00
|
|
|
<ProbBar contract={contract} />
|
|
|
|
</>
|
|
|
|
)}
|
2022-08-16 22:03:55 +00:00
|
|
|
<Row
|
|
|
|
className={clsx(
|
|
|
|
'absolute bottom-3 gap-2 truncate px-5 md:gap-0',
|
|
|
|
showQuickBet ? 'w-[85%]' : 'w-full'
|
|
|
|
)}
|
|
|
|
>
|
2022-08-26 17:31:25 +00:00
|
|
|
<AvatarDetails contract={contract} short={true} className="md:hidden" />
|
2022-08-16 22:03:55 +00:00
|
|
|
<MiscDetails
|
|
|
|
contract={contract}
|
|
|
|
showTime={showTime}
|
|
|
|
hideGroupLink={hideGroupLink}
|
|
|
|
/>
|
|
|
|
</Row>
|
2022-08-26 23:17:15 +00:00
|
|
|
|
|
|
|
{/* Add click layer */}
|
|
|
|
{onClick ? (
|
|
|
|
<a
|
|
|
|
className="absolute top-0 left-0 right-0 bottom-0"
|
|
|
|
href={contractPath(contract)}
|
|
|
|
onClick={(e) => {
|
|
|
|
// Let the browser handle the link click (opens in new tab).
|
|
|
|
if (e.ctrlKey || e.metaKey) return
|
|
|
|
|
|
|
|
e.preventDefault()
|
2022-08-29 05:15:21 +00:00
|
|
|
track('click market card' + (trackingPostfix ?? ''), {
|
2022-08-26 23:17:15 +00:00
|
|
|
slug: contract.slug,
|
|
|
|
contractId: contract.id,
|
|
|
|
})
|
|
|
|
onClick()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<Link href={contractPath(contract)}>
|
|
|
|
<a
|
2022-08-29 05:15:21 +00:00
|
|
|
onClick={trackCallback(
|
|
|
|
'click market card' + (trackingPostfix ?? ''),
|
|
|
|
{
|
|
|
|
slug: contract.slug,
|
|
|
|
contractId: contract.id,
|
|
|
|
}
|
|
|
|
)}
|
2022-08-26 23:17:15 +00:00
|
|
|
className="absolute top-0 left-0 right-0 bottom-0"
|
|
|
|
/>
|
|
|
|
</Link>
|
|
|
|
)}
|
2022-08-14 08:05:17 +00:00
|
|
|
</Row>
|
2022-01-02 19:09:01 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-18 23:02:40 +00:00
|
|
|
export function BinaryResolutionOrChance(props: {
|
2022-06-01 02:42:35 +00:00
|
|
|
contract: BinaryContract
|
2022-01-02 20:53:42 +00:00
|
|
|
large?: boolean
|
|
|
|
className?: string
|
2022-08-19 17:07:48 +00:00
|
|
|
probAfter?: number // 0 to 1
|
2022-01-02 20:53:42 +00:00
|
|
|
}) {
|
2022-08-19 17:07:48 +00:00
|
|
|
const { contract, large, className, probAfter } = props
|
2022-04-18 23:02:40 +00:00
|
|
|
const { resolution } = contract
|
2022-05-16 23:15:22 +00:00
|
|
|
const textColor = `text-${getColor(contract)}`
|
2022-02-14 21:33:47 +00:00
|
|
|
|
2022-08-19 17:07:48 +00:00
|
|
|
const before = getBinaryProbPercent(contract)
|
|
|
|
const after = probAfter && formatPercent(probAfter)
|
|
|
|
const probChanged = before !== after
|
|
|
|
|
2022-01-02 20:53:42 +00:00
|
|
|
return (
|
|
|
|
<Col className={clsx(large ? 'text-4xl' : 'text-3xl', className)}>
|
|
|
|
{resolution ? (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
className={clsx('text-gray-500', large ? 'text-xl' : 'text-base')}
|
|
|
|
>
|
|
|
|
Resolved
|
|
|
|
</div>
|
2022-04-18 23:02:40 +00:00
|
|
|
<BinaryContractOutcomeLabel
|
|
|
|
contract={contract}
|
|
|
|
resolution={resolution}
|
|
|
|
/>
|
2022-01-02 20:53:42 +00:00
|
|
|
</>
|
|
|
|
) : (
|
2022-04-18 23:02:40 +00:00
|
|
|
<>
|
2022-08-19 17:07:48 +00:00
|
|
|
{probAfter && probChanged ? (
|
|
|
|
<div>
|
|
|
|
<span className="text-gray-500 line-through">{before}</span>
|
|
|
|
<span className={textColor}>{after}</span>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className={textColor}>{before}</div>
|
|
|
|
)}
|
2022-05-24 23:38:43 +00:00
|
|
|
<div className={clsx(textColor, large ? 'text-xl' : 'text-base')}>
|
|
|
|
chance
|
|
|
|
</div>
|
2022-04-18 23:02:40 +00:00
|
|
|
</>
|
2022-01-02 20:53:42 +00:00
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-24 06:44:16 +00:00
|
|
|
function FreeResponseTopAnswer(props: {
|
2022-07-29 16:20:21 +00:00
|
|
|
contract: FreeResponseContract | MultipleChoiceContract
|
2022-05-24 06:44:16 +00:00
|
|
|
className?: string
|
|
|
|
}) {
|
2022-08-20 20:05:33 +00:00
|
|
|
const { contract } = props
|
2022-05-24 06:44:16 +00:00
|
|
|
|
|
|
|
const topAnswer = getTopAnswer(contract)
|
|
|
|
|
|
|
|
return topAnswer ? (
|
|
|
|
<AnswerLabel
|
|
|
|
className="!text-gray-600"
|
|
|
|
answer={topAnswer}
|
2022-08-20 20:05:33 +00:00
|
|
|
truncate="long"
|
2022-05-24 06:44:16 +00:00
|
|
|
/>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
|
2022-04-19 02:44:31 +00:00
|
|
|
export function FreeResponseResolutionOrChance(props: {
|
2022-07-28 02:40:33 +00:00
|
|
|
contract: FreeResponseContract | MultipleChoiceContract
|
2022-04-18 23:02:40 +00:00
|
|
|
truncate: 'short' | 'long' | 'none'
|
2022-04-20 03:31:41 +00:00
|
|
|
className?: string
|
2022-04-18 23:02:40 +00:00
|
|
|
}) {
|
2022-05-24 23:38:43 +00:00
|
|
|
const { contract, truncate, className } = props
|
2022-04-19 02:44:31 +00:00
|
|
|
const { resolution } = contract
|
|
|
|
|
|
|
|
const topAnswer = getTopAnswer(contract)
|
2022-05-16 23:15:22 +00:00
|
|
|
const textColor = `text-${getColor(contract)}`
|
2022-04-19 02:44:31 +00:00
|
|
|
|
2022-04-18 23:02:40 +00:00
|
|
|
return (
|
2022-04-20 03:31:41 +00:00
|
|
|
<Col className={clsx(resolution ? 'text-3xl' : 'text-xl', className)}>
|
2022-04-19 02:44:31 +00:00
|
|
|
{resolution ? (
|
|
|
|
<>
|
2022-05-25 13:13:33 +00:00
|
|
|
<div className={clsx('text-base text-gray-500 sm:hidden')}>
|
|
|
|
Resolved
|
|
|
|
</div>
|
|
|
|
{(resolution === 'CANCEL' || resolution === 'MKT') && (
|
|
|
|
<FreeResponseOutcomeLabel
|
|
|
|
contract={contract}
|
|
|
|
resolution={resolution}
|
|
|
|
truncate={truncate}
|
|
|
|
answerClassName="text-3xl uppercase text-blue-500"
|
|
|
|
/>
|
|
|
|
)}
|
2022-04-19 02:44:31 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
topAnswer && (
|
2022-04-20 03:31:41 +00:00
|
|
|
<Row className="items-center gap-6">
|
2022-05-16 23:15:22 +00:00
|
|
|
<Col className={clsx('text-3xl', textColor)}>
|
2022-04-19 02:44:31 +00:00
|
|
|
<div>
|
|
|
|
{formatPercent(getOutcomeProbability(contract, topAnswer.id))}
|
|
|
|
</div>
|
2022-05-24 23:38:43 +00:00
|
|
|
<div className="text-base">chance</div>
|
2022-04-19 02:44:31 +00:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
)}
|
2022-04-18 23:02:40 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
2022-05-19 17:42:03 +00:00
|
|
|
|
|
|
|
export function NumericResolutionOrExpectation(props: {
|
|
|
|
contract: NumericContract
|
|
|
|
className?: string
|
|
|
|
}) {
|
2022-05-24 23:38:43 +00:00
|
|
|
const { contract, className } = props
|
2022-05-19 17:42:03 +00:00
|
|
|
const { resolution } = contract
|
2022-05-24 06:44:16 +00:00
|
|
|
const textColor = `text-${getColor(contract)}`
|
2022-05-19 17:42:03 +00:00
|
|
|
|
|
|
|
const resolutionValue =
|
|
|
|
contract.resolutionValue ?? getValueFromBucket(resolution ?? '', contract)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col className={clsx(resolution ? 'text-3xl' : 'text-xl', className)}>
|
|
|
|
{resolution ? (
|
|
|
|
<>
|
|
|
|
<div className={clsx('text-base text-gray-500')}>Resolved</div>
|
2022-05-26 14:39:06 +00:00
|
|
|
|
|
|
|
{resolution === 'CANCEL' ? (
|
|
|
|
<CancelLabel />
|
|
|
|
) : (
|
2022-07-02 19:37:59 +00:00
|
|
|
<div className="text-blue-400">
|
|
|
|
{formatLargeNumber(resolutionValue)}
|
|
|
|
</div>
|
2022-05-26 14:39:06 +00:00
|
|
|
)}
|
2022-05-19 17:42:03 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
2022-05-24 06:44:16 +00:00
|
|
|
<div className={clsx('text-3xl', textColor)}>
|
2022-05-20 19:25:32 +00:00
|
|
|
{formatLargeNumber(getExpectedValue(contract))}
|
2022-05-19 17:42:03 +00:00
|
|
|
</div>
|
2022-05-24 23:38:43 +00:00
|
|
|
<div className={clsx('text-base', textColor)}>expected</div>
|
2022-05-19 17:42:03 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
2022-07-02 19:37:59 +00:00
|
|
|
|
|
|
|
export function PseudoNumericResolutionOrExpectation(props: {
|
|
|
|
contract: PseudoNumericContract
|
|
|
|
className?: string
|
|
|
|
}) {
|
|
|
|
const { contract, className } = props
|
|
|
|
const { resolution, resolutionValue, resolutionProbability } = contract
|
|
|
|
const textColor = `text-blue-400`
|
|
|
|
|
2022-08-02 21:59:47 +00:00
|
|
|
const value = resolution
|
|
|
|
? resolutionValue
|
|
|
|
? resolutionValue
|
|
|
|
: getMappedValue(contract)(resolutionProbability ?? 0)
|
|
|
|
: getMappedValue(contract)(getProbability(contract))
|
|
|
|
|
2022-07-02 19:37:59 +00:00
|
|
|
return (
|
|
|
|
<Col className={clsx(resolution ? 'text-3xl' : 'text-xl', className)}>
|
|
|
|
{resolution ? (
|
|
|
|
<>
|
|
|
|
<div className={clsx('text-base text-gray-500')}>Resolved</div>
|
|
|
|
|
|
|
|
{resolution === 'CANCEL' ? (
|
|
|
|
<CancelLabel />
|
|
|
|
) : (
|
2022-08-12 19:04:23 +00:00
|
|
|
<Tooltip className={textColor} text={value.toFixed(2)}>
|
2022-08-02 21:59:47 +00:00
|
|
|
{formatLargeNumber(value)}
|
2022-08-12 19:04:23 +00:00
|
|
|
</Tooltip>
|
2022-07-02 19:37:59 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
2022-08-12 19:04:23 +00:00
|
|
|
<Tooltip
|
|
|
|
className={clsx('text-3xl', textColor)}
|
|
|
|
text={value.toFixed(2)}
|
2022-08-02 21:59:47 +00:00
|
|
|
>
|
|
|
|
{formatLargeNumber(value)}
|
2022-08-12 19:04:23 +00:00
|
|
|
</Tooltip>
|
2022-07-02 19:37:59 +00:00
|
|
|
<div className={clsx('text-base', textColor)}>expected</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|