2022-01-02 19:09:01 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import Link from 'next/link'
|
2022-02-21 04:04:00 +00:00
|
|
|
import { ClockIcon, DatabaseIcon, PencilIcon } from '@heroicons/react/outline'
|
|
|
|
import { TrendingUpIcon } from '@heroicons/react/solid'
|
2022-01-02 19:09:01 +00:00
|
|
|
import { Row } from '../components/layout/row'
|
2022-03-16 02:46:07 +00:00
|
|
|
import { formatMoney, formatPercent } 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,
|
2022-02-17 23:00:19 +00:00
|
|
|
getBinaryProbPercent,
|
2022-02-21 04:04:00 +00:00
|
|
|
updateContract,
|
2022-01-12 19:01:04 +00:00
|
|
|
} 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-16 09:16:15 +00:00
|
|
|
import { DateTimeTooltip } from './datetime-tooltip'
|
2022-01-24 07:38:29 +00:00
|
|
|
import { fromNow } from '../lib/util/time'
|
2022-02-04 18:30:56 +00:00
|
|
|
import { Avatar } from './avatar'
|
|
|
|
import { Spacer } from './layout/spacer'
|
2022-02-21 04:04:00 +00:00
|
|
|
import { useState } from 'react'
|
2022-02-23 03:38:53 +00:00
|
|
|
import { TweetButton } from './tweet-button'
|
2022-03-16 02:46:07 +00:00
|
|
|
import { getProbability } from '../../common/calculate'
|
2022-03-21 20:23:21 +00:00
|
|
|
import { ShareEmbedButton } from './share-embed-button'
|
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-02-17 23:00:19 +00:00
|
|
|
const { question } = 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
|
2022-02-18 02:24:10 +00:00
|
|
|
className="break-words font-medium text-indigo-700"
|
2022-02-15 02:27:43 +00:00
|
|
|
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
|
2022-02-17 23:00:19 +00:00
|
|
|
const { resolution, outcomeType } = contract
|
|
|
|
const isBinary = outcomeType === 'BINARY'
|
2022-02-14 21:33:47 +00:00
|
|
|
const marketClosed = (contract.closeTime || Infinity) < Date.now()
|
2022-01-02 20:53:42 +00:00
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const resolutionColor =
|
|
|
|
{
|
|
|
|
YES: 'text-primary',
|
|
|
|
NO: 'text-red-400',
|
|
|
|
MKT: 'text-blue-400',
|
|
|
|
CANCEL: 'text-yellow-400',
|
|
|
|
'': '', // Empty if unresolved
|
|
|
|
}[resolution || ''] ?? 'text-primary'
|
2022-01-02 20:53:42 +00:00
|
|
|
|
2022-02-14 21:33:47 +00:00
|
|
|
const probColor = marketClosed ? 'text-gray-400' : 'text-primary'
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const resolutionText =
|
|
|
|
{
|
|
|
|
YES: 'YES',
|
|
|
|
NO: 'NO',
|
2022-03-16 02:46:07 +00:00
|
|
|
MKT: isBinary
|
|
|
|
? formatPercent(
|
|
|
|
contract.resolutionProbability ?? getProbability(contract)
|
|
|
|
)
|
|
|
|
: 'MULTI',
|
2022-02-17 23:00:19 +00:00
|
|
|
CANCEL: 'N/A',
|
|
|
|
'': '',
|
|
|
|
}[resolution || ''] ?? `#${resolution}`
|
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>
|
|
|
|
<div className={resolutionColor}>{resolutionText}</div>
|
|
|
|
</>
|
|
|
|
) : (
|
2022-02-17 23:00:19 +00:00
|
|
|
isBinary && (
|
|
|
|
<>
|
|
|
|
<div className={probColor}>{getBinaryProbPercent(contract)}</div>
|
|
|
|
<div className={clsx(probColor, large ? 'text-xl' : 'text-base')}>
|
|
|
|
chance
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
2022-01-02 20:53:42 +00:00
|
|
|
)}
|
|
|
|
</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-03-15 22:27:51 +00:00
|
|
|
const { liquidityLabel } = 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 ? (
|
2022-02-18 02:24:10 +00:00
|
|
|
<Row className="gap-1">
|
|
|
|
<TrendingUpIcon className="h-5 w-5" /> {formatMoney(volume24Hours)}
|
|
|
|
</Row>
|
2022-01-17 22:54:00 +00:00
|
|
|
) : showCloseTime ? (
|
2022-02-18 02:24:10 +00:00
|
|
|
<Row className="gap-1">
|
|
|
|
<ClockIcon className="h-5 w-5" />
|
2022-03-02 02:00:14 +00:00
|
|
|
{(closeTime || 0) < Date.now() ? 'Closed' : 'Closes'}{' '}
|
|
|
|
{fromNow(closeTime || 0)}
|
2022-02-18 02:24:10 +00:00
|
|
|
</Row>
|
2022-01-09 21:21:30 +00:00
|
|
|
) : (
|
2022-02-18 02:24:10 +00:00
|
|
|
<Row className="gap-1">
|
|
|
|
{/* <DatabaseIcon className="h-5 w-5" /> */}
|
2022-03-15 22:27:51 +00:00
|
|
|
{liquidityLabel}
|
2022-02-18 02:24:10 +00:00
|
|
|
</Row>
|
2022-01-09 21:21:30 +00:00
|
|
|
)}
|
2022-01-05 07:06:30 +00:00
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-21 04:04:00 +00:00
|
|
|
export function ContractDetails(props: {
|
|
|
|
contract: Contract
|
|
|
|
isCreator?: boolean
|
2022-03-21 20:23:21 +00:00
|
|
|
hideShareButtons?: boolean
|
2022-02-21 04:04:00 +00:00
|
|
|
}) {
|
2022-03-21 20:23:21 +00:00
|
|
|
const { contract, isCreator, hideShareButtons } = props
|
2022-01-31 03:25:50 +00:00
|
|
|
const { closeTime, creatorName, creatorUsername } = contract
|
2022-03-15 22:27:51 +00:00
|
|
|
const { liquidityLabel, createdDate, resolvedDate } =
|
|
|
|
contractMetrics(contract)
|
2022-01-02 19:09:01 +00:00
|
|
|
|
2022-02-23 03:38:53 +00:00
|
|
|
const tweetText = getTweetText(contract, !!isCreator)
|
|
|
|
|
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">
|
2022-03-21 21:19:08 +00:00
|
|
|
<Row className="flex-wrap items-center gap-x-4 gap-y-3">
|
2022-02-18 02:24:10 +00:00
|
|
|
<Row className="items-center gap-2">
|
|
|
|
<Avatar
|
|
|
|
username={creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
size={6}
|
|
|
|
/>
|
|
|
|
<UserLink
|
|
|
|
className="whitespace-nowrap"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
|
|
|
|
<Row className="items-center gap-1">
|
|
|
|
<ClockIcon className="h-5 w-5" />
|
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 && (
|
|
|
|
<>
|
2022-02-21 04:04:00 +00:00
|
|
|
{' - '}{' '}
|
|
|
|
<EditableCloseDate
|
|
|
|
closeTime={closeTime}
|
|
|
|
contract={contract}
|
|
|
|
isCreator={isCreator ?? false}
|
|
|
|
/>
|
2022-01-19 22:01:54 +00:00
|
|
|
</>
|
|
|
|
)}
|
2022-02-18 02:24:10 +00:00
|
|
|
</Row>
|
|
|
|
|
|
|
|
<Row className="items-center gap-1">
|
|
|
|
<DatabaseIcon className="h-5 w-5" />
|
2022-01-19 22:01:54 +00:00
|
|
|
|
2022-03-15 22:27:51 +00:00
|
|
|
<div className="whitespace-nowrap">{liquidityLabel}</div>
|
2022-02-18 02:24:10 +00:00
|
|
|
</Row>
|
2022-02-23 03:22:24 +00:00
|
|
|
|
2022-03-21 20:23:21 +00:00
|
|
|
{!hideShareButtons && (
|
|
|
|
<>
|
|
|
|
<TweetButton className="self-end" tweetText={tweetText} />
|
|
|
|
<ShareEmbedButton contract={contract} />
|
|
|
|
</>
|
2022-03-20 21:05:16 +00:00
|
|
|
)}
|
2022-01-04 22:09:03 +00:00
|
|
|
</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-03-15 22:27:51 +00:00
|
|
|
const { createdDate, resolvedDate, liquidityLabel } =
|
|
|
|
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')}`
|
|
|
|
: '') +
|
2022-03-15 22:27:51 +00:00
|
|
|
` • ${liquidityLabel}` +
|
2022-01-31 03:25:50 +00:00
|
|
|
(hashtags.length > 0 ? ` • ${hashtags.join(' ')}` : '')
|
2022-01-10 07:05:24 +00:00
|
|
|
)
|
|
|
|
}
|
2022-02-21 04:04:00 +00:00
|
|
|
|
|
|
|
function EditableCloseDate(props: {
|
|
|
|
closeTime: number
|
|
|
|
contract: Contract
|
|
|
|
isCreator: boolean
|
|
|
|
}) {
|
|
|
|
const { closeTime, contract, isCreator } = props
|
|
|
|
|
|
|
|
const [isEditingCloseTime, setIsEditingCloseTime] = useState(false)
|
|
|
|
const [closeDate, setCloseDate] = useState(
|
|
|
|
closeTime && dayjs(closeTime).format('YYYY-MM-DDT23:59')
|
|
|
|
)
|
|
|
|
|
|
|
|
const onSave = () => {
|
|
|
|
const newCloseTime = dayjs(closeDate).valueOf()
|
|
|
|
if (newCloseTime === closeTime) setIsEditingCloseTime(false)
|
|
|
|
else if (newCloseTime > Date.now()) {
|
|
|
|
const { description } = contract
|
|
|
|
const formattedCloseDate = dayjs(newCloseTime).format('YYYY-MM-DD h:mm a')
|
|
|
|
const newDescription = `${description}\n\nClose date updated to ${formattedCloseDate}`
|
|
|
|
|
|
|
|
updateContract(contract.id, {
|
|
|
|
closeTime: newCloseTime,
|
|
|
|
description: newDescription,
|
|
|
|
})
|
|
|
|
|
|
|
|
setIsEditingCloseTime(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{isEditingCloseTime ? (
|
|
|
|
<div className="form-control mr-1 items-start">
|
|
|
|
<input
|
|
|
|
type="datetime-local"
|
|
|
|
className="input input-bordered"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => setCloseDate(e.target.value || '')}
|
|
|
|
min={Date.now()}
|
|
|
|
value={closeDate}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<DateTimeTooltip
|
|
|
|
text={closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'}
|
|
|
|
time={closeTime}
|
|
|
|
>
|
|
|
|
{dayjs(closeTime).format('MMM D')} ({fromNow(closeTime)})
|
|
|
|
</DateTimeTooltip>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{isCreator &&
|
|
|
|
(isEditingCloseTime ? (
|
|
|
|
<button className="btn btn-xs" onClick={onSave}>
|
|
|
|
Done
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
className="btn btn-xs btn-ghost"
|
|
|
|
onClick={() => setIsEditingCloseTime(true)}
|
|
|
|
>
|
2022-03-02 02:00:14 +00:00
|
|
|
<PencilIcon className="mr-2 inline h-4 w-4" /> Edit
|
2022-02-21 04:04:00 +00:00
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-02-23 03:38:53 +00:00
|
|
|
|
|
|
|
const getTweetText = (contract: Contract, isCreator: boolean) => {
|
|
|
|
const { question, creatorName, resolution, outcomeType } = contract
|
|
|
|
const isBinary = outcomeType === 'BINARY'
|
|
|
|
|
|
|
|
const tweetQuestion = isCreator
|
|
|
|
? question
|
|
|
|
: `${question} Asked by ${creatorName}.`
|
|
|
|
const tweetDescription = resolution
|
|
|
|
? `Resolved ${resolution}!`
|
|
|
|
: isBinary
|
|
|
|
? `Currently ${getBinaryProbPercent(
|
|
|
|
contract
|
|
|
|
)} chance, place your bets here:`
|
|
|
|
: `Submit your own answer:`
|
2022-03-08 21:36:15 +00:00
|
|
|
|
|
|
|
const timeParam = `${Date.now()}`.substring(7)
|
|
|
|
const url = `https://manifold.markets${contractPath(contract)}?t=${timeParam}`
|
2022-02-23 03:38:53 +00:00
|
|
|
|
|
|
|
return `${tweetQuestion}\n\n${tweetDescription}\n\n${url}`
|
|
|
|
}
|