2021-12-14 01:07:28 +00:00
|
|
|
import router from 'next/router'
|
2021-12-16 03:58:28 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-05 05:51:26 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import dayjs from 'dayjs'
|
2022-01-06 08:45:30 +00:00
|
|
|
import Textarea from 'react-expanding-textarea'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { Spacer } from 'web/components/layout/spacer'
|
|
|
|
import { useUser } from 'web/hooks/use-user'
|
|
|
|
import { Contract, contractPath } from 'web/lib/firebase/contracts'
|
|
|
|
import { createContract } from 'web/lib/firebase/api-call'
|
|
|
|
import { FIXED_ANTE, MINIMUM_ANTE } from 'common/antes'
|
|
|
|
import { InfoTooltip } from 'web/components/info-tooltip'
|
|
|
|
import { Page } from 'web/components/page'
|
|
|
|
import { Row } from 'web/components/layout/row'
|
2022-05-26 12:57:59 +00:00
|
|
|
import { MAX_DESCRIPTION_LENGTH, outcomeType, RESOLUTIONS, resolution, resolutionType } from 'common/contract'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
|
|
|
import { useHasCreatedContractToday } from 'web/hooks/use-has-created-contract-today'
|
2022-05-23 12:35:50 +00:00
|
|
|
import { removeUndefinedProps } from 'common/util/object'
|
2022-05-13 23:42:48 +00:00
|
|
|
import { CATEGORIES } from 'common/categories'
|
2022-05-23 12:35:50 +00:00
|
|
|
import { ChoicesToggleGroup } from 'web/components/choices-toggle-group'
|
2022-01-21 18:33:58 +00:00
|
|
|
|
|
|
|
export default function Create() {
|
|
|
|
const [question, setQuestion] = useState('')
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mx-auto w-full max-w-2xl">
|
2022-05-23 12:35:50 +00:00
|
|
|
<div className="rounded-lg px-6 py-4">
|
2022-01-21 18:33:58 +00:00
|
|
|
<form>
|
|
|
|
<div className="form-control w-full">
|
|
|
|
<label className="label">
|
2022-05-23 12:35:50 +00:00
|
|
|
<span className="mb-1">
|
|
|
|
Question<span className={'text-red-700'}>*</span>
|
|
|
|
</span>
|
2022-01-21 18:33:58 +00:00
|
|
|
</label>
|
|
|
|
|
|
|
|
<Textarea
|
|
|
|
placeholder="e.g. Will the Democrats win the 2024 US presidential election?"
|
|
|
|
className="input input-bordered resize-none"
|
2022-04-19 16:04:07 +00:00
|
|
|
autoFocus
|
2022-01-21 18:33:58 +00:00
|
|
|
value={question}
|
|
|
|
onChange={(e) => setQuestion(e.target.value || '')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<NewContract question={question} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
2021-12-14 01:07:28 +00:00
|
|
|
|
2021-12-10 17:54:16 +00:00
|
|
|
// Allow user to create a new contract
|
2022-01-27 18:45:35 +00:00
|
|
|
export function NewContract(props: { question: string; tag?: string }) {
|
|
|
|
const { question, tag } = props
|
2021-12-10 17:54:16 +00:00
|
|
|
const creator = useUser()
|
|
|
|
|
2021-12-16 03:58:28 +00:00
|
|
|
useEffect(() => {
|
2021-12-16 07:00:35 +00:00
|
|
|
if (creator === null) router.push('/')
|
2022-01-05 18:23:58 +00:00
|
|
|
}, [creator])
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-05-17 04:43:40 +00:00
|
|
|
createContract({}).catch(() => {}) // warm up function
|
2022-01-05 18:23:58 +00:00
|
|
|
}, [])
|
2021-12-16 03:58:28 +00:00
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
2022-05-24 16:47:21 +00:00
|
|
|
const [resolutionType, setResolutionType] = useState<resolutionType>('MANUAL')
|
2022-05-26 12:57:59 +00:00
|
|
|
const [automaticResolution, setAutomaticResolution] = useState<resolution>('CANCEL')
|
2021-12-14 01:07:28 +00:00
|
|
|
const [initialProb, setInitialProb] = useState(50)
|
2022-05-19 17:42:03 +00:00
|
|
|
const [minString, setMinString] = useState('')
|
|
|
|
const [maxString, setMaxString] = useState('')
|
2021-12-14 01:07:28 +00:00
|
|
|
const [description, setDescription] = useState('')
|
2022-05-12 15:07:10 +00:00
|
|
|
|
|
|
|
const [category, setCategory] = useState<string>('')
|
|
|
|
// const [tagText, setTagText] = useState<string>(tag ?? '')
|
|
|
|
// const tags = parseWordsAsTags(tagText)
|
2022-01-05 05:51:26 +00:00
|
|
|
|
2022-04-09 18:51:22 +00:00
|
|
|
const [ante, setAnte] = useState(FIXED_ANTE)
|
2022-04-28 23:01:50 +00:00
|
|
|
|
2022-05-23 14:43:11 +00:00
|
|
|
const mustWaitForDailyFreeMarketStatus = useHasCreatedContractToday(creator)
|
2022-04-28 23:01:50 +00:00
|
|
|
|
2022-04-09 18:51:22 +00:00
|
|
|
// useEffect(() => {
|
|
|
|
// if (ante === null && creator) {
|
|
|
|
// const initialAnte = creator.balance < 100 ? MINIMUM_ANTE : 100
|
|
|
|
// setAnte(initialAnte)
|
|
|
|
// }
|
|
|
|
// }, [ante, creator])
|
2022-01-14 23:39:17 +00:00
|
|
|
|
2022-04-09 18:51:22 +00:00
|
|
|
// const [anteError, setAnteError] = useState<string | undefined>()
|
2022-01-21 18:33:58 +00:00
|
|
|
// By default, close the market a week from today
|
2022-05-25 19:37:16 +00:00
|
|
|
const [closeDate, setCloseDate] = useState<undefined | string>(weekFrom(dayjs()))
|
|
|
|
const [resolutionDate, setResolutionDate] = useState<undefined | string>(weekFrom(closeDate))
|
2022-05-25 17:54:28 +00:00
|
|
|
const [closeHoursMinutes, setCloseHoursMinutes] = useState<string>('23:59')
|
|
|
|
const [probErrorText, setProbErrorText] = useState('')
|
|
|
|
const [marketInfoText, setMarketInfoText] = useState('')
|
2021-12-14 01:07:28 +00:00
|
|
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
2022-01-03 05:21:25 +00:00
|
|
|
|
2022-05-25 17:54:28 +00:00
|
|
|
const closeTime = closeDate
|
|
|
|
? dayjs(`${closeDate}T${closeHoursMinutes}`).valueOf()
|
|
|
|
: undefined
|
2022-05-26 12:57:59 +00:00
|
|
|
const automaticResolutionTime = resolutionDate ? dayjs(resolutionDate).valueOf() : undefined
|
2022-01-05 05:51:26 +00:00
|
|
|
|
2022-01-15 23:30:48 +00:00
|
|
|
const balance = creator?.balance || 0
|
2022-01-03 05:21:25 +00:00
|
|
|
|
2022-05-19 17:42:03 +00:00
|
|
|
const min = minString ? parseFloat(minString) : undefined
|
|
|
|
const max = maxString ? parseFloat(maxString) : undefined
|
2022-05-25 17:54:28 +00:00
|
|
|
// get days from today until the end of this year:
|
|
|
|
const daysLeftInTheYear = dayjs().endOf('year').diff(dayjs(), 'day')
|
2022-05-19 17:42:03 +00:00
|
|
|
|
2022-01-03 05:21:25 +00:00
|
|
|
const isValid =
|
2022-05-25 17:54:28 +00:00
|
|
|
(outcomeType === 'BINARY' ? initialProb >= 5 && initialProb <= 95 : true) &&
|
2022-01-03 05:21:25 +00:00
|
|
|
question.length > 0 &&
|
2022-01-14 23:39:17 +00:00
|
|
|
ante !== undefined &&
|
2022-02-06 01:02:13 +00:00
|
|
|
ante !== null &&
|
2022-01-14 23:39:17 +00:00
|
|
|
ante >= MINIMUM_ANTE &&
|
2022-05-23 14:43:11 +00:00
|
|
|
(ante <= balance ||
|
|
|
|
(mustWaitForDailyFreeMarketStatus != 'loading' &&
|
|
|
|
!mustWaitForDailyFreeMarketStatus)) &&
|
2022-01-24 22:33:02 +00:00
|
|
|
// closeTime must be in the future
|
2022-01-12 05:40:41 +00:00
|
|
|
closeTime &&
|
2022-05-19 17:42:03 +00:00
|
|
|
closeTime > Date.now() &&
|
|
|
|
(outcomeType !== 'NUMERIC' ||
|
|
|
|
(min !== undefined &&
|
|
|
|
max !== undefined &&
|
|
|
|
isFinite(min) &&
|
|
|
|
isFinite(max) &&
|
|
|
|
min < max &&
|
|
|
|
max - min > 0.01))
|
2021-12-14 01:07:28 +00:00
|
|
|
|
2022-05-25 19:37:16 +00:00
|
|
|
function weekFrom(date: string | dayjs.Dayjs | undefined) {
|
|
|
|
return dayjs(date).add(7, 'day').format('YYYY-MM-DDT23:59')
|
|
|
|
}
|
|
|
|
|
2022-05-23 12:35:50 +00:00
|
|
|
function setCloseDateInDays(days: number) {
|
2022-05-25 17:54:28 +00:00
|
|
|
const newCloseDate = dayjs().add(days, 'day').format('YYYY-MM-DD')
|
2022-05-23 12:35:50 +00:00
|
|
|
setCloseDate(newCloseDate)
|
|
|
|
}
|
|
|
|
|
2021-12-14 01:07:28 +00:00
|
|
|
async function submit() {
|
2022-01-03 05:21:25 +00:00
|
|
|
// TODO: Tell users why their contract is invalid
|
|
|
|
if (!creator || !isValid) return
|
2021-12-14 01:07:28 +00:00
|
|
|
|
|
|
|
setIsSubmitting(true)
|
|
|
|
|
2022-05-19 22:04:34 +00:00
|
|
|
try {
|
|
|
|
const result = await createContract(
|
|
|
|
removeUndefinedProps({
|
|
|
|
question,
|
|
|
|
outcomeType,
|
|
|
|
description,
|
|
|
|
initialProb,
|
|
|
|
ante,
|
|
|
|
closeTime,
|
|
|
|
tags: category ? [category] : undefined,
|
|
|
|
min,
|
|
|
|
max,
|
2022-05-25 20:17:38 +00:00
|
|
|
automaticResolution,
|
2022-05-26 12:57:59 +00:00
|
|
|
automaticResolutionTime
|
2022-05-19 22:04:34 +00:00
|
|
|
})
|
|
|
|
)
|
2022-05-20 21:58:14 +00:00
|
|
|
await router.push(contractPath(result as Contract))
|
2022-05-19 22:04:34 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.log('error creating contract', e)
|
2022-01-05 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const descriptionPlaceholder =
|
|
|
|
outcomeType === 'BINARY'
|
2022-05-23 12:35:50 +00:00
|
|
|
? `e.g. This question resolves to "YES" if they receive the majority of votes...`
|
2022-02-17 23:00:19 +00:00
|
|
|
: `e.g. I will choose the answer according to...`
|
2021-12-10 17:54:16 +00:00
|
|
|
|
2021-12-16 03:58:28 +00:00
|
|
|
if (!creator) return <></>
|
|
|
|
|
2021-12-10 17:54:16 +00:00
|
|
|
return (
|
2022-01-23 00:38:34 +00:00
|
|
|
<div>
|
2022-05-23 12:35:50 +00:00
|
|
|
<label className="label mt-1">
|
2022-05-25 17:54:28 +00:00
|
|
|
<span className="mt-1">Answer type</span>
|
2022-02-17 23:00:19 +00:00
|
|
|
</label>
|
2022-05-25 17:54:28 +00:00
|
|
|
<ChoicesToggleGroup
|
|
|
|
currentChoice={outcomeType}
|
|
|
|
setChoice={(choice) => {
|
|
|
|
if (choice === 'NUMERIC')
|
|
|
|
setMarketInfoText(
|
|
|
|
'Numeric markets are still experimental and subject to major revisions.'
|
|
|
|
)
|
|
|
|
else if (choice === 'FREE_RESPONSE')
|
|
|
|
setMarketInfoText(
|
|
|
|
'Users can submit their own answers to this market.'
|
|
|
|
)
|
|
|
|
else setMarketInfoText('')
|
|
|
|
setOutcomeType(choice as outcomeType)
|
|
|
|
}}
|
|
|
|
choicesMap={{
|
|
|
|
'Yes / No': 'BINARY',
|
|
|
|
'Free response': 'FREE_RESPONSE',
|
|
|
|
Numeric: 'NUMERIC',
|
|
|
|
}}
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
className={'col-span-4'}
|
|
|
|
/>
|
|
|
|
{marketInfoText && (
|
|
|
|
<div className="mt-2 ml-1 text-sm text-indigo-700">
|
|
|
|
{marketInfoText}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-02-17 23:00:19 +00:00
|
|
|
<Spacer h={4} />
|
2022-01-30 21:51:30 +00:00
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
{outcomeType === 'BINARY' && (
|
|
|
|
<div className="form-control">
|
2022-05-23 12:35:50 +00:00
|
|
|
<Row className="label justify-start">
|
|
|
|
<span className="mb-1">How likely is it to happen?</span>
|
|
|
|
</Row>
|
2022-05-25 17:54:28 +00:00
|
|
|
<Row className={'justify-start'}>
|
2022-05-23 12:35:50 +00:00
|
|
|
<ChoicesToggleGroup
|
|
|
|
currentChoice={initialProb}
|
2022-05-25 17:54:28 +00:00
|
|
|
setChoice={(option) => {
|
|
|
|
setProbErrorText('')
|
|
|
|
setInitialProb(option as number)
|
|
|
|
}}
|
|
|
|
choicesMap={{
|
|
|
|
Unlikely: 25,
|
|
|
|
'Not Sure': 50,
|
|
|
|
Likely: 75,
|
|
|
|
}}
|
2022-05-23 12:35:50 +00:00
|
|
|
isSubmitting={isSubmitting}
|
2022-05-25 17:54:28 +00:00
|
|
|
className={'col-span-4 sm:col-span-3'}
|
|
|
|
>
|
2022-05-25 18:47:44 +00:00
|
|
|
<Row className={'col-span-3 items-center justify-start'}>
|
2022-05-23 12:35:50 +00:00
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
value={initialProb}
|
|
|
|
className={
|
2022-05-25 18:13:51 +00:00
|
|
|
'input-bordered input-md max-w-[100px] rounded-md border-gray-300 pr-2 text-lg'
|
2022-05-23 12:35:50 +00:00
|
|
|
}
|
2022-05-25 17:54:28 +00:00
|
|
|
min={5}
|
|
|
|
max={95}
|
2022-05-23 12:35:50 +00:00
|
|
|
disabled={isSubmitting}
|
2022-05-25 17:54:28 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
// show error if prob is less than 5 or greater than 95:
|
|
|
|
const prob = parseInt(e.target.value)
|
|
|
|
setInitialProb(prob)
|
|
|
|
if (prob < 5 || prob > 95)
|
|
|
|
setProbErrorText('Probability must be between 5% and 95%')
|
|
|
|
else setProbErrorText('')
|
|
|
|
}}
|
2022-05-23 12:35:50 +00:00
|
|
|
/>
|
2022-05-25 18:13:51 +00:00
|
|
|
<span className={'ml-1'}>%</span>
|
|
|
|
</Row>
|
2022-05-25 17:54:28 +00:00
|
|
|
</ChoicesToggleGroup>
|
2022-05-23 12:35:50 +00:00
|
|
|
</Row>
|
2022-05-25 17:54:28 +00:00
|
|
|
{probErrorText && (
|
|
|
|
<div className="text-error mt-2 ml-1 text-sm">{probErrorText}</div>
|
|
|
|
)}
|
2022-02-17 23:00:19 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2022-01-16 01:02:01 +00:00
|
|
|
|
2022-05-19 17:42:03 +00:00
|
|
|
{outcomeType === 'NUMERIC' && (
|
|
|
|
<div className="form-control items-start">
|
|
|
|
<label className="label gap-2">
|
|
|
|
<span className="mb-1">Range</span>
|
|
|
|
<InfoTooltip text="The minimum and maximum numbers across the numeric range." />
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<Row className="gap-2">
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
className="input input-bordered"
|
|
|
|
placeholder="MIN"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => setMinString(e.target.value)}
|
|
|
|
min={Number.MIN_SAFE_INTEGER}
|
|
|
|
max={Number.MAX_SAFE_INTEGER}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={minString ?? ''}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
className="input input-bordered"
|
|
|
|
placeholder="MAX"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => setMaxString(e.target.value)}
|
|
|
|
min={Number.MIN_SAFE_INTEGER}
|
|
|
|
max={Number.MAX_SAFE_INTEGER}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={maxString}
|
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-01-21 18:33:58 +00:00
|
|
|
<Spacer h={4} />
|
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="form-control mb-1 items-start">
|
|
|
|
<label className="label mb-1 gap-2">
|
2022-01-21 18:33:58 +00:00
|
|
|
<span className="mb-1">Description</span>
|
2022-05-25 17:54:28 +00:00
|
|
|
<InfoTooltip text="Optional. Describe how you will resolve this question." />
|
2022-01-21 18:33:58 +00:00
|
|
|
</label>
|
|
|
|
<Textarea
|
2022-03-25 16:27:28 +00:00
|
|
|
className="textarea textarea-bordered w-full resize-none"
|
2022-01-21 18:33:58 +00:00
|
|
|
rows={3}
|
2022-03-09 17:08:57 +00:00
|
|
|
maxLength={MAX_DESCRIPTION_LENGTH}
|
2022-01-21 18:33:58 +00:00
|
|
|
placeholder={descriptionPlaceholder}
|
|
|
|
value={description}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => setDescription(e.target.value || '')}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-01-16 01:02:01 +00:00
|
|
|
|
2022-05-12 15:07:10 +00:00
|
|
|
<Spacer h={4} />
|
2022-01-21 18:33:58 +00:00
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="form-control max-w-sm items-start">
|
2022-02-06 23:14:07 +00:00
|
|
|
<label className="label gap-2">
|
2022-05-12 15:07:10 +00:00
|
|
|
<span className="mb-1">Category</span>
|
2022-02-06 23:14:07 +00:00
|
|
|
</label>
|
|
|
|
|
2022-05-12 15:07:10 +00:00
|
|
|
<select
|
|
|
|
className="select select-bordered w-full max-w-xs"
|
2022-05-13 23:42:48 +00:00
|
|
|
value={category}
|
|
|
|
onChange={(e) => setCategory(e.currentTarget.value ?? '')}
|
2022-05-12 15:07:10 +00:00
|
|
|
>
|
2022-05-17 15:56:43 +00:00
|
|
|
<option value={''}>(none)</option>
|
2022-05-13 23:42:48 +00:00
|
|
|
{Object.entries(CATEGORIES).map(([id, name]) => (
|
|
|
|
<option key={id} value={id}>
|
|
|
|
{name}
|
2022-05-12 15:07:10 +00:00
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
2022-02-06 23:14:07 +00:00
|
|
|
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="form-control mb-1 items-start">
|
|
|
|
<label className="label mb-1 gap-2">
|
2022-05-25 17:54:28 +00:00
|
|
|
<span>Question closes in:</span>
|
|
|
|
<InfoTooltip text="Betting will be halted after this time (local timezone)." />
|
2022-01-21 18:33:58 +00:00
|
|
|
</label>
|
2022-05-23 12:35:50 +00:00
|
|
|
<Row className={'w-full items-center gap-2'}>
|
|
|
|
<ChoicesToggleGroup
|
2022-05-25 17:54:28 +00:00
|
|
|
currentChoice={dayjs(`${closeDate}T23:59`).diff(dayjs(), 'day')}
|
|
|
|
setChoice={(choice) => {
|
|
|
|
setCloseDateInDays(choice as number)
|
|
|
|
}}
|
|
|
|
choicesMap={{
|
|
|
|
'A day': 1,
|
|
|
|
'A week': 7,
|
|
|
|
'30 days': 30,
|
|
|
|
'This year': daysLeftInTheYear,
|
|
|
|
}}
|
2022-05-23 12:35:50 +00:00
|
|
|
isSubmitting={isSubmitting}
|
2022-05-25 17:54:28 +00:00
|
|
|
className={'col-span-4 sm:col-span-2'}
|
2022-05-23 12:35:50 +00:00
|
|
|
/>
|
|
|
|
</Row>
|
2022-05-25 17:54:28 +00:00
|
|
|
<Row>
|
2022-05-23 12:35:50 +00:00
|
|
|
<input
|
|
|
|
type={'date'}
|
|
|
|
className="input input-bordered mt-4"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) =>
|
2022-05-25 17:54:28 +00:00
|
|
|
setCloseDate(dayjs(e.target.value).format('YYYY-MM-DD') || '')
|
2022-05-23 12:35:50 +00:00
|
|
|
}
|
|
|
|
min={Date.now()}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={dayjs(closeDate).format('YYYY-MM-DD')}
|
|
|
|
/>
|
2022-05-25 17:54:28 +00:00
|
|
|
<input
|
|
|
|
type={'time'}
|
|
|
|
className="input input-bordered mt-4 ml-2"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => setCloseHoursMinutes(e.target.value)}
|
|
|
|
min={'00:00'}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={closeHoursMinutes}
|
|
|
|
/>
|
|
|
|
</Row>
|
2022-01-21 18:33:58 +00:00
|
|
|
</div>
|
2022-01-16 01:02:01 +00:00
|
|
|
|
2022-05-25 20:17:38 +00:00
|
|
|
{outcomeType === 'BINARY' && (
|
|
|
|
<div>
|
|
|
|
<Spacer h={4} />
|
2022-05-25 19:37:16 +00:00
|
|
|
<div className="form-control mb-1 items-start">
|
2022-05-25 20:17:38 +00:00
|
|
|
<label className="label mt-1 gap-2">
|
|
|
|
<span>Resolution type</span>
|
|
|
|
<InfoTooltip text="Combined markets can be resolved manually but will be resolved automatically under given conditions." />
|
2022-05-25 19:37:16 +00:00
|
|
|
</label>
|
2022-05-25 20:17:38 +00:00
|
|
|
<Row className="form-control gap-2">
|
|
|
|
<label className="label cursor-pointer gap-2">
|
|
|
|
<input
|
|
|
|
className="radio"
|
|
|
|
type="radio"
|
|
|
|
name="res"
|
|
|
|
checked={resolutionType === 'MANUAL'}
|
|
|
|
value="MANUAL"
|
|
|
|
onChange={() => setResolutionType('MANUAL')}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
/>
|
|
|
|
<span className="label-text">Manual</span>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<label className="label cursor-pointer gap-2">
|
|
|
|
<input
|
|
|
|
className="radio"
|
|
|
|
type="radio"
|
|
|
|
name="res"
|
|
|
|
checked={resolutionType === 'COMBINED'}
|
|
|
|
value="COMBINED"
|
|
|
|
onChange={() => setResolutionType('COMBINED')}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
/>
|
|
|
|
<span className="label-text">Combined (experimental)</span>
|
|
|
|
</label>
|
2022-05-25 19:37:16 +00:00
|
|
|
</Row>
|
2022-05-25 20:17:38 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
{resolutionType === 'COMBINED' && (
|
2022-05-27 21:11:22 +00:00
|
|
|
<div className="form-control">
|
|
|
|
<Row className="label justify-start">
|
|
|
|
<span>Question resolves automatically as:</span>
|
2022-05-25 20:17:38 +00:00
|
|
|
<InfoTooltip text="The market will be resolved automatically on this date (local timezone)." />
|
2022-05-27 21:11:22 +00:00
|
|
|
</Row>
|
|
|
|
<Row className={'justify-start'}>
|
2022-05-25 20:17:38 +00:00
|
|
|
<ChoicesToggleGroup
|
|
|
|
currentChoice={automaticResolution}
|
2022-05-27 21:11:22 +00:00
|
|
|
setChoice={(choice) => setAutomaticResolution(choice as resolution)}
|
|
|
|
choicesMap={{
|
|
|
|
'YES': 'YES',
|
|
|
|
'NO': 'NO',
|
|
|
|
'MKT': 'PROB',
|
|
|
|
'CANCEL': 'N/A',
|
|
|
|
}}
|
2022-05-25 20:17:38 +00:00
|
|
|
isSubmitting={isSubmitting}
|
2022-05-27 21:11:22 +00:00
|
|
|
className={'col-span-4 sm:col-span-3'}
|
2022-05-25 20:17:38 +00:00
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
<input
|
|
|
|
type={'date'}
|
|
|
|
className="input input-bordered mt-4"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) =>
|
|
|
|
setResolutionDate(
|
|
|
|
dayjs(e.target.value).format('YYYY-MM-DDT23:59') || ''
|
|
|
|
)
|
|
|
|
}
|
|
|
|
min={Date.parse(closeDate??"")} // TODO: Fix: Market can be created with dates in the past
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={dayjs(resolutionDate).format('YYYY-MM-DD')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-05-25 19:37:16 +00:00
|
|
|
</div>
|
2022-05-25 20:17:38 +00:00
|
|
|
)}
|
2022-05-25 19:37:16 +00:00
|
|
|
|
2022-01-21 18:33:58 +00:00
|
|
|
<Spacer h={4} />
|
2022-01-16 01:02:01 +00:00
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="form-control mb-1 items-start">
|
|
|
|
<label className="label mb-1 gap-2">
|
2022-04-09 18:51:22 +00:00
|
|
|
<span>Cost</span>
|
2022-05-23 14:43:11 +00:00
|
|
|
{mustWaitForDailyFreeMarketStatus != 'loading' &&
|
|
|
|
mustWaitForDailyFreeMarketStatus && (
|
|
|
|
<InfoTooltip
|
2022-05-25 17:54:28 +00:00
|
|
|
text={`Cost to create your question. This amount is used to subsidize betting.`}
|
2022-05-23 14:43:11 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-01-21 18:33:58 +00:00
|
|
|
</label>
|
2022-05-23 14:43:11 +00:00
|
|
|
{mustWaitForDailyFreeMarketStatus != 'loading' &&
|
|
|
|
!mustWaitForDailyFreeMarketStatus ? (
|
2022-05-23 12:35:50 +00:00
|
|
|
<div className="label-text text-primary pl-1">
|
|
|
|
<span className={'label-text text-neutral line-through '}>
|
|
|
|
{formatMoney(ante)}
|
|
|
|
</span>{' '}
|
|
|
|
FREE
|
|
|
|
</div>
|
2022-04-28 23:01:50 +00:00
|
|
|
) : (
|
2022-05-23 14:43:11 +00:00
|
|
|
mustWaitForDailyFreeMarketStatus != 'loading' && (
|
|
|
|
<div className="label-text text-neutral pl-1">
|
|
|
|
{formatMoney(ante)}
|
|
|
|
</div>
|
|
|
|
)
|
2022-04-09 18:51:22 +00:00
|
|
|
)}
|
2022-05-23 14:43:11 +00:00
|
|
|
{mustWaitForDailyFreeMarketStatus != 'loading' &&
|
|
|
|
mustWaitForDailyFreeMarketStatus &&
|
|
|
|
ante > balance && (
|
|
|
|
<div className="mb-2 mt-2 mr-auto self-center whitespace-nowrap text-xs font-medium tracking-wide">
|
|
|
|
<span className="mr-2 text-red-500">Insufficient balance</span>
|
|
|
|
<button
|
|
|
|
className="btn btn-xs btn-primary"
|
|
|
|
onClick={() => (window.location.href = '/add-funds')}
|
|
|
|
>
|
|
|
|
Add funds
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-04-09 18:51:22 +00:00
|
|
|
|
|
|
|
{/* <BuyAmountInput
|
2022-02-06 01:10:26 +00:00
|
|
|
amount={ante ?? undefined}
|
2022-01-21 18:33:58 +00:00
|
|
|
minimumAmount={MINIMUM_ANTE}
|
|
|
|
onChange={setAnte}
|
|
|
|
error={anteError}
|
|
|
|
setError={setAnteError}
|
|
|
|
disabled={isSubmitting}
|
2022-03-02 21:50:19 +00:00
|
|
|
contractIdForLoan={undefined}
|
2022-04-09 18:51:22 +00:00
|
|
|
/> */}
|
2022-01-21 18:33:58 +00:00
|
|
|
</div>
|
2022-01-16 01:02:01 +00:00
|
|
|
|
2022-01-21 18:33:58 +00:00
|
|
|
<Spacer h={4} />
|
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="my-4 flex justify-end">
|
2022-01-21 18:33:58 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
className={clsx(
|
2022-04-28 23:01:50 +00:00
|
|
|
'btn btn-primary capitalize',
|
2022-01-21 18:33:58 +00:00
|
|
|
isSubmitting && 'loading disabled'
|
|
|
|
)}
|
|
|
|
disabled={isSubmitting || !isValid}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
submit()
|
|
|
|
}}
|
|
|
|
>
|
2022-05-25 17:54:28 +00:00
|
|
|
{isSubmitting ? 'Creating...' : 'Create question'}
|
2022-01-21 18:33:58 +00:00
|
|
|
</button>
|
2021-12-10 17:54:16 +00:00
|
|
|
</div>
|
2022-05-25 20:17:38 +00:00
|
|
|
</div>
|
2021-12-10 17:54:16 +00:00
|
|
|
)
|
|
|
|
}
|