Add Bounty type, enable from /create

This commit is contained in:
Austin Chen 2022-08-14 17:47:27 -07:00
parent 977268e9fc
commit ac76094174
3 changed files with 55 additions and 23 deletions

View File

@ -1,3 +1,4 @@
import { JSONContent } from '@tiptap/core'
import { User } from './user'
export type Answer = {
@ -12,6 +13,7 @@ export type Answer = {
avatarUrl?: string
text: string
description?: string | JSONContent
}
export const getNoneAnswer = (contractId: string, creator: User) => {

View File

@ -10,6 +10,7 @@ export type AnyOutcomeType =
| PseudoNumeric
| FreeResponse
| Numeric
| Bounty
export type AnyContractType =
| (CPMM & Binary)
| (CPMM & PseudoNumeric)
@ -68,6 +69,7 @@ export type DPMContract = Contract & DPM
export type CPMMContract = Contract & CPMM
export type DPMBinaryContract = BinaryContract & DPM
export type CPMMBinaryContract = BinaryContract & CPMM
export type BountyContract = Contract & Bounty
export type DPM = {
mechanism: 'dpm-2'
@ -127,6 +129,18 @@ export type Numeric = {
resolutionValue?: number
}
export type Bounty = {
outcomeType: 'BOUNTY'
// One answer for each submission
answers: Answer[]
prizes: {
[giverId: string]: number
}
prizeTotal: number
// Resolution = which ID the bounty went to
resolution?: string | 'MKT' | 'CANCEL'
}
export type outcomeType = AnyOutcomeType['outcomeType']
export type resolution = 'YES' | 'NO' | 'MKT' | 'CANCEL'
export const RESOLUTIONS = ['YES', 'NO', 'MKT', 'CANCEL'] as const
@ -136,6 +150,7 @@ export const OUTCOME_TYPES = [
'FREE_RESPONSE',
'PSEUDO_NUMERIC',
'NUMERIC',
'BOUNTY',
] as const
export const MAX_QUESTION_LENGTH = 480

View File

@ -108,6 +108,19 @@ function NewContract(props: { creator: User; params?: NewQuestionParams }) {
setQuestion(params?.q ?? '')
}, [params?.q])
const questionLabel = outcomeType === 'BOUNTY' ? 'Bounty' : 'Question'
const placeholders = {
BINARY: 'e.g. Will the Democrats win the 2024 US presidential election?',
MULTIPLE_CHOICE:
'e.g. Which basketball team will be the March Madness champion?',
FREE_RESPONSE: 'e.g. What programming language should I learn next?',
NUMERIC: '', // Numeric type is deprecated
PSEUDO_NUMERIC:
'e.g. How many people will show up to Taco Tuesday this week?',
BOUNTY: 'e.g. Add Dark Mode to Manifold Markets',
}
const placeholder = placeholders[outcomeType] ?? placeholders['BINARY']
const [ante, _setAnte] = useState(FIXED_ANTE)
// If params.closeTime is set, extract out the specified date and time
@ -231,28 +244,8 @@ function NewContract(props: { creator: User; params?: NewQuestionParams }) {
return (
<div>
<form>
<div className="form-control w-full">
<label className="label">
<span className="mb-1">
Question<span className={'text-red-700'}>*</span>
</span>
</label>
<Textarea
placeholder="e.g. Will the Democrats win the 2024 US presidential election?"
className="input input-bordered resize-none"
autoFocus
maxLength={MAX_QUESTION_LENGTH}
value={question}
onChange={(e) => setQuestion(e.target.value || '')}
/>
</div>
</form>
<Spacer h={6} />
<label className="label">
<span className="mb-1">Answer type</span>
<span className="mb-1">Market type</span>
</label>
<ChoicesToggleGroup
currentChoice={outcomeType}
@ -269,6 +262,7 @@ function NewContract(props: { creator: User; params?: NewQuestionParams }) {
'Multiple choice': 'MULTIPLE_CHOICE',
'Free response': 'FREE_RESPONSE',
Numeric: 'PSEUDO_NUMERIC',
Bounty: 'BOUNTY',
}}
isSubmitting={isSubmitting}
className={'col-span-4'}
@ -281,6 +275,27 @@ function NewContract(props: { creator: User; params?: NewQuestionParams }) {
<Spacer h={6} />
<form>
<div className="form-control w-full">
<label className="label">
<span className="mb-1">
{questionLabel}
<span className={'text-red-700'}>*</span>
</span>
</label>
<Textarea
placeholder={placeholder}
className="input input-bordered resize-none"
autoFocus
maxLength={MAX_QUESTION_LENGTH}
value={question}
onChange={(e) => setQuestion(e.target.value || '')}
/>
</div>
</form>
<Spacer h={6} />
{outcomeType === 'MULTIPLE_CHOICE' && (
<MultipleChoiceAnswers answers={answers} setAnswers={setAnswers} />
)}
@ -377,7 +392,7 @@ function NewContract(props: { creator: User; params?: NewQuestionParams }) {
<div className="form-control mb-1 items-start">
<label className="label mb-1 gap-2">
<span>Question closes in</span>
<span>{questionLabel} closes in</span>
<InfoTooltip text="Betting will be halted after this time (local timezone)." />
</label>
<Row className={'w-full items-center gap-2'}>
@ -433,7 +448,7 @@ function NewContract(props: { creator: User; params?: NewQuestionParams }) {
<Row className="items-end justify-between">
<div className="form-control mb-1 items-start">
<label className="label mb-1 gap-2">
<span>Cost</span>
<span>{outcomeType === 'BOUNTY' ? 'Initial Bounty' : 'Cost'}</span>
<InfoTooltip
text={`Cost to create your question. This amount is used to subsidize betting.`}
/>