import clsx from 'clsx'
import { partition } from 'lodash'
import { contractPath } from 'web/lib/firebase/contracts'
import { CPMMContract } from 'common/contract'
import { formatPercent } from 'common/util/format'
import { SiteLink } from '../site-link'
import { Col } from '../layout/col'
import { Row } from '../layout/row'
import { LoadingIndicator } from '../loading-indicator'
import { useContractWithPreload } from 'web/hooks/use-contract'
export function ProbChangeTable(props: {
changes: CPMMContract[] | undefined
full?: boolean
}) {
const { changes, full } = props
if (!changes) return
const [positiveChanges, negativeChanges] = partition(
changes,
(c) => c.probChanges.day > 0
)
const threshold = 0.01
const positiveAboveThreshold = positiveChanges.filter(
(c) => c.probChanges.day > threshold
)
const negativeAboveThreshold = negativeChanges.filter(
(c) => c.probChanges.day < threshold
)
const maxRows = Math.min(
positiveAboveThreshold.length,
negativeAboveThreshold.length
)
const rows = full ? maxRows : Math.min(3, maxRows)
const filteredPositiveChanges = positiveAboveThreshold.slice(0, rows)
const filteredNegativeChanges = negativeAboveThreshold.slice(0, rows)
if (rows === 0) return
None
return (
{filteredPositiveChanges.map((contract) => (
))}
{filteredNegativeChanges.map((contract) => (
))}
)
}
export function ProbChangeRow(props: {
contract: CPMMContract
className?: string
}) {
const { className } = props
const contract =
(useContractWithPreload(props.contract) as CPMMContract) ?? props.contract
return (
{contract.question}
)
}
export function ProbChange(props: {
contract: CPMMContract
className?: string
}) {
const { contract, className } = props
const {
prob,
probChanges: { day: change },
} = contract
const color = change >= 0 ? 'text-green-500' : 'text-red-500'
return (
{formatPercent(Math.round(100 * prob) / 100)}
{(change > 0 ? '+' : '') + (change * 100).toFixed(0) + '%'}
)
}