From 645e891b73f439a98f9cb4544e6a9d6c289a4341 Mon Sep 17 00:00:00 2001 From: Milli Date: Tue, 24 May 2022 18:47:21 +0200 Subject: [PATCH] Added radio buttons to market creation (non functional) --- common/contract.ts | 3 +++ common/new-contract.ts | 2 ++ functions/src/create-contract.ts | 10 ++++++- web/pages/create.tsx | 45 +++++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/common/contract.ts b/common/contract.ts index a8f2bd42..e7bb7a60 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -28,6 +28,7 @@ export type FullContract< isResolved: boolean resolutionTime?: number // When the contract creator resolved the market resolution?: string + resolutionType: 'manual' | 'combined' | 'automatic' closeEmailsSent?: number @@ -97,7 +98,9 @@ export type Numeric = { } export type outcomeType = 'BINARY' | 'MULTI' | 'FREE_RESPONSE' | 'NUMERIC' +export type resolutionType = 'MANUAL' | 'COMBINED' | 'AUTOMATIC' export const OUTCOME_TYPES = ['BINARY', 'MULTI', 'FREE_RESPONSE', 'NUMERIC'] +export const RESOLUTION_TYPES = ['MANUAL', 'COMBINED', 'AUTOMATIC'] export const MAX_QUESTION_LENGTH = 480 export const MAX_DESCRIPTION_LENGTH = 10000 diff --git a/common/new-contract.ts b/common/new-contract.ts index d658a943..bb4109f7 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -8,6 +8,7 @@ import { FreeResponse, Numeric, outcomeType, + resolutionType, } from './contract' import { User } from './user' import { parseTags } from './util/parse' @@ -25,6 +26,7 @@ export function getNewContract( ante: number, closeTime: number, extraTags: string[], + resolutionType: resolutionType, // used for numeric markets bucketCount: number, diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 485e3bb1..526b844a 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -12,6 +12,7 @@ import { MAX_TAG_LENGTH, Numeric, OUTCOME_TYPES, + RESOLUTION_TYPES } from '../../common/contract' import { slugify } from '../../common/util/slugify' import { randomString } from '../../common/util/random' @@ -44,6 +45,7 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => { min, max, manaLimitPerUser, + resolutionType, } = req.body || {} if (!question || typeof question != 'string') @@ -87,6 +89,11 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => { ) throw new APIError(400, 'Invalid initial probability') + resolutionType = resolutionType ?? 'MANUAL' + + if (!RESOLUTION_TYPES.includes(resolutionType)) + throw new APIError(400, 'Invalid resolutionType') + // Uses utc time on server: const yesterday = new Date() yesterday.setUTCDate(yesterday.getUTCDate() - 1) @@ -138,7 +145,8 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => { NUMERIC_BUCKET_COUNT, min ?? 0, max ?? 0, - manaLimitPerUser ?? 0 + manaLimitPerUser ?? 0, + resolutionType, ) if (!isFree && ante) await chargeUser(creator.id, ante, true) diff --git a/web/pages/create.tsx b/web/pages/create.tsx index 1e01d2da..1634c074 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -11,7 +11,7 @@ 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' -import { MAX_DESCRIPTION_LENGTH, outcomeType } from 'common/contract' +import { MAX_DESCRIPTION_LENGTH, outcomeType, resolutionType } from 'common/contract' import { formatMoney } from 'common/util/format' import { useHasCreatedContractToday } from 'web/hooks/use-has-created-contract-today' import { removeUndefinedProps } from 'common/util/object' @@ -64,6 +64,7 @@ export function NewContract(props: { question: string; tag?: string }) { }, []) const [outcomeType, setOutcomeType] = useState('BINARY') + const [resolutionType, setResolutionType] = useState('MANUAL') const [initialProb, setInitialProb] = useState(50) const [minString, setMinString] = useState('') const [maxString, setMaxString] = useState('') @@ -365,6 +366,48 @@ export function NewContract(props: { question: string; tag?: string }) { )} + + + + + + + +