import clsx from 'clsx' import { Answer } from '../../common/answer' import { getProbability } from '../../common/calculate' import { Binary, Contract, CPMM, DPM, FreeResponse, FreeResponseContract, FullContract, } from '../../common/contract' import { formatPercent } from '../../common/util/format' export function OutcomeLabel(props: { contract: Contract outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' | string truncate: 'short' | 'long' | 'none' }) { const { outcome, contract, truncate } = props if (contract.outcomeType === 'BINARY') return return ( } resolution={outcome} truncate={truncate} answerClassName={'font-bold text-base-400'} /> ) } export function BinaryOutcomeLabel(props: { outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' }) { const { outcome } = props if (outcome === 'YES') return if (outcome === 'NO') return if (outcome === 'MKT') return return } export function BinaryContractOutcomeLabel(props: { contract: FullContract resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT' }) { const { contract, resolution } = props if (resolution === 'MKT') { const prob = contract.resolutionProbability ?? getProbability(contract) return } return } export function FreeResponseOutcomeLabel(props: { contract: FreeResponseContract resolution: string | 'CANCEL' | 'MKT' truncate: 'short' | 'long' | 'none' answerClassName?: string }) { const { contract, resolution, truncate, answerClassName } = props if (resolution === 'CANCEL') return if (resolution === 'MKT') return const { answers } = contract const chosen = answers?.find((answer) => answer.id === resolution) if (!chosen) return return ( ) } export function YesLabel() { return YES } export function NoLabel() { return NO } export function CancelLabel() { return N/A } export function ProbLabel() { return PROB } export function MultiLabel() { return MULTI } export function ProbPercentLabel(props: { prob: number }) { const { prob } = props return {formatPercent(prob)} } export function AnswerNumberLabel(props: { number: string }) { return #{props.number} } export function AnswerLabel(props: { answer: Answer truncate: 'short' | 'long' | 'none' className?: string }) { const { answer, truncate, className } = props const { text } = answer let truncated = text if (truncate === 'short' && text.length > 20) { truncated = text.slice(0, 10) + '...' + text.slice(-10) } else if (truncate === 'long' && text.length > 75) { truncated = text.slice(0, 75) + '...' } return {truncated} }