Hide BetRow when not appropriate
This commit is contained in:
parent
4d289f2e1e
commit
42086241d1
|
@ -7,7 +7,6 @@ import { Row } from './layout/row'
|
||||||
import { YesNoSelector } from './yes-no-selector'
|
import { YesNoSelector } from './yes-no-selector'
|
||||||
|
|
||||||
// Inline version of a bet panel. Opens BetPanel in a new modal.
|
// Inline version of a bet panel. Opens BetPanel in a new modal.
|
||||||
// TODO: Hide when not appropriate
|
|
||||||
export default function BetRow(props: { contract: Contract }) {
|
export default function BetRow(props: { contract: Contract }) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(
|
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(
|
||||||
|
@ -16,7 +15,7 @@ export default function BetRow(props: { contract: Contract }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="-mt-4 text-xl pb-6 -mx-4 -mb-6">
|
<div className="-mt-2 text-xl -mx-4">
|
||||||
<Row className="items-center gap-2 justify-center">
|
<Row className="items-center gap-2 justify-center">
|
||||||
Buy
|
Buy
|
||||||
<YesNoSelector
|
<YesNoSelector
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
Contract,
|
Contract,
|
||||||
contractPath,
|
contractPath,
|
||||||
updateContract,
|
updateContract,
|
||||||
|
tradingAllowed,
|
||||||
} from '../lib/firebase/contracts'
|
} from '../lib/firebase/contracts'
|
||||||
import { useUser } from '../hooks/use-user'
|
import { useUser } from '../hooks/use-user'
|
||||||
import { Linkify } from './linkify'
|
import { Linkify } from './linkify'
|
||||||
|
@ -39,6 +40,7 @@ import Textarea from 'react-expanding-textarea'
|
||||||
import { outcome } from '../../common/contract'
|
import { outcome } from '../../common/contract'
|
||||||
import { fromNow } from '../lib/util/time'
|
import { fromNow } from '../lib/util/time'
|
||||||
import BetRow from './bet-row'
|
import BetRow from './bet-row'
|
||||||
|
import clsx from 'clsx'
|
||||||
|
|
||||||
export function AvatarWithIcon(props: { username: string; avatarUrl: string }) {
|
export function AvatarWithIcon(props: { username: string; avatarUrl: string }) {
|
||||||
const { username, avatarUrl } = props
|
const { username, avatarUrl } = props
|
||||||
|
@ -649,7 +651,7 @@ export function ContractFeed(props: {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flow-root">
|
<div className="flow-root">
|
||||||
<ul role="list" className="">
|
<ul role="list" className={clsx(tradingAllowed(contract) ? '' : '-mb-8')}>
|
||||||
{items.map((activityItem, activityItemIdx) => (
|
{items.map((activityItem, activityItemIdx) => (
|
||||||
<li key={activityItem.id}>
|
<li key={activityItem.id}>
|
||||||
<div className="relative pb-8">
|
<div className="relative pb-8">
|
||||||
|
@ -688,7 +690,7 @@ export function ContractFeed(props: {
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
<BetRow contract={contract} />
|
{tradingAllowed(contract) && <BetRow contract={contract} />}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,13 @@ export function contractMetrics(contract: Contract) {
|
||||||
return { truePool, probPercent, startProb, createdDate, resolvedDate }
|
return { truePool, probPercent, startProb, createdDate, resolvedDate }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function tradingAllowed(contract: Contract) {
|
||||||
|
return (
|
||||||
|
!contract.isResolved &&
|
||||||
|
(!contract.closeTime || contract.closeTime > Date.now())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const db = getFirestore(app)
|
const db = getFirestore(app)
|
||||||
export const contractCollection = collection(db, 'contracts')
|
export const contractCollection = collection(db, 'contracts')
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
contractMetrics,
|
contractMetrics,
|
||||||
Contract,
|
Contract,
|
||||||
getContractFromSlug,
|
getContractFromSlug,
|
||||||
|
tradingAllowed,
|
||||||
} from '../../lib/firebase/contracts'
|
} from '../../lib/firebase/contracts'
|
||||||
import { SEO } from '../../components/SEO'
|
import { SEO } from '../../components/SEO'
|
||||||
import { Page } from '../../components/page'
|
import { Page } from '../../components/page'
|
||||||
|
@ -70,8 +71,7 @@ export default function ContractPage(props: {
|
||||||
|
|
||||||
const { creatorId, isResolved, resolution, question } = contract
|
const { creatorId, isResolved, resolution, question } = contract
|
||||||
const isCreator = user?.id === creatorId
|
const isCreator = user?.id === creatorId
|
||||||
const allowTrade =
|
const allowTrade = tradingAllowed(contract)
|
||||||
!isResolved && (!contract.closeTime || contract.closeTime > Date.now())
|
|
||||||
const allowResolve = !isResolved && isCreator && !!user
|
const allowResolve = !isResolved && isCreator && !!user
|
||||||
|
|
||||||
const { probPercent } = contractMetrics(contract)
|
const { probPercent } = contractMetrics(contract)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user