2022-01-02 19:09:01 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import { Row } from '../components/layout/row'
|
2022-01-30 21:51:30 +00:00
|
|
|
import { formatMoney } from '../../common/util/format'
|
2022-01-02 19:09:01 +00:00
|
|
|
import { UserLink } from './user-page'
|
2022-01-12 19:01:04 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
|
|
|
contractMetrics,
|
|
|
|
contractPath,
|
|
|
|
} from '../lib/firebase/contracts'
|
2022-01-02 20:53:42 +00:00
|
|
|
import { Col } from './layout/col'
|
2022-01-05 17:49:20 +00:00
|
|
|
import dayjs from 'dayjs'
|
2022-01-24 07:38:29 +00:00
|
|
|
import { TrendingUpIcon } from '@heroicons/react/solid'
|
2022-01-16 09:16:15 +00:00
|
|
|
import { DateTimeTooltip } from './datetime-tooltip'
|
2022-01-24 07:38:29 +00:00
|
|
|
import { ClockIcon } from '@heroicons/react/outline'
|
|
|
|
import { fromNow } from '../lib/util/time'
|
2022-02-04 18:30:56 +00:00
|
|
|
import { Avatar } from './avatar'
|
|
|
|
import { Spacer } from './layout/spacer'
|
2022-01-02 19:09:01 +00:00
|
|
|
|
2022-01-09 21:21:30 +00:00
|
|
|
export function ContractCard(props: {
|
|
|
|
contract: Contract
|
|
|
|
showHotVolume?: boolean
|
2022-01-17 22:54:00 +00:00
|
|
|
showCloseTime?: boolean
|
2022-01-14 06:55:35 +00:00
|
|
|
className?: string
|
2022-01-09 21:21:30 +00:00
|
|
|
}) {
|
2022-01-17 22:54:00 +00:00
|
|
|
const { contract, showHotVolume, showCloseTime, className } = props
|
2022-01-04 22:09:03 +00:00
|
|
|
const { question, resolution } = contract
|
2022-01-12 19:01:04 +00:00
|
|
|
const { probPercent } = contractMetrics(contract)
|
2022-01-02 19:09:01 +00:00
|
|
|
|
|
|
|
return (
|
2022-01-18 22:55:39 +00:00
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2022-02-11 18:40:22 +00:00
|
|
|
'relative rounded-lg bg-white p-6 shadow-md hover:bg-gray-100',
|
2022-01-18 22:55:39 +00:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Link href={contractPath(contract)}>
|
|
|
|
<a className="absolute left-0 right-0 top-0 bottom-0" />
|
|
|
|
</Link>
|
2022-02-04 18:30:56 +00:00
|
|
|
|
|
|
|
<AbbrContractDetails
|
|
|
|
contract={contract}
|
|
|
|
showHotVolume={showHotVolume}
|
|
|
|
showCloseTime={showCloseTime}
|
|
|
|
/>
|
|
|
|
<Spacer h={3} />
|
|
|
|
|
|
|
|
<Row className="justify-between gap-4">
|
2022-02-15 02:27:43 +00:00
|
|
|
<p
|
|
|
|
className="font-medium text-indigo-700 break-words"
|
|
|
|
style={{ /* For iOS safari */ wordBreak: 'break-word' }}
|
|
|
|
>
|
|
|
|
{question}
|
|
|
|
</p>
|
2022-02-14 21:33:47 +00:00
|
|
|
<ResolutionOrChance className="items-center" contract={contract} />
|
2022-01-18 22:55:39 +00:00
|
|
|
</Row>
|
|
|
|
</div>
|
2022-01-14 22:59:14 +00:00
|
|
|
</div>
|
2022-01-02 19:09:01 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-02 20:53:42 +00:00
|
|
|
export function ResolutionOrChance(props: {
|
2022-02-14 21:33:47 +00:00
|
|
|
contract: Contract
|
2022-01-02 20:53:42 +00:00
|
|
|
large?: boolean
|
|
|
|
className?: string
|
|
|
|
}) {
|
2022-02-14 21:33:47 +00:00
|
|
|
const { contract, large, className } = props
|
|
|
|
const { resolution } = contract
|
|
|
|
const { probPercent } = contractMetrics(contract)
|
|
|
|
const marketClosed = (contract.closeTime || Infinity) < Date.now()
|
2022-01-02 20:53:42 +00:00
|
|
|
|
|
|
|
const resolutionColor = {
|
|
|
|
YES: 'text-primary',
|
|
|
|
NO: 'text-red-400',
|
|
|
|
MKT: 'text-blue-400',
|
|
|
|
CANCEL: 'text-yellow-400',
|
|
|
|
'': '', // Empty if unresolved
|
|
|
|
}[resolution || '']
|
|
|
|
|
2022-02-14 21:33:47 +00:00
|
|
|
const probColor = marketClosed ? 'text-gray-400' : 'text-primary'
|
|
|
|
|
2022-01-02 20:53:42 +00:00
|
|
|
const resolutionText = {
|
|
|
|
YES: 'YES',
|
|
|
|
NO: 'NO',
|
2022-01-30 21:51:30 +00:00
|
|
|
MKT: probPercent,
|
2022-01-02 20:53:42 +00:00
|
|
|
CANCEL: 'N/A',
|
|
|
|
'': '',
|
|
|
|
}[resolution || '']
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col className={clsx(large ? 'text-4xl' : 'text-3xl', className)}>
|
|
|
|
{resolution ? (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
className={clsx('text-gray-500', large ? 'text-xl' : 'text-base')}
|
|
|
|
>
|
|
|
|
Resolved
|
|
|
|
</div>
|
|
|
|
<div className={resolutionColor}>{resolutionText}</div>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
2022-02-14 21:33:47 +00:00
|
|
|
<div className={probColor}>{probPercent}</div>
|
|
|
|
<div className={clsx(probColor, large ? 'text-xl' : 'text-base')}>
|
2022-01-02 20:53:42 +00:00
|
|
|
chance
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-04 18:30:56 +00:00
|
|
|
function AbbrContractDetails(props: {
|
2022-01-09 21:21:30 +00:00
|
|
|
contract: Contract
|
|
|
|
showHotVolume?: boolean
|
2022-01-17 22:54:00 +00:00
|
|
|
showCloseTime?: boolean
|
2022-01-09 21:21:30 +00:00
|
|
|
}) {
|
2022-01-17 22:54:00 +00:00
|
|
|
const { contract, showHotVolume, showCloseTime } = props
|
|
|
|
const { volume24Hours, creatorName, creatorUsername, closeTime } = contract
|
2022-01-12 19:01:04 +00:00
|
|
|
const { truePool } = contractMetrics(contract)
|
2022-01-05 07:06:30 +00:00
|
|
|
|
|
|
|
return (
|
2022-02-11 18:40:22 +00:00
|
|
|
<Col className={clsx('gap-2 text-sm text-gray-500')}>
|
|
|
|
<Row className="items-center justify-between">
|
|
|
|
<Row className="items-center gap-2">
|
2022-02-04 18:30:56 +00:00
|
|
|
<Avatar
|
|
|
|
username={creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
size={6}
|
|
|
|
/>
|
|
|
|
<UserLink
|
|
|
|
className="whitespace-nowrap"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
|
2022-01-09 21:21:30 +00:00
|
|
|
{showHotVolume ? (
|
|
|
|
<div className="whitespace-nowrap">
|
2022-02-11 18:40:22 +00:00
|
|
|
<TrendingUpIcon className="inline h-5 w-5 text-gray-500" />{' '}
|
2022-01-12 17:51:46 +00:00
|
|
|
{formatMoney(volume24Hours)}
|
2022-01-09 21:21:30 +00:00
|
|
|
</div>
|
2022-01-17 22:54:00 +00:00
|
|
|
) : showCloseTime ? (
|
|
|
|
<div className="whitespace-nowrap">
|
2022-02-11 18:40:22 +00:00
|
|
|
<ClockIcon className="-my-1 inline h-5 w-5 text-gray-500" /> Closes{' '}
|
2022-01-24 07:38:29 +00:00
|
|
|
{fromNow(closeTime || 0)}
|
2022-01-17 22:54:00 +00:00
|
|
|
</div>
|
2022-01-09 21:21:30 +00:00
|
|
|
) : (
|
|
|
|
<div className="whitespace-nowrap">{formatMoney(truePool)} pool</div>
|
|
|
|
)}
|
2022-01-05 07:06:30 +00:00
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ContractDetails(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
2022-01-31 03:25:50 +00:00
|
|
|
const { closeTime, creatorName, creatorUsername } = contract
|
2022-01-12 19:01:04 +00:00
|
|
|
const { truePool, createdDate, resolvedDate } = contractMetrics(contract)
|
2022-01-02 19:09:01 +00:00
|
|
|
|
|
|
|
return (
|
2022-02-11 18:40:22 +00:00
|
|
|
<Col className="gap-2 text-sm text-gray-500 sm:flex-row sm:flex-wrap">
|
|
|
|
<Row className="flex-wrap items-center gap-2">
|
2022-02-06 07:02:52 +00:00
|
|
|
<Avatar
|
|
|
|
username={creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
size={6}
|
|
|
|
/>
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="whitespace-nowrap"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>
|
2022-01-04 22:09:03 +00:00
|
|
|
<div className="">•</div>
|
2022-01-19 22:01:54 +00:00
|
|
|
|
2022-01-04 22:09:03 +00:00
|
|
|
<div className="whitespace-nowrap">
|
2022-01-19 22:01:54 +00:00
|
|
|
<DateTimeTooltip text="Market created:" time={contract.createdTime}>
|
2022-01-16 09:16:15 +00:00
|
|
|
{createdDate}
|
|
|
|
</DateTimeTooltip>
|
2022-01-19 22:01:54 +00:00
|
|
|
|
2022-01-16 09:16:15 +00:00
|
|
|
{resolvedDate && contract.resolutionTime ? (
|
|
|
|
<>
|
|
|
|
{' - '}
|
2022-01-19 22:01:54 +00:00
|
|
|
<DateTimeTooltip
|
|
|
|
text="Market resolved:"
|
|
|
|
time={contract.resolutionTime}
|
|
|
|
>
|
2022-01-16 09:16:15 +00:00
|
|
|
{resolvedDate}
|
|
|
|
</DateTimeTooltip>
|
|
|
|
</>
|
|
|
|
) : null}
|
2022-01-19 22:01:54 +00:00
|
|
|
|
|
|
|
{!resolvedDate && closeTime && (
|
|
|
|
<>
|
|
|
|
{' - '}
|
|
|
|
<DateTimeTooltip
|
|
|
|
text={
|
2022-01-19 22:07:58 +00:00
|
|
|
closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'
|
2022-01-19 22:01:54 +00:00
|
|
|
}
|
|
|
|
time={closeTime}
|
|
|
|
>
|
2022-01-16 09:16:15 +00:00
|
|
|
{dayjs(closeTime).format('MMM D, YYYY')}
|
|
|
|
</DateTimeTooltip>
|
2022-01-19 22:01:54 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
2022-01-04 22:09:03 +00:00
|
|
|
<div className="">•</div>
|
|
|
|
<div className="whitespace-nowrap">{formatMoney(truePool)} pool</div>
|
|
|
|
</Row>
|
|
|
|
</Col>
|
2022-01-02 19:09:01 +00:00
|
|
|
)
|
|
|
|
}
|
2022-01-10 07:05:24 +00:00
|
|
|
|
|
|
|
// String version of the above, to send to the OpenGraph image generator
|
|
|
|
export function contractTextDetails(contract: Contract) {
|
2022-01-31 03:25:50 +00:00
|
|
|
const { closeTime, tags } = contract
|
2022-01-12 19:01:04 +00:00
|
|
|
const { truePool, createdDate, resolvedDate } = contractMetrics(contract)
|
2022-01-10 07:05:24 +00:00
|
|
|
|
2022-01-31 03:25:50 +00:00
|
|
|
const hashtags = tags.map((tag) => `#${tag}`)
|
2022-01-10 07:05:24 +00:00
|
|
|
|
|
|
|
return (
|
2022-01-10 07:09:39 +00:00
|
|
|
`${resolvedDate ? `${createdDate} - ${resolvedDate}` : createdDate}` +
|
2022-01-10 07:05:24 +00:00
|
|
|
(closeTime
|
|
|
|
? ` • ${closeTime > Date.now() ? 'Closes' : 'Closed'} ${dayjs(
|
|
|
|
closeTime
|
|
|
|
).format('MMM D, h:mma')}`
|
|
|
|
: '') +
|
|
|
|
` • ${formatMoney(truePool)} pool` +
|
2022-01-31 03:25:50 +00:00
|
|
|
(hashtags.length > 0 ? ` • ${hashtags.join(' ')}` : '')
|
2022-01-10 07:05:24 +00:00
|
|
|
)
|
|
|
|
}
|