Date doc: Toggle to disable creating a prediction market

This commit is contained in:
James Grugett 2022-10-06 18:36:27 -05:00
parent 9d12fa3af0
commit badd67c278
3 changed files with 47 additions and 29 deletions

View File

@ -71,19 +71,23 @@ export const createpost = newEndpoint({}, async (req, auth) => {
if (question) { if (question) {
const closeTime = Date.now() + DAY_MS * 30 * 3 const closeTime = Date.now() + DAY_MS * 30 * 3
const result = await createMarketHelper( try {
{ const result = await createMarketHelper(
question, {
closeTime, question,
outcomeType: 'BINARY', closeTime,
visibility: 'unlisted', outcomeType: 'BINARY',
initialProb: 50, visibility: 'unlisted',
// Dating group! initialProb: 50,
groupId: 'j3ZE8fkeqiKmRGumy3O1', // Dating group!
}, groupId: 'j3ZE8fkeqiKmRGumy3O1',
auth },
) auth
contractSlug = result.slug )
contractSlug = result.slug
} catch (e) {
console.error(e)
}
} }
const post: Post = removeUndefinedProps({ const post: Post = removeUndefinedProps({

View File

@ -142,15 +142,17 @@ export function DateDocPost(props: {
) : ( ) : (
<Content content={content} /> <Content content={content} />
)} )}
<div className="mt-4 w-full max-w-lg self-center rounded-xl bg-gradient-to-r from-blue-200 via-purple-200 to-indigo-300 p-3"> {contractSlug && (
<iframe <div className="mt-4 w-full max-w-lg self-center rounded-xl bg-gradient-to-r from-blue-200 via-purple-200 to-indigo-300 p-3">
height="405" <iframe
src={marketUrl} height="405"
title="" src={marketUrl}
frameBorder="0" title=""
className="w-full rounded-xl bg-white p-10" frameBorder="0"
></iframe> className="w-full rounded-xl bg-white p-10"
</div> ></iframe>
</div>
)}
</Col> </Col>
) )
} }

View File

@ -15,6 +15,8 @@ import { MINUTE_MS } from 'common/util/time'
import { Col } from 'web/components/layout/col' import { Col } from 'web/components/layout/col'
import { MAX_QUESTION_LENGTH } from 'common/contract' import { MAX_QUESTION_LENGTH } from 'common/contract'
import { NoSEO } from 'web/components/NoSEO' import { NoSEO } from 'web/components/NoSEO'
import ShortToggle from 'web/components/widgets/short-toggle'
import { removeUndefinedProps } from 'common/util/object'
export default function CreateDateDocPage() { export default function CreateDateDocPage() {
const user = useUser() const user = useUser()
@ -26,6 +28,7 @@ export default function CreateDateDocPage() {
const title = `${user?.name}'s Date Doc` const title = `${user?.name}'s Date Doc`
const subtitle = 'Manifold dating docs' const subtitle = 'Manifold dating docs'
const [birthday, setBirthday] = useState<undefined | string>(undefined) const [birthday, setBirthday] = useState<undefined | string>(undefined)
const [createMarket, setCreateMarket] = useState(true)
const [question, setQuestion] = useState( const [question, setQuestion] = useState(
'Will I find a partner in the next 3 months?' 'Will I find a partner in the next 3 months?'
) )
@ -38,7 +41,11 @@ export default function CreateDateDocPage() {
const birthdayTime = birthday ? dayjs(birthday).valueOf() : undefined const birthdayTime = birthday ? dayjs(birthday).valueOf() : undefined
const isValid = const isValid =
user && birthday && editor && editor.isEmpty === false && question user &&
birthday &&
editor &&
editor.isEmpty === false &&
(question || !createMarket)
async function saveDateDoc() { async function saveDateDoc() {
if (!user || !editor || !birthdayTime) return if (!user || !editor || !birthdayTime) return
@ -46,15 +53,15 @@ export default function CreateDateDocPage() {
const newPost: Omit< const newPost: Omit<
DateDoc, DateDoc,
'id' | 'creatorId' | 'createdTime' | 'slug' | 'contractSlug' 'id' | 'creatorId' | 'createdTime' | 'slug' | 'contractSlug'
> & { question: string } = { > & { question?: string } = removeUndefinedProps({
title, title,
subtitle, subtitle,
content: editor.getJSON(), content: editor.getJSON(),
bounty: 0, bounty: 0,
birthday: birthdayTime, birthday: birthdayTime,
type: 'date-doc', type: 'date-doc',
question, question: createMarket ? question : undefined,
} })
const result = await createPost(newPost) const result = await createPost(newPost)
@ -106,9 +113,13 @@ export default function CreateDateDocPage() {
</Col> </Col>
<Col className="gap-4"> <Col className="gap-4">
<div className=""> <Row className="items-center gap-4">
Finally, we'll create an (unlisted) prediction market! <ShortToggle
</div> on={createMarket}
setOn={(on) => setCreateMarket(on)}
/>
Create an (unlisted) prediction market attached to the date doc
</Row>
<Col className="gap-2"> <Col className="gap-2">
<Textarea <Textarea
@ -116,6 +127,7 @@ export default function CreateDateDocPage() {
maxLength={MAX_QUESTION_LENGTH} maxLength={MAX_QUESTION_LENGTH}
value={question} value={question}
onChange={(e) => setQuestion(e.target.value || '')} onChange={(e) => setQuestion(e.target.value || '')}
disabled={!createMarket}
/> />
<div className="ml-2 text-gray-500">Cost: M$100</div> <div className="ml-2 text-gray-500">Cost: M$100</div>
</Col> </Col>