2022-01-04 07:21:14 +00:00
|
|
|
// From https://tailwindui.com/components/application-ui/lists/feeds
|
2022-03-17 07:29:08 +00:00
|
|
|
import { Fragment, useRef, useState } from 'react'
|
2022-03-15 22:27:51 +00:00
|
|
|
import * as _ from 'lodash'
|
2022-01-04 07:21:14 +00:00
|
|
|
import {
|
|
|
|
BanIcon,
|
|
|
|
CheckIcon,
|
2022-01-22 17:46:59 +00:00
|
|
|
DotsVerticalIcon,
|
2022-01-04 07:21:14 +00:00
|
|
|
LockClosedIcon,
|
|
|
|
UserIcon,
|
|
|
|
UsersIcon,
|
|
|
|
XIcon,
|
2022-04-20 22:25:29 +00:00
|
|
|
SparklesIcon,
|
2022-01-04 07:21:14 +00:00
|
|
|
} from '@heroicons/react/solid'
|
2022-01-27 23:14:18 +00:00
|
|
|
import clsx from 'clsx'
|
2022-02-17 23:00:19 +00:00
|
|
|
import Textarea from 'react-expanding-textarea'
|
2022-01-27 23:14:18 +00:00
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
import { OutcomeLabel } from '../outcome-label'
|
2022-01-11 16:56:26 +00:00
|
|
|
import {
|
2022-01-12 19:01:04 +00:00
|
|
|
contractMetrics,
|
2022-01-11 16:56:26 +00:00
|
|
|
Contract,
|
2022-01-12 19:01:04 +00:00
|
|
|
contractPath,
|
2022-01-26 20:08:03 +00:00
|
|
|
tradingAllowed,
|
2022-03-14 20:29:32 +00:00
|
|
|
} from '../../lib/firebase/contracts'
|
|
|
|
import { useUser } from '../../hooks/use-user'
|
|
|
|
import { Linkify } from '../linkify'
|
|
|
|
import { Row } from '../layout/row'
|
2022-03-17 02:55:03 +00:00
|
|
|
import { createComment, MAX_COMMENT_LENGTH } from '../../lib/firebase/comments'
|
2022-03-17 04:42:24 +00:00
|
|
|
import { formatMoney, formatPercent } from '../../../common/util/format'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { Comment } from '../../../common/comment'
|
2022-04-18 23:02:40 +00:00
|
|
|
import { BinaryResolutionOrChance } from '../contract/contract-card'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { SiteLink } from '../site-link'
|
|
|
|
import { Col } from '../layout/col'
|
|
|
|
import { UserLink } from '../user-page'
|
|
|
|
import { DateTimeTooltip } from '../datetime-tooltip'
|
|
|
|
import { Bet } from '../../lib/firebase/bets'
|
|
|
|
import { JoinSpans } from '../join-spans'
|
|
|
|
import { fromNow } from '../../lib/util/time'
|
2022-03-29 19:56:56 +00:00
|
|
|
import BetRow from '../bet-row'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { Avatar } from '../avatar'
|
|
|
|
import { Answer } from '../../../common/answer'
|
|
|
|
import { ActivityItem } from './activity-items'
|
2022-03-15 22:27:51 +00:00
|
|
|
import { FreeResponse, FullContract } from '../../../common/contract'
|
2022-03-17 04:42:24 +00:00
|
|
|
import { BuyButton } from '../yes-no-selector'
|
|
|
|
import { getDpmOutcomeProbability } from '../../../common/calculate-dpm'
|
|
|
|
import { AnswerBetPanel } from '../answers/answer-bet-panel'
|
2022-03-17 07:29:08 +00:00
|
|
|
import { useSaveSeenContract } from '../../hooks/use-seen-contracts'
|
2022-03-21 01:07:45 +00:00
|
|
|
import { User } from '../../../common/user'
|
2022-03-29 19:56:56 +00:00
|
|
|
import { Modal } from '../layout/modal'
|
2022-04-19 05:16:08 +00:00
|
|
|
import { trackClick } from '../../lib/firebase/tracking'
|
2022-04-20 22:25:29 +00:00
|
|
|
import { DAY_MS } from '../../../common/util/time'
|
2022-04-21 06:03:16 +00:00
|
|
|
import NewContractBadge from '../new-contract-badge'
|
2022-03-14 20:29:32 +00:00
|
|
|
|
|
|
|
export function FeedItems(props: {
|
|
|
|
contract: Contract
|
|
|
|
items: ActivityItem[]
|
2022-04-06 05:22:43 +00:00
|
|
|
className?: string
|
2022-03-14 20:29:32 +00:00
|
|
|
betRowClassName?: string
|
|
|
|
}) {
|
2022-04-19 05:16:08 +00:00
|
|
|
const { contract, items, className, betRowClassName } = props
|
2022-03-14 20:29:32 +00:00
|
|
|
const { outcomeType } = contract
|
|
|
|
|
2022-03-17 07:29:08 +00:00
|
|
|
const ref = useRef<HTMLDivElement | null>(null)
|
2022-04-19 05:16:08 +00:00
|
|
|
useSaveSeenContract(ref, contract)
|
2022-03-17 07:29:08 +00:00
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
return (
|
2022-04-06 05:22:43 +00:00
|
|
|
<div className={clsx('flow-root pr-2 md:pr-0', className)} ref={ref}>
|
2022-03-14 20:29:32 +00:00
|
|
|
<div className={clsx(tradingAllowed(contract) ? '' : '-mb-6')}>
|
|
|
|
{items.map((item, activityItemIdx) => (
|
|
|
|
<div key={item.id} className="relative pb-6">
|
|
|
|
{activityItemIdx !== items.length - 1 ||
|
|
|
|
item.type === 'answergroup' ? (
|
|
|
|
<span
|
|
|
|
className="absolute top-5 left-5 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<div className="relative flex items-start space-x-3">
|
|
|
|
<FeedItem item={item} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
{outcomeType === 'BINARY' && tradingAllowed(contract) && (
|
|
|
|
<BetRow contract={contract} className={clsx('mb-2', betRowClassName)} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedItem(props: { item: ActivityItem }) {
|
|
|
|
const { item } = props
|
|
|
|
|
|
|
|
switch (item.type) {
|
|
|
|
case 'question':
|
|
|
|
return <FeedQuestion {...item} />
|
|
|
|
case 'description':
|
|
|
|
return <FeedDescription {...item} />
|
|
|
|
case 'comment':
|
|
|
|
return <FeedComment {...item} />
|
|
|
|
case 'bet':
|
|
|
|
return <FeedBet {...item} />
|
|
|
|
case 'betgroup':
|
|
|
|
return <FeedBetGroup {...item} />
|
|
|
|
case 'answergroup':
|
|
|
|
return <FeedAnswerGroup {...item} />
|
|
|
|
case 'close':
|
|
|
|
return <FeedClose {...item} />
|
|
|
|
case 'resolve':
|
|
|
|
return <FeedResolve {...item} />
|
|
|
|
}
|
2022-03-10 06:29:36 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 01:07:45 +00:00
|
|
|
export function FeedComment(props: {
|
2022-03-14 20:29:32 +00:00
|
|
|
contract: Contract
|
|
|
|
comment: Comment
|
|
|
|
bet: Bet
|
|
|
|
hideOutcome: boolean
|
|
|
|
truncate: boolean
|
2022-03-14 21:56:53 +00:00
|
|
|
smallAvatar: boolean
|
2022-01-21 18:53:51 +00:00
|
|
|
}) {
|
2022-03-14 21:56:53 +00:00
|
|
|
const { contract, comment, bet, hideOutcome, truncate, smallAvatar } = props
|
2022-03-14 20:29:32 +00:00
|
|
|
const { amount, outcome } = bet
|
|
|
|
const { text, userUsername, userName, userAvatarUrl, createdTime } = comment
|
2022-01-18 03:36:33 +00:00
|
|
|
|
|
|
|
const bought = amount >= 0 ? 'bought' : 'sold'
|
|
|
|
const money = formatMoney(Math.abs(amount))
|
|
|
|
|
2022-01-04 07:21:14 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-03-14 21:56:53 +00:00
|
|
|
<Avatar
|
|
|
|
className={clsx(smallAvatar && 'ml-1')}
|
|
|
|
size={smallAvatar ? 'sm' : undefined}
|
|
|
|
username={userUsername}
|
|
|
|
avatarUrl={userAvatarUrl}
|
|
|
|
/>
|
2022-01-04 07:21:14 +00:00
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
<div>
|
|
|
|
<p className="mt-0.5 text-sm text-gray-500">
|
2022-01-13 21:24:14 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-500"
|
2022-03-14 20:29:32 +00:00
|
|
|
username={userUsername}
|
|
|
|
name={userName}
|
2022-01-13 21:24:14 +00:00
|
|
|
/>{' '}
|
2022-02-24 19:26:01 +00:00
|
|
|
{bought} {money}
|
2022-03-14 20:29:32 +00:00
|
|
|
{!hideOutcome && (
|
|
|
|
<>
|
|
|
|
{' '}
|
2022-04-18 23:02:40 +00:00
|
|
|
of{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={outcome}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
2022-03-14 20:29:32 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<RelativeTimestamp time={createdTime} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2022-01-21 18:53:51 +00:00
|
|
|
<TruncatedComment
|
|
|
|
comment={text}
|
2022-03-14 20:29:32 +00:00
|
|
|
moreHref={contractPath(contract)}
|
|
|
|
shouldTruncate={truncate}
|
2022-01-21 18:53:51 +00:00
|
|
|
/>
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
function RelativeTimestamp(props: { time: number }) {
|
2022-01-04 07:21:14 +00:00
|
|
|
const { time } = props
|
|
|
|
return (
|
2022-01-16 09:16:15 +00:00
|
|
|
<DateTimeTooltip time={time}>
|
2022-02-11 18:40:22 +00:00
|
|
|
<span className="ml-1 whitespace-nowrap text-gray-400">
|
2022-01-24 07:38:29 +00:00
|
|
|
{fromNow(time)}
|
2022-01-16 09:16:15 +00:00
|
|
|
</span>
|
|
|
|
</DateTimeTooltip>
|
2022-01-04 07:21:14 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-21 01:07:45 +00:00
|
|
|
export function FeedBet(props: {
|
2022-03-14 20:29:32 +00:00
|
|
|
contract: Contract
|
|
|
|
bet: Bet
|
|
|
|
hideOutcome: boolean
|
2022-03-14 21:56:53 +00:00
|
|
|
smallAvatar: boolean
|
2022-03-21 01:07:45 +00:00
|
|
|
bettor?: User // If set: reveal bettor identity
|
2022-03-14 20:29:32 +00:00
|
|
|
}) {
|
2022-03-21 01:07:45 +00:00
|
|
|
const { contract, bet, hideOutcome, smallAvatar, bettor } = props
|
2022-03-14 20:29:32 +00:00
|
|
|
const { id, amount, outcome, createdTime, userId } = bet
|
2022-01-04 07:21:14 +00:00
|
|
|
const user = useUser()
|
2022-03-14 20:29:32 +00:00
|
|
|
const isSelf = user?.id === userId
|
|
|
|
|
2022-03-09 00:24:06 +00:00
|
|
|
// You can comment if your bet was posted in the last hour
|
2022-03-17 02:55:03 +00:00
|
|
|
const canComment = isSelf && Date.now() - createdTime < 60 * 60 * 1000
|
2022-01-04 07:21:14 +00:00
|
|
|
|
|
|
|
const [comment, setComment] = useState('')
|
|
|
|
async function submitComment() {
|
2022-03-17 02:55:03 +00:00
|
|
|
if (!user || !comment || !canComment) return
|
2022-03-14 20:29:32 +00:00
|
|
|
await createComment(contract.id, id, comment, user)
|
2022-01-04 07:21:14 +00:00
|
|
|
}
|
2022-01-18 03:36:33 +00:00
|
|
|
|
|
|
|
const bought = amount >= 0 ? 'bought' : 'sold'
|
|
|
|
const money = formatMoney(Math.abs(amount))
|
|
|
|
|
2022-01-04 07:21:14 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
2022-02-06 06:19:10 +00:00
|
|
|
{isSelf ? (
|
2022-03-14 21:56:53 +00:00
|
|
|
<Avatar
|
|
|
|
className={clsx(smallAvatar && 'ml-1')}
|
|
|
|
size={smallAvatar ? 'sm' : undefined}
|
|
|
|
avatarUrl={user.avatarUrl}
|
|
|
|
username={user.username}
|
|
|
|
/>
|
2022-03-21 01:07:45 +00:00
|
|
|
) : bettor ? (
|
|
|
|
<Avatar
|
|
|
|
className={clsx(smallAvatar && 'ml-1')}
|
|
|
|
size={smallAvatar ? 'sm' : undefined}
|
|
|
|
avatarUrl={bettor.avatarUrl}
|
|
|
|
username={bettor.username}
|
|
|
|
/>
|
2022-02-06 06:19:10 +00:00
|
|
|
) : (
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-02-06 06:19:10 +00:00
|
|
|
<UserIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
|
|
|
</div>
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
2022-02-06 06:19:10 +00:00
|
|
|
)}
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
2022-03-21 01:07:45 +00:00
|
|
|
<div className={'min-w-0 flex-1 py-1.5'}>
|
2022-03-10 06:29:36 +00:00
|
|
|
<div className="text-sm text-gray-500">
|
2022-03-21 01:07:45 +00:00
|
|
|
<span>{isSelf ? 'You' : bettor ? bettor.name : 'A trader'}</span>{' '}
|
|
|
|
{bought} {money}
|
2022-03-15 22:27:51 +00:00
|
|
|
{!hideOutcome && (
|
2022-03-14 20:29:32 +00:00
|
|
|
<>
|
|
|
|
{' '}
|
2022-04-18 23:02:40 +00:00
|
|
|
of{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={outcome}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
2022-03-14 20:29:32 +00:00
|
|
|
</>
|
2022-03-10 06:29:36 +00:00
|
|
|
)}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={createdTime} />
|
2022-03-17 02:55:03 +00:00
|
|
|
{(canComment || comment) && (
|
2022-03-10 06:29:36 +00:00
|
|
|
<div className="mt-2">
|
|
|
|
<Textarea
|
|
|
|
value={comment}
|
|
|
|
onChange={(e) => setComment(e.target.value)}
|
2022-03-25 16:27:28 +00:00
|
|
|
className="textarea textarea-bordered w-full resize-none"
|
2022-03-10 06:29:36 +00:00
|
|
|
placeholder="Add a comment..."
|
|
|
|
rows={3}
|
|
|
|
maxLength={MAX_COMMENT_LENGTH}
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
|
|
|
submitComment()
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
className="btn btn-outline btn-sm mt-1"
|
|
|
|
onClick={submitComment}
|
2022-03-17 02:55:03 +00:00
|
|
|
disabled={!canComment}
|
2022-03-10 06:29:36 +00:00
|
|
|
>
|
|
|
|
Comment
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-21 18:53:51 +00:00
|
|
|
function TruncatedComment(props: {
|
|
|
|
comment: string
|
|
|
|
moreHref: string
|
|
|
|
shouldTruncate?: boolean
|
|
|
|
}) {
|
|
|
|
const { comment, moreHref, shouldTruncate } = props
|
|
|
|
let truncated = comment
|
|
|
|
|
|
|
|
// Keep descriptions to at most 400 characters
|
2022-01-22 17:46:59 +00:00
|
|
|
const MAX_CHARS = 400
|
|
|
|
if (shouldTruncate && truncated.length > MAX_CHARS) {
|
|
|
|
truncated = truncated.slice(0, MAX_CHARS)
|
2022-01-21 18:53:51 +00:00
|
|
|
// Make sure to end on a space
|
|
|
|
const i = truncated.lastIndexOf(' ')
|
|
|
|
truncated = truncated.slice(0, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-03-05 00:06:11 +00:00
|
|
|
<div
|
|
|
|
className="mt-2 whitespace-pre-line break-words text-gray-700"
|
|
|
|
style={{ fontSize: 15 }}
|
|
|
|
>
|
2022-01-21 18:53:51 +00:00
|
|
|
<Linkify text={truncated} />
|
|
|
|
{truncated != comment && (
|
|
|
|
<SiteLink href={moreHref} className="text-indigo-700">
|
|
|
|
... (show more)
|
|
|
|
</SiteLink>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
export function FeedQuestion(props: {
|
2022-03-05 00:06:11 +00:00
|
|
|
contract: Contract
|
2022-04-11 21:13:26 +00:00
|
|
|
showDescription: boolean
|
|
|
|
contractPath?: string
|
2022-03-05 00:06:11 +00:00
|
|
|
}) {
|
|
|
|
const { contract, showDescription } = props
|
2022-04-20 22:25:29 +00:00
|
|
|
const {
|
|
|
|
creatorName,
|
|
|
|
creatorUsername,
|
|
|
|
question,
|
|
|
|
outcomeType,
|
|
|
|
volume,
|
|
|
|
createdTime,
|
|
|
|
} = contract
|
2022-03-23 05:02:47 +00:00
|
|
|
const { volumeLabel } = contractMetrics(contract)
|
2022-02-17 23:00:19 +00:00
|
|
|
const isBinary = outcomeType === 'BINARY'
|
2022-04-20 22:25:29 +00:00
|
|
|
const isNew = createdTime > Date.now() - DAY_MS
|
2022-01-11 16:56:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-04 18:30:56 +00:00
|
|
|
<Avatar
|
|
|
|
username={contract.creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
/>
|
2022-01-11 16:56:26 +00:00
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mb-2 text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-01-22 00:10:38 +00:00
|
|
|
asked
|
2022-02-24 04:20:42 +00:00
|
|
|
{/* Currently hidden on mobile; ideally we'd fit this in somewhere. */}
|
2022-04-21 06:03:16 +00:00
|
|
|
<div className="relative -top-2 float-right ">
|
2022-04-20 22:25:29 +00:00
|
|
|
{isNew || volume === 0 ? (
|
2022-04-21 06:03:16 +00:00
|
|
|
<NewContractBadge />
|
2022-04-20 22:25:29 +00:00
|
|
|
) : (
|
2022-04-21 06:03:16 +00:00
|
|
|
<span className="hidden text-gray-400 sm:inline">
|
2022-04-20 22:25:29 +00:00
|
|
|
{volumeLabel}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-01-11 16:56:26 +00:00
|
|
|
</div>
|
2022-03-05 00:06:11 +00:00
|
|
|
<Col className="items-start justify-between gap-2 sm:flex-row sm:gap-4">
|
|
|
|
<Col>
|
|
|
|
<SiteLink
|
2022-04-11 21:13:26 +00:00
|
|
|
href={
|
|
|
|
props.contractPath ? props.contractPath : contractPath(contract)
|
|
|
|
}
|
2022-04-19 05:16:08 +00:00
|
|
|
onClick={() => trackClick(contract.id)}
|
2022-03-05 00:06:11 +00:00
|
|
|
className="text-lg text-indigo-700 sm:text-xl"
|
|
|
|
>
|
|
|
|
{question}
|
|
|
|
</SiteLink>
|
|
|
|
</Col>
|
2022-04-18 23:02:40 +00:00
|
|
|
{isBinary && (
|
|
|
|
<BinaryResolutionOrChance
|
|
|
|
className="items-center"
|
|
|
|
contract={contract}
|
|
|
|
/>
|
2022-02-17 23:00:19 +00:00
|
|
|
)}
|
2022-01-11 20:57:44 +00:00
|
|
|
</Col>
|
2022-03-05 00:06:11 +00:00
|
|
|
{showDescription && (
|
|
|
|
<TruncatedComment
|
|
|
|
comment={contract.description}
|
|
|
|
moreHref={contractPath(contract)}
|
|
|
|
shouldTruncate
|
|
|
|
/>
|
|
|
|
)}
|
2022-01-11 16:56:26 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedDescription(props: { contract: Contract }) {
|
2022-01-04 07:21:14 +00:00
|
|
|
const { contract } = props
|
2022-01-13 21:16:47 +00:00
|
|
|
const { creatorName, creatorUsername } = contract
|
2022-01-04 07:21:14 +00:00
|
|
|
const user = useUser()
|
|
|
|
const isCreator = user?.id === contract.creatorId
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-04 18:30:56 +00:00
|
|
|
<Avatar
|
|
|
|
username={contract.creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
/>
|
2022-01-04 07:21:14 +00:00
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
created this market <RelativeTimestamp time={contract.createdTime} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
function OutcomeIcon(props: { outcome?: string }) {
|
2022-01-04 07:21:14 +00:00
|
|
|
const { outcome } = props
|
|
|
|
switch (outcome) {
|
|
|
|
case 'YES':
|
|
|
|
return <CheckIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
|
|
|
case 'NO':
|
|
|
|
return <XIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
|
|
|
case 'CANCEL':
|
|
|
|
return <BanIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-02-17 23:00:19 +00:00
|
|
|
default:
|
|
|
|
return <CheckIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-01-04 07:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedResolve(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
2022-01-13 21:16:47 +00:00
|
|
|
const { creatorName, creatorUsername } = contract
|
2022-01-04 07:21:14 +00:00
|
|
|
const resolution = contract.resolution || 'CANCEL'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-04 07:21:14 +00:00
|
|
|
<OutcomeIcon outcome={resolution} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-04-18 23:02:40 +00:00
|
|
|
resolved this market to{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={resolution}
|
|
|
|
contract={contract}
|
|
|
|
truncate="long"
|
|
|
|
/>{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={contract.resolutionTime || 0} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedClose(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-04 07:21:14 +00:00
|
|
|
<LockClosedIcon
|
|
|
|
className="h-5 w-5 text-gray-500"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
|
|
|
Trading closed in this market{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={contract.closeTime || 0} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-18 23:02:40 +00:00
|
|
|
function BetGroupSpan(props: {
|
|
|
|
contract: Contract
|
|
|
|
bets: Bet[]
|
|
|
|
outcome?: string
|
|
|
|
}) {
|
|
|
|
const { contract, bets, outcome } = props
|
2022-01-18 03:36:33 +00:00
|
|
|
|
|
|
|
const numberTraders = _.uniqBy(bets, (b) => b.userId).length
|
|
|
|
|
|
|
|
const [buys, sells] = _.partition(bets, (bet) => bet.amount >= 0)
|
|
|
|
const buyTotal = _.sumBy(buys, (b) => b.amount)
|
|
|
|
const sellTotal = _.sumBy(sells, (b) => -b.amount)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{numberTraders} {numberTraders > 1 ? 'traders' : 'trader'}{' '}
|
|
|
|
<JoinSpans>
|
|
|
|
{buyTotal > 0 && <>bought {formatMoney(buyTotal)} </>}
|
|
|
|
{sellTotal > 0 && <>sold {formatMoney(sellTotal)} </>}
|
|
|
|
</JoinSpans>
|
2022-03-14 20:29:32 +00:00
|
|
|
{outcome && (
|
|
|
|
<>
|
|
|
|
{' '}
|
2022-04-18 23:02:40 +00:00
|
|
|
of{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={outcome}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
2022-03-14 20:29:32 +00:00
|
|
|
</>
|
|
|
|
)}{' '}
|
2022-01-18 03:36:33 +00:00
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
function FeedBetGroup(props: {
|
|
|
|
contract: Contract
|
|
|
|
bets: Bet[]
|
|
|
|
hideOutcome: boolean
|
|
|
|
}) {
|
2022-04-18 23:02:40 +00:00
|
|
|
const { contract, bets, hideOutcome } = props
|
2022-01-04 07:21:14 +00:00
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const betGroups = _.groupBy(bets, (bet) => bet.outcome)
|
|
|
|
const outcomes = Object.keys(betGroups)
|
2022-01-18 03:36:33 +00:00
|
|
|
|
2022-02-03 08:56:49 +00:00
|
|
|
// Use the time of the last bet for the entire group
|
|
|
|
const createdTime = bets[bets.length - 1].createdTime
|
2022-01-04 07:21:14 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-19 07:54:00 +00:00
|
|
|
<UsersIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-14 22:11:10 +00:00
|
|
|
<div className={clsx('min-w-0 flex-1', outcomes.length === 1 && 'mt-1')}>
|
2022-01-04 07:21:14 +00:00
|
|
|
<div className="text-sm text-gray-500">
|
2022-02-17 23:00:19 +00:00
|
|
|
{outcomes.map((outcome, index) => (
|
|
|
|
<Fragment key={outcome}>
|
2022-02-24 19:26:01 +00:00
|
|
|
<BetGroupSpan
|
2022-04-18 23:02:40 +00:00
|
|
|
contract={contract}
|
2022-03-14 20:29:32 +00:00
|
|
|
outcome={hideOutcome ? undefined : outcome}
|
2022-02-24 19:26:01 +00:00
|
|
|
bets={betGroups[outcome]}
|
|
|
|
/>
|
2022-02-17 23:00:19 +00:00
|
|
|
{index !== outcomes.length - 1 && <br />}
|
|
|
|
</Fragment>
|
|
|
|
))}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={createdTime} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
function FeedAnswerGroup(props: {
|
2022-03-15 22:27:51 +00:00
|
|
|
contract: FullContract<any, FreeResponse>
|
2022-03-14 20:29:32 +00:00
|
|
|
answer: Answer
|
|
|
|
items: ActivityItem[]
|
|
|
|
}) {
|
2022-03-17 04:42:24 +00:00
|
|
|
const { answer, items, contract } = props
|
2022-03-15 20:11:14 +00:00
|
|
|
const { username, avatarUrl, name, text } = answer
|
2022-03-14 20:29:32 +00:00
|
|
|
|
2022-03-17 04:42:24 +00:00
|
|
|
const prob = getDpmOutcomeProbability(contract.totalShares, answer.id)
|
|
|
|
const probPercent = formatPercent(prob)
|
|
|
|
const [open, setOpen] = useState(false)
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
return (
|
2022-03-15 19:22:21 +00:00
|
|
|
<Col className="flex-1 gap-2">
|
2022-03-17 04:42:24 +00:00
|
|
|
<Modal open={open} setOpen={setOpen}>
|
|
|
|
<AnswerBetPanel
|
|
|
|
answer={answer}
|
|
|
|
contract={contract}
|
|
|
|
closePanel={() => setOpen(false)}
|
|
|
|
className="sm:max-w-84 !rounded-md bg-white !px-8 !py-6"
|
|
|
|
isModal={true}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
|
2022-03-15 20:11:14 +00:00
|
|
|
<Row className="my-4 gap-3">
|
2022-03-14 20:29:32 +00:00
|
|
|
<div className="px-1">
|
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
|
|
|
<Avatar username={username} avatarUrl={avatarUrl} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Col className="min-w-0 flex-1 gap-2">
|
|
|
|
<div className="text-sm text-gray-500">
|
2022-03-15 19:22:21 +00:00
|
|
|
<UserLink username={username} name={name} /> answered
|
2022-03-14 20:29:32 +00:00
|
|
|
</div>
|
2022-03-17 04:42:24 +00:00
|
|
|
|
2022-04-18 23:02:40 +00:00
|
|
|
<Col className="align-items justify-between gap-4 sm:flex-row">
|
2022-03-25 16:27:28 +00:00
|
|
|
<span className="whitespace-pre-line text-lg">
|
2022-03-17 04:42:24 +00:00
|
|
|
<Linkify text={text} />
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<Row className="align-items justify-end gap-4">
|
|
|
|
<span
|
|
|
|
className={clsx(
|
|
|
|
'text-2xl',
|
|
|
|
tradingAllowed(contract) ? 'text-green-500' : 'text-gray-500'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{probPercent}
|
|
|
|
</span>
|
|
|
|
<BuyButton
|
2022-03-18 00:15:07 +00:00
|
|
|
className={clsx(
|
2022-04-18 23:02:40 +00:00
|
|
|
'btn-sm flex-initial !px-6 sm:flex',
|
2022-03-18 00:15:07 +00:00
|
|
|
tradingAllowed(contract) ? '' : '!hidden'
|
|
|
|
)}
|
|
|
|
onClick={() => setOpen(true)}
|
2022-03-17 04:42:24 +00:00
|
|
|
/>
|
|
|
|
</Row>
|
2022-04-18 23:02:40 +00:00
|
|
|
</Col>
|
2022-03-14 20:29:32 +00:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
|
|
|
|
{items.map((item, index) => (
|
|
|
|
<div
|
|
|
|
key={item.id}
|
|
|
|
className={clsx(
|
|
|
|
'relative ml-8',
|
|
|
|
index !== items.length - 1 && 'pb-4'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{index !== items.length - 1 ? (
|
|
|
|
<span
|
|
|
|
className="absolute top-5 left-5 -ml-px h-[calc(100%-1rem)] w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<div className="relative flex items-start space-x-3">
|
|
|
|
<FeedItem item={item} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-22 17:46:59 +00:00
|
|
|
// TODO: Should highlight the entire Feed segment
|
|
|
|
function FeedExpand(props: { setExpanded: (expanded: boolean) => void }) {
|
|
|
|
const { setExpanded } = props
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<button onClick={() => setExpanded(true)}>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200 hover:bg-gray-300">
|
2022-01-22 17:46:59 +00:00
|
|
|
<DotsVerticalIcon
|
|
|
|
className="h-5 w-5 text-gray-500"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button onClick={() => setExpanded(true)}>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500 hover:text-gray-700">
|
|
|
|
<span>Show all activity</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|