f48ae0170b
* sell bet * dev mode * single-pot no-refund payoff; bet selling * Increase default fetch size 25 -> 99 * Fix about page numbering * Don't flash no markets when loading on tag page. * Change Title to use body font * Make a bunch of predictions at once (#9) * Set up a page to make bulk predictions * Integrate preview into the same card * List created predictions * Make changes per James's comments * Increase the starting balance (#11) * Remove references to paying for our Mantic Dollars * Update simulator to use new calculations * Change simulator random to be evenly random again * Sell bet UI * Migrate contracts and bets script * Add comment to script * bets => trades; exclude sold bets * change sale formula * Change current value to uncapped sell value. * Disable sell button while selling * Update some 'bet' to 'trade' Co-authored-by: Austin Chen <akrolsmir@gmail.com> Co-authored-by: jahooma <jahooma@gmail.com>
108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
import React from 'react'
|
|
|
|
import { useContractWithPreload } from '../../hooks/use-contract'
|
|
import { ContractOverview } from '../../components/contract-overview'
|
|
import { BetPanel } from '../../components/bet-panel'
|
|
import { Col } from '../../components/layout/col'
|
|
import { useUser } from '../../hooks/use-user'
|
|
import { ResolutionPanel } from '../../components/resolution-panel'
|
|
import { ContractBetsTable, MyBetsSummary } from '../../components/bets-list'
|
|
import { useBets } from '../../hooks/use-bets'
|
|
import { Title } from '../../components/title'
|
|
import { Spacer } from '../../components/layout/spacer'
|
|
import { User } from '../../lib/firebase/users'
|
|
import { Contract, getContractFromSlug } from '../../lib/firebase/contracts'
|
|
import { SEO } from '../../components/SEO'
|
|
import { Page } from '../../components/page'
|
|
|
|
export async function getStaticProps(props: { params: any }) {
|
|
const { username, contractSlug } = props.params
|
|
const contract = (await getContractFromSlug(contractSlug)) || null
|
|
|
|
return {
|
|
props: {
|
|
username,
|
|
slug: contractSlug,
|
|
contract,
|
|
},
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
}
|
|
}
|
|
|
|
export async function getStaticPaths() {
|
|
return { paths: [], fallback: 'blocking' }
|
|
}
|
|
|
|
export default function ContractPage(props: {
|
|
contract: Contract | null
|
|
slug: string
|
|
username: string
|
|
}) {
|
|
const user = useUser()
|
|
|
|
const contract = useContractWithPreload(props.slug, props.contract)
|
|
|
|
if (!contract) {
|
|
return <div>Contract not found...</div>
|
|
}
|
|
|
|
const { creatorId, isResolved } = contract
|
|
const isCreator = user?.id === creatorId
|
|
|
|
return (
|
|
<Page wide={!isResolved}>
|
|
<SEO
|
|
title={contract.question}
|
|
description={contract.description}
|
|
url={`/${props.username}/${props.slug}`}
|
|
/>
|
|
|
|
<Col className="w-full md:flex-row justify-between mt-6">
|
|
<div className="flex-[3]">
|
|
<ContractOverview contract={contract} />
|
|
<BetsSection contract={contract} user={user ?? null} />
|
|
</div>
|
|
|
|
{!isResolved && (
|
|
<>
|
|
<div className="md:ml-8" />
|
|
|
|
<Col className="flex-1">
|
|
<BetPanel contract={contract} />
|
|
|
|
{isCreator && user && (
|
|
<ResolutionPanel creator={user} contract={contract} />
|
|
)}
|
|
</Col>
|
|
</>
|
|
)}
|
|
</Col>
|
|
</Page>
|
|
)
|
|
}
|
|
|
|
function BetsSection(props: { contract: Contract; user: User | null }) {
|
|
const { contract, user } = props
|
|
const bets = useBets(contract.id)
|
|
|
|
if (bets === 'loading' || bets.length === 0) return <></>
|
|
|
|
// Decending creation time.
|
|
bets.sort((bet1, bet2) => bet2.createdTime - bet1.createdTime)
|
|
|
|
const userBets = user && bets.filter((bet) => bet.userId === user.id)
|
|
|
|
if (!userBets || userBets.length === 0) return <></>
|
|
|
|
return (
|
|
<div>
|
|
<Title text="Your trades" />
|
|
<MyBetsSummary contract={contract} bets={userBets} />
|
|
<Spacer h={6} />
|
|
<ContractBetsTable contract={contract} bets={userBets} />
|
|
<Spacer h={12} />
|
|
</div>
|
|
)
|
|
}
|