2022-05-10 21:49:24 +00:00
|
|
|
import React, { useEffect, useMemo, useState } from 'react'
|
2022-04-11 21:13:26 +00:00
|
|
|
import { ArrowLeftIcon } from '@heroicons/react/outline'
|
2022-05-22 08:36:05 +00:00
|
|
|
import { keyBy, sortBy, groupBy, sumBy, mapValues } from 'lodash'
|
2021-12-16 03:14:00 +00:00
|
|
|
|
2022-05-09 13:04:36 +00:00
|
|
|
import { useContractWithPreload } from 'web/hooks/use-contract'
|
|
|
|
import { ContractOverview } from 'web/components/contract/contract-overview'
|
|
|
|
import { BetPanel } from 'web/components/bet-panel'
|
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { useUser } from 'web/hooks/use-user'
|
|
|
|
import { ResolutionPanel } from 'web/components/resolution-panel'
|
|
|
|
import { Title } from 'web/components/title'
|
|
|
|
import { Spacer } from 'web/components/layout/spacer'
|
2022-07-01 13:47:19 +00:00
|
|
|
import { listUsers, User, writeReferralInfo } from 'web/lib/firebase/users'
|
2022-01-02 04:52:55 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
|
|
|
getContractFromSlug,
|
2022-01-26 20:08:03 +00:00
|
|
|
tradingAllowed,
|
2022-02-17 23:00:19 +00:00
|
|
|
getBinaryProbPercent,
|
2022-05-09 13:04:36 +00:00
|
|
|
} from 'web/lib/firebase/contracts'
|
|
|
|
import { SEO } from 'web/components/SEO'
|
|
|
|
import { Page } from 'web/components/page'
|
|
|
|
import { Bet, listAllBets } from 'web/lib/firebase/bets'
|
|
|
|
import { Comment, listAllComments } from 'web/lib/firebase/comments'
|
2022-01-16 03:09:15 +00:00
|
|
|
import Custom404 from '../404'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { AnswersPanel } from 'web/components/answers/answers-panel'
|
|
|
|
import { fromPropz, usePropz } from 'web/hooks/use-propz'
|
|
|
|
import { Leaderboard } from 'web/components/leaderboard'
|
|
|
|
import { resolvedPayout } from 'common/calculate'
|
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-07-14 00:43:20 +00:00
|
|
|
import { useUserById } from 'web/hooks/use-user'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { ContractTabs } from 'web/components/contract/contract-tabs'
|
|
|
|
import { contractTextDetails } from 'web/components/contract/contract-details'
|
|
|
|
import { useWindowSize } from 'web/hooks/use-window-size'
|
2022-04-28 23:01:50 +00:00
|
|
|
import Confetti from 'react-confetti'
|
2022-05-19 17:42:03 +00:00
|
|
|
import { NumericBetPanel } from '../../components/numeric-bet-panel'
|
|
|
|
import { NumericResolutionPanel } from '../../components/numeric-resolution-panel'
|
2022-05-18 14:42:13 +00:00
|
|
|
import { FeedComment } from 'web/components/feed/feed-comments'
|
|
|
|
import { FeedBet } from 'web/components/feed/feed-bets'
|
2022-05-20 00:34:08 +00:00
|
|
|
import { useIsIframe } from 'web/hooks/use-is-iframe'
|
|
|
|
import ContractEmbedPage from '../embed/[username]/[contractSlug]'
|
2022-06-10 17:23:27 +00:00
|
|
|
import { useBets } from 'web/hooks/use-bets'
|
2022-07-10 18:05:44 +00:00
|
|
|
import { CPMMBinaryContract } from 'common/contract'
|
2022-06-14 02:09:09 +00:00
|
|
|
import { AlertBox } from 'web/components/alert-box'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
2022-06-18 03:28:16 +00:00
|
|
|
import { CommentTipMap, useTipTxns } from 'web/hooks/use-tip-txns'
|
2022-07-01 13:47:19 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2022-06-27 00:00:02 +00:00
|
|
|
import { useLiquidity } from 'web/hooks/use-liquidity'
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
import { richTextToString } from 'common/util/parse'
|
2021-12-09 21:31:02 +00:00
|
|
|
|
2022-03-09 02:43:30 +00:00
|
|
|
export const getStaticProps = fromPropz(getStaticPropz)
|
|
|
|
export async function getStaticPropz(props: {
|
2022-01-21 23:21:46 +00:00
|
|
|
params: { username: string; contractSlug: string }
|
|
|
|
}) {
|
2021-12-19 05:50:47 +00:00
|
|
|
const { username, contractSlug } = props.params
|
|
|
|
const contract = (await getContractFromSlug(contractSlug)) || null
|
2022-01-15 00:16:25 +00:00
|
|
|
const contractId = contract?.id
|
|
|
|
|
2022-04-11 21:13:26 +00:00
|
|
|
const [bets, comments] = await Promise.all([
|
2022-02-01 18:06:42 +00:00
|
|
|
contractId ? listAllBets(contractId) : [],
|
|
|
|
contractId ? listAllComments(contractId) : [],
|
2022-01-15 00:16:25 +00:00
|
|
|
])
|
2021-12-09 22:05:55 +00:00
|
|
|
|
2021-12-16 03:24:11 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2022-02-01 18:06:42 +00:00
|
|
|
contract,
|
2021-12-16 18:40:23 +00:00
|
|
|
username,
|
2021-12-19 05:50:47 +00:00
|
|
|
slug: contractSlug,
|
2022-07-14 19:57:17 +00:00
|
|
|
// Limit the data sent to the client. Client will still load all bets and comments directly.
|
|
|
|
bets: bets.slice(0, 5000),
|
|
|
|
comments: comments.slice(0, 1000),
|
2021-12-16 03:24:11 +00:00
|
|
|
},
|
2021-12-09 22:05:55 +00:00
|
|
|
|
2021-12-16 06:36:51 +00:00
|
|
|
revalidate: 60, // regenerate after a minute
|
2021-12-09 22:05:55 +00:00
|
|
|
}
|
2021-12-16 03:24:11 +00:00
|
|
|
}
|
2021-12-09 21:31:02 +00:00
|
|
|
|
2021-12-16 06:36:51 +00:00
|
|
|
export async function getStaticPaths() {
|
|
|
|
return { paths: [], fallback: 'blocking' }
|
|
|
|
}
|
2021-12-16 03:14:00 +00:00
|
|
|
|
2021-12-16 06:36:51 +00:00
|
|
|
export default function ContractPage(props: {
|
2021-12-16 18:21:16 +00:00
|
|
|
contract: Contract | null
|
2021-12-16 18:40:23 +00:00
|
|
|
username: string
|
2022-02-01 18:06:42 +00:00
|
|
|
bets: Bet[]
|
|
|
|
comments: Comment[]
|
|
|
|
slug: string
|
2022-04-11 21:13:26 +00:00
|
|
|
backToHome?: () => void
|
2021-12-16 06:36:51 +00:00
|
|
|
}) {
|
2022-03-09 02:43:30 +00:00
|
|
|
props = usePropz(props, getStaticPropz) ?? {
|
|
|
|
contract: null,
|
|
|
|
username: '',
|
|
|
|
comments: [],
|
|
|
|
bets: [],
|
|
|
|
slug: '',
|
|
|
|
}
|
2022-06-10 17:23:27 +00:00
|
|
|
|
|
|
|
const inIframe = useIsIframe()
|
|
|
|
if (inIframe) {
|
|
|
|
return <ContractEmbedPage {...props} />
|
|
|
|
}
|
|
|
|
|
2022-06-13 21:05:46 +00:00
|
|
|
const { contract } = props
|
|
|
|
|
2022-06-10 17:23:27 +00:00
|
|
|
if (!contract) {
|
|
|
|
return <Custom404 />
|
|
|
|
}
|
|
|
|
|
|
|
|
return <ContractPageContent {...{ ...props, contract }} />
|
2022-04-11 21:13:26 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 17:23:27 +00:00
|
|
|
export function ContractPageContent(
|
|
|
|
props: Parameters<typeof ContractPage>[0] & { contract: Contract }
|
|
|
|
) {
|
2022-06-13 21:05:46 +00:00
|
|
|
const { backToHome, comments } = props
|
|
|
|
|
|
|
|
const contract = useContractWithPreload(props.contract) ?? props.contract
|
2022-06-10 17:23:27 +00:00
|
|
|
|
2022-06-15 21:34:34 +00:00
|
|
|
useTracking('view market', {
|
|
|
|
slug: contract.slug,
|
|
|
|
contractId: contract.id,
|
|
|
|
creatorId: contract.creatorId,
|
|
|
|
})
|
|
|
|
|
2022-06-10 17:23:27 +00:00
|
|
|
const bets = useBets(contract.id) ?? props.bets
|
2022-06-27 00:00:02 +00:00
|
|
|
const liquidityProvisions =
|
|
|
|
useLiquidity(contract.id)?.filter((l) => !l.isAnte && l.amount > 0) ?? []
|
2022-06-10 17:23:27 +00:00
|
|
|
// Sort for now to see if bug is fixed.
|
|
|
|
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
|
2022-04-11 21:13:26 +00:00
|
|
|
|
2022-07-07 23:23:13 +00:00
|
|
|
const tips = useTipTxns({ contractId: contract.id })
|
2022-06-18 03:28:16 +00:00
|
|
|
|
2021-12-16 05:56:12 +00:00
|
|
|
const user = useUser()
|
2022-07-10 18:05:44 +00:00
|
|
|
|
2022-04-28 23:01:50 +00:00
|
|
|
const { width, height } = useWindowSize()
|
2021-12-09 22:05:55 +00:00
|
|
|
|
2022-04-28 23:01:50 +00:00
|
|
|
const [showConfetti, setShowConfetti] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const shouldSeeConfetti = !!(
|
|
|
|
user &&
|
|
|
|
contract.creatorId === user.id &&
|
|
|
|
Date.now() - contract.createdTime < 10 * 1000
|
|
|
|
)
|
|
|
|
setShowConfetti(shouldSeeConfetti)
|
|
|
|
}, [contract, user])
|
2022-02-06 22:55:14 +00:00
|
|
|
|
2022-05-19 17:42:03 +00:00
|
|
|
const { creatorId, isResolved, question, outcomeType } = contract
|
2022-02-17 23:00:19 +00:00
|
|
|
|
2021-12-14 06:12:25 +00:00
|
|
|
const isCreator = user?.id === creatorId
|
2022-02-17 23:00:19 +00:00
|
|
|
const isBinary = outcomeType === 'BINARY'
|
2022-07-02 19:37:59 +00:00
|
|
|
const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC'
|
2022-05-19 17:42:03 +00:00
|
|
|
const isNumeric = outcomeType === 'NUMERIC'
|
2022-01-26 20:08:03 +00:00
|
|
|
const allowTrade = tradingAllowed(contract)
|
2022-01-10 16:32:54 +00:00
|
|
|
const allowResolve = !isResolved && isCreator && !!user
|
2022-07-02 19:37:59 +00:00
|
|
|
const hasSidePanel =
|
|
|
|
(isBinary || isNumeric || isPseudoNumeric) && (allowTrade || allowResolve)
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2022-02-18 00:34:11 +00:00
|
|
|
const ogCardProps = getOpenGraphProps(contract)
|
2022-01-10 07:05:24 +00:00
|
|
|
|
2022-07-01 13:47:19 +00:00
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const { referrer } = router.query as {
|
|
|
|
referrer?: string
|
|
|
|
}
|
|
|
|
if (!user && router.isReady)
|
|
|
|
writeReferralInfo(contract.creatorUsername, contract.id, referrer)
|
|
|
|
}, [user, contract, router])
|
|
|
|
|
2022-03-31 05:35:20 +00:00
|
|
|
const rightSidebar = hasSidePanel ? (
|
|
|
|
<Col className="gap-4">
|
2022-05-19 17:42:03 +00:00
|
|
|
{allowTrade &&
|
|
|
|
(isNumeric ? (
|
2022-06-01 02:42:35 +00:00
|
|
|
<NumericBetPanel className="hidden xl:flex" contract={contract} />
|
2022-05-19 17:42:03 +00:00
|
|
|
) : (
|
2022-07-10 18:05:44 +00:00
|
|
|
<BetPanel
|
|
|
|
className="hidden xl:flex"
|
|
|
|
contract={contract as CPMMBinaryContract}
|
|
|
|
/>
|
2022-05-19 17:42:03 +00:00
|
|
|
))}
|
|
|
|
{allowResolve &&
|
2022-07-02 19:37:59 +00:00
|
|
|
(isNumeric || isPseudoNumeric ? (
|
2022-06-01 02:42:35 +00:00
|
|
|
<NumericResolutionPanel creator={user} contract={contract} />
|
2022-05-19 17:42:03 +00:00
|
|
|
) : (
|
2022-06-01 02:42:35 +00:00
|
|
|
<ResolutionPanel creator={user} contract={contract} />
|
2022-05-19 17:42:03 +00:00
|
|
|
))}
|
2022-03-31 05:35:20 +00:00
|
|
|
</Col>
|
|
|
|
) : null
|
|
|
|
|
2021-12-09 22:05:55 +00:00
|
|
|
return (
|
2022-03-31 05:35:20 +00:00
|
|
|
<Page rightSidebar={rightSidebar}>
|
2022-04-28 23:01:50 +00:00
|
|
|
{showConfetti && (
|
|
|
|
<Confetti
|
|
|
|
width={width ? width : 500}
|
|
|
|
height={height ? height : 500}
|
|
|
|
recycle={false}
|
|
|
|
numberOfPieces={300}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
{ogCardProps && (
|
|
|
|
<SEO
|
|
|
|
title={question}
|
|
|
|
description={ogCardProps.description}
|
|
|
|
url={`/${props.username}/${props.slug}`}
|
|
|
|
ogCardProps={ogCardProps}
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-16 03:14:00 +00:00
|
|
|
|
2022-05-23 22:09:40 +00:00
|
|
|
<Col className="w-full justify-between rounded border-0 border-gray-100 bg-white py-6 pl-1 pr-2 sm:px-2 md:px-6 md:py-8">
|
2022-04-11 21:13:26 +00:00
|
|
|
{backToHome && (
|
|
|
|
<button
|
|
|
|
className="btn btn-sm mb-4 items-center gap-2 self-start border-0 border-gray-700 bg-white normal-case text-gray-700 hover:bg-white hover:text-gray-700 lg:hidden"
|
|
|
|
onClick={backToHome}
|
|
|
|
>
|
|
|
|
<ArrowLeftIcon className="h-5 w-5 text-gray-700" />
|
|
|
|
Back
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
|
2022-06-18 03:28:16 +00:00
|
|
|
<ContractOverview contract={contract} bets={bets} />
|
2022-07-02 19:37:59 +00:00
|
|
|
|
2022-06-14 02:09:09 +00:00
|
|
|
{isNumeric && (
|
|
|
|
<AlertBox
|
|
|
|
title="Warning"
|
2022-07-02 19:37:59 +00:00
|
|
|
text="Distributional numeric markets were introduced as an experimental feature and are now deprecated."
|
2022-06-14 02:09:09 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-04-18 23:02:40 +00:00
|
|
|
|
2022-05-03 21:54:00 +00:00
|
|
|
{outcomeType === 'FREE_RESPONSE' && (
|
|
|
|
<>
|
|
|
|
<Spacer h={4} />
|
2022-06-01 02:42:35 +00:00
|
|
|
<AnswersPanel contract={contract} />
|
2022-05-03 21:54:00 +00:00
|
|
|
<Spacer h={4} />
|
|
|
|
</>
|
|
|
|
)}
|
2022-04-03 21:57:38 +00:00
|
|
|
|
2022-06-07 22:03:22 +00:00
|
|
|
{isNumeric && allowTrade && (
|
2022-06-01 02:42:35 +00:00
|
|
|
<NumericBetPanel className="xl:hidden" contract={contract} />
|
2022-05-19 17:42:03 +00:00
|
|
|
)}
|
|
|
|
|
2022-05-03 20:57:39 +00:00
|
|
|
{isResolved && (
|
2022-04-03 21:57:38 +00:00
|
|
|
<>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2">
|
2022-05-10 21:22:57 +00:00
|
|
|
<ContractLeaderboard contract={contract} bets={bets} />
|
2022-04-03 21:57:38 +00:00
|
|
|
<ContractTopTrades
|
|
|
|
contract={contract}
|
|
|
|
bets={bets}
|
|
|
|
comments={comments}
|
2022-06-18 03:28:16 +00:00
|
|
|
tips={tips}
|
2022-04-03 21:57:38 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Spacer h={12} />
|
|
|
|
</>
|
|
|
|
)}
|
2022-04-08 21:13:10 +00:00
|
|
|
|
|
|
|
<ContractTabs
|
|
|
|
contract={contract}
|
|
|
|
user={user}
|
2022-06-27 00:00:02 +00:00
|
|
|
liquidityProvisions={liquidityProvisions}
|
2022-04-08 21:13:10 +00:00
|
|
|
bets={bets}
|
2022-06-18 03:28:16 +00:00
|
|
|
tips={tips}
|
2022-04-08 21:13:10 +00:00
|
|
|
comments={comments}
|
|
|
|
/>
|
2021-12-12 22:14:52 +00:00
|
|
|
</Col>
|
2021-12-20 04:06:30 +00:00
|
|
|
</Page>
|
2021-12-09 22:05:55 +00:00
|
|
|
)
|
|
|
|
}
|
2021-12-16 04:30:24 +00:00
|
|
|
|
2022-05-10 21:22:57 +00:00
|
|
|
function ContractLeaderboard(props: { contract: Contract; bets: Bet[] }) {
|
|
|
|
const { contract, bets } = props
|
2022-03-21 01:07:45 +00:00
|
|
|
const [users, setUsers] = useState<User[]>()
|
|
|
|
|
2022-05-10 21:49:24 +00:00
|
|
|
const { userProfits, top5Ids } = useMemo(() => {
|
|
|
|
// Create a map of userIds to total profits (including sales)
|
2022-06-10 16:01:15 +00:00
|
|
|
const openBets = bets.filter((bet) => !bet.isSold && !bet.sale)
|
|
|
|
const betsByUser = groupBy(openBets, 'userId')
|
|
|
|
|
2022-05-22 08:36:05 +00:00
|
|
|
const userProfits = mapValues(betsByUser, (bets) =>
|
|
|
|
sumBy(bets, (bet) => resolvedPayout(contract, bet) - bet.amount)
|
2022-05-10 21:49:24 +00:00
|
|
|
)
|
|
|
|
// Find the 5 users with the most profits
|
2022-05-22 08:36:05 +00:00
|
|
|
const top5Ids = Object.entries(userProfits)
|
|
|
|
.sort(([_i1, p1], [_i2, p2]) => p2 - p1)
|
2022-05-10 21:49:24 +00:00
|
|
|
.filter(([, p]) => p > 0)
|
|
|
|
.slice(0, 5)
|
|
|
|
.map(([id]) => id)
|
|
|
|
return { userProfits, top5Ids }
|
|
|
|
}, [contract, bets])
|
2022-05-10 20:58:38 +00:00
|
|
|
|
2022-05-10 21:22:57 +00:00
|
|
|
useEffect(() => {
|
2022-03-21 01:07:45 +00:00
|
|
|
if (top5Ids.length > 0) {
|
|
|
|
listUsers(top5Ids).then((users) => {
|
2022-05-22 08:36:05 +00:00
|
|
|
const sortedUsers = sortBy(users, (user) => -userProfits[user.id])
|
2022-03-21 01:07:45 +00:00
|
|
|
setUsers(sortedUsers)
|
|
|
|
})
|
|
|
|
}
|
2022-05-10 21:49:24 +00:00
|
|
|
}, [userProfits, top5Ids])
|
2022-03-21 01:07:45 +00:00
|
|
|
|
|
|
|
return users && users.length > 0 ? (
|
|
|
|
<Leaderboard
|
2022-04-26 14:42:45 +00:00
|
|
|
title="🏅 Top bettors"
|
2022-03-21 01:07:45 +00:00
|
|
|
users={users || []}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
header: 'Total profit',
|
|
|
|
renderCell: (user) => formatMoney(userProfits[user.id] || 0),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
className="mt-12 max-w-sm"
|
|
|
|
/>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
function ContractTopTrades(props: {
|
|
|
|
contract: Contract
|
|
|
|
bets: Bet[]
|
|
|
|
comments: Comment[]
|
2022-06-18 03:28:16 +00:00
|
|
|
tips: CommentTipMap
|
2022-03-21 01:07:45 +00:00
|
|
|
}) {
|
2022-06-18 03:28:16 +00:00
|
|
|
const { contract, bets, comments, tips } = props
|
2022-05-22 08:36:05 +00:00
|
|
|
const commentsById = keyBy(comments, 'id')
|
|
|
|
const betsById = keyBy(bets, 'id')
|
2022-03-21 01:07:45 +00:00
|
|
|
|
|
|
|
// If 'id2' is the sale of 'id1', both are logged with (id2 - id1) of profit
|
|
|
|
// Otherwise, we record the profit at resolution time
|
|
|
|
const profitById: Record<string, number> = {}
|
|
|
|
for (const bet of bets) {
|
|
|
|
if (bet.sale) {
|
|
|
|
const originalBet = betsById[bet.sale.betId]
|
|
|
|
const profit = bet.sale.amount - originalBet.amount
|
|
|
|
profitById[bet.id] = profit
|
|
|
|
profitById[originalBet.id] = profit
|
|
|
|
} else {
|
|
|
|
profitById[bet.id] = resolvedPayout(contract, bet) - bet.amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now find the betId with the highest profit
|
2022-05-22 08:36:05 +00:00
|
|
|
const topBetId = sortBy(bets, (b) => -profitById[b.id])[0]?.id
|
2022-03-21 22:19:42 +00:00
|
|
|
const topBettor = useUserById(betsById[topBetId]?.userId)
|
2022-03-21 01:07:45 +00:00
|
|
|
|
|
|
|
// And also the commentId of the comment with the highest profit
|
2022-05-22 08:36:05 +00:00
|
|
|
const topCommentId = sortBy(
|
2022-04-21 17:09:06 +00:00
|
|
|
comments,
|
|
|
|
(c) => c.betId && -profitById[c.betId]
|
|
|
|
)[0]?.id
|
2022-03-21 01:07:45 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mt-12 max-w-sm">
|
2022-03-23 19:06:39 +00:00
|
|
|
{topCommentId && profitById[topCommentId] > 0 && (
|
2022-03-21 01:07:45 +00:00
|
|
|
<>
|
|
|
|
<Title text="💬 Proven correct" className="!mt-0" />
|
|
|
|
<div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4">
|
|
|
|
<FeedComment
|
|
|
|
contract={contract}
|
|
|
|
comment={commentsById[topCommentId]}
|
2022-06-18 03:28:16 +00:00
|
|
|
tips={tips[topCommentId]}
|
2022-04-29 21:11:04 +00:00
|
|
|
betsBySameUser={[betsById[topCommentId]]}
|
2022-03-21 01:07:45 +00:00
|
|
|
truncate={false}
|
|
|
|
smallAvatar={false}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="mt-2 text-sm text-gray-500">
|
|
|
|
{commentsById[topCommentId].userName} made{' '}
|
|
|
|
{formatMoney(profitById[topCommentId] || 0)}!
|
|
|
|
</div>
|
|
|
|
<Spacer h={16} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* If they're the same, only show the comment; otherwise show both */}
|
2022-03-23 19:06:39 +00:00
|
|
|
{topBettor && topBetId !== topCommentId && profitById[topBetId] > 0 && (
|
2022-03-21 01:07:45 +00:00
|
|
|
<>
|
|
|
|
<Title text="💸 Smartest money" className="!mt-0" />
|
|
|
|
<div className="relative flex items-start space-x-3 rounded-md bg-gray-50 px-2 py-4">
|
|
|
|
<FeedBet
|
|
|
|
contract={contract}
|
|
|
|
bet={betsById[topBetId]}
|
|
|
|
hideOutcome={false}
|
|
|
|
smallAvatar={false}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="mt-2 text-sm text-gray-500">
|
|
|
|
{topBettor?.name} made {formatMoney(profitById[topBetId] || 0)}!
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const getOpenGraphProps = (contract: Contract) => {
|
2022-04-29 23:38:31 +00:00
|
|
|
const {
|
|
|
|
resolution,
|
|
|
|
question,
|
|
|
|
creatorName,
|
|
|
|
creatorUsername,
|
|
|
|
outcomeType,
|
|
|
|
creatorAvatarUrl,
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
description: desc,
|
2022-04-29 23:38:31 +00:00
|
|
|
} = contract
|
2022-02-18 00:34:11 +00:00
|
|
|
const probPercent =
|
|
|
|
outcomeType === 'BINARY' ? getBinaryProbPercent(contract) : undefined
|
2022-02-17 23:00:19 +00:00
|
|
|
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
const stringDesc = typeof desc === 'string' ? desc : richTextToString(desc)
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const description = resolution
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
? `Resolved ${resolution}. ${stringDesc}`
|
2022-02-22 20:17:58 +00:00
|
|
|
: probPercent
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
? `${probPercent} chance. ${stringDesc}`
|
|
|
|
: stringDesc
|
2022-02-17 23:00:19 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
question,
|
|
|
|
probability: probPercent,
|
|
|
|
metadata: contractTextDetails(contract),
|
2022-04-29 23:38:31 +00:00
|
|
|
creatorName,
|
|
|
|
creatorUsername,
|
|
|
|
creatorAvatarUrl,
|
2022-02-17 23:00:19 +00:00
|
|
|
description,
|
|
|
|
}
|
|
|
|
}
|