76f27d1a93
* Numeric contract type * Create market numeric type * Add numeric graph (coded without testing) * Outline of numeric bet panel * Update bet panel logic * create numeric contracts * remove batching for antes for numeric markets * Remove focus * numeric market range [1, 100] * Zoom graph * Hide bet panels * getNumericBets * Add numeric resolution panel * Use getNumericBets in bet panel calc * Switch bucket count to 100 * Parallelize ante creation * placeBet for numeric markets * halve std of numeric bets * Update resolveMarket with numeric type * Set min and max for contract * lower std for numeric bets * calculateNumericDpmShares: use sorted order * Use min and max to map the input * Fix probability calc * normpdf variance mislabeled * range input * merge * change numeric graph color * fix getNewContract params * bet panel labels * validation * number input * fix bucketing * bucket input, numeric resolution panel * outcome label * merge * numeric bet panel on mobile * Make text underneath filled green answer bar selectable * Default to 'all' feed category when loading page. * fix numeric resolution panel * fix numeric bet panel calculations * display numeric resolution * don't render NumericBetPanel for non numeric markets * numeric bets: store shares, bet amounts across buckets in each bet object * restore your bets for numeric markets * numeric pnl calculations * remove hasUserHitManaLimit * contrain contract type * handle undefined allOutcomeShares * numeric ante bet amount * use correct amount for numeric dpm payouts * change numeric graph/outcome color * numeric constants * hack to show correct numeric payout in calculateDpmPayoutAfterCorrectBet * remove comment * fix ante display in bet list * halve bucket count * cast to NumericContract * fix merge imports * OUTCOME_TYPES * typo * lower bucket count to 200 * store raw numeric value with bet * store raw numeric resolution value * number input max length * create page: min, max to undefined if not numeric market * numeric resolution formatting * expected value for numeric markets * expected value for numeric markets * rearrange lines for readability * move normalpdf to util/math * show bets tab * check if outcomeMode is undefined * remove extraneous auto-merge cruft * hide comment status for numeric markets * import Co-authored-by: mantikoros <sgrugett@gmail.com>
163 lines
4.5 KiB
TypeScript
163 lines
4.5 KiB
TypeScript
import { Bet } from 'common/bet'
|
|
import {
|
|
BinaryContract,
|
|
Contract,
|
|
DPM,
|
|
FreeResponse,
|
|
FullContract,
|
|
NumericContract,
|
|
} from 'common/contract'
|
|
import { DOMAIN } from 'common/envs/constants'
|
|
import { AnswersGraph } from 'web/components/answers/answers-graph'
|
|
import BetRow from 'web/components/bet-row'
|
|
import {
|
|
BinaryResolutionOrChance,
|
|
FreeResponseResolutionOrChance,
|
|
NumericResolutionOrExpectation,
|
|
} from 'web/components/contract/contract-card'
|
|
import { ContractDetails } from 'web/components/contract/contract-details'
|
|
import { ContractProbGraph } from 'web/components/contract/contract-prob-graph'
|
|
import { Col } from 'web/components/layout/col'
|
|
import { Row } from 'web/components/layout/row'
|
|
import { Spacer } from 'web/components/layout/spacer'
|
|
import { Linkify } from 'web/components/linkify'
|
|
import { SiteLink } from 'web/components/site-link'
|
|
import { useContractWithPreload } from 'web/hooks/use-contract'
|
|
import { useMeasureSize } from 'web/hooks/use-measure-size'
|
|
import { fromPropz, usePropz } from 'web/hooks/use-propz'
|
|
import { useWindowSize } from 'web/hooks/use-window-size'
|
|
import { listAllBets } from 'web/lib/firebase/bets'
|
|
import { contractPath, getContractFromSlug } from 'web/lib/firebase/contracts'
|
|
import Custom404 from '../../404'
|
|
|
|
export const getStaticProps = fromPropz(getStaticPropz)
|
|
export async function getStaticPropz(props: {
|
|
params: { username: string; contractSlug: string }
|
|
}) {
|
|
const { username, contractSlug } = props.params
|
|
const contract = (await getContractFromSlug(contractSlug)) || null
|
|
const contractId = contract?.id
|
|
|
|
const bets = contractId ? await listAllBets(contractId) : []
|
|
|
|
return {
|
|
props: {
|
|
contract,
|
|
username,
|
|
slug: contractSlug,
|
|
bets,
|
|
},
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
}
|
|
}
|
|
|
|
export async function getStaticPaths() {
|
|
return { paths: [], fallback: 'blocking' }
|
|
}
|
|
|
|
export default function ContractEmbedPage(props: {
|
|
contract: Contract | null
|
|
username: string
|
|
bets: Bet[]
|
|
slug: string
|
|
}) {
|
|
props = usePropz(props, getStaticPropz) ?? {
|
|
contract: null,
|
|
username: '',
|
|
bets: [],
|
|
slug: '',
|
|
}
|
|
|
|
const contract = useContractWithPreload(props.contract)
|
|
const { bets } = props
|
|
|
|
bets.sort((bet1, bet2) => bet1.createdTime - bet2.createdTime)
|
|
|
|
if (!contract) {
|
|
return <Custom404 />
|
|
}
|
|
|
|
return <ContractEmbed contract={contract} bets={bets} />
|
|
}
|
|
|
|
function ContractEmbed(props: { contract: Contract; bets: Bet[] }) {
|
|
const { contract, bets } = props
|
|
const { question, resolution, outcomeType } = contract
|
|
|
|
const isBinary = outcomeType === 'BINARY'
|
|
|
|
const href = `https://${DOMAIN}${contractPath(contract)}`
|
|
|
|
const { height: windowHeight } = useWindowSize()
|
|
const { setElem, height: topSectionHeight } = useMeasureSize()
|
|
const paddingBottom = 8
|
|
|
|
const graphHeight =
|
|
windowHeight && topSectionHeight
|
|
? windowHeight - topSectionHeight - paddingBottom
|
|
: 0
|
|
|
|
return (
|
|
<Col className="w-full flex-1 bg-white">
|
|
<div className="relative flex flex-col pt-2" ref={setElem}>
|
|
<div className="px-3 text-xl text-indigo-700 md:text-2xl">
|
|
<SiteLink href={href}>{question}</SiteLink>
|
|
</div>
|
|
|
|
<Spacer h={3} />
|
|
|
|
<Row className="items-center justify-between gap-4 px-2">
|
|
<ContractDetails
|
|
contract={contract}
|
|
bets={bets}
|
|
isCreator={false}
|
|
disabled
|
|
/>
|
|
|
|
{isBinary && (
|
|
<Row className="items-center gap-4">
|
|
<BetRow
|
|
contract={contract as BinaryContract}
|
|
betPanelClassName="scale-75"
|
|
/>
|
|
<BinaryResolutionOrChance contract={contract} />
|
|
</Row>
|
|
)}
|
|
|
|
{outcomeType === 'FREE_RESPONSE' && resolution && (
|
|
<FreeResponseResolutionOrChance
|
|
contract={contract}
|
|
truncate="long"
|
|
/>
|
|
)}
|
|
|
|
{outcomeType === 'NUMERIC' && resolution && (
|
|
<NumericResolutionOrExpectation
|
|
contract={contract as NumericContract}
|
|
/>
|
|
)}
|
|
</Row>
|
|
|
|
<Spacer h={2} />
|
|
</div>
|
|
|
|
<div className="mx-1" style={{ paddingBottom }}>
|
|
{isBinary ? (
|
|
<ContractProbGraph
|
|
contract={contract}
|
|
bets={bets}
|
|
height={graphHeight}
|
|
/>
|
|
) : (
|
|
<AnswersGraph
|
|
contract={contract as FullContract<DPM, FreeResponse>}
|
|
bets={bets}
|
|
height={graphHeight}
|
|
/>
|
|
)}
|
|
</div>
|
|
</Col>
|
|
)
|
|
}
|