created const for resolutions

This commit is contained in:
Milli 2022-05-26 14:57:59 +02:00
parent 66971ed204
commit a618a43071
6 changed files with 34 additions and 12 deletions

View File

@ -28,9 +28,9 @@ export type FullContract<
isResolved: boolean
resolutionTime?: number // When the market is resolved
resolution?: string
resolutionType: 'manual' | 'combined'
automaticResolutionTime?: number
resolutionType: resolutionType
automaticResolution?: resolution
automaticResolutionTime?: number
closeEmailsSent?: number
@ -102,6 +102,7 @@ export type Numeric = {
export type outcomeType = 'BINARY' | 'MULTI' | 'FREE_RESPONSE' | 'NUMERIC'
export type resolutionType = 'MANUAL' | 'COMBINED'
export type resolution = 'YES' | 'NO' | 'MKT' | 'CANCEL'
export const RESOLUTIONS = ['YES' , 'NO' , 'MKT' , 'CANCEL']
export const OUTCOME_TYPES = ['BINARY', 'MULTI', 'FREE_RESPONSE', 'NUMERIC']
export const RESOLUTION_TYPES = ['MANUAL', 'COMBINED']

View File

@ -8,6 +8,7 @@ import {
FreeResponse,
Numeric,
outcomeType,
resolution,
resolutionType,
} from './contract'
import { User } from './user'
@ -27,6 +28,8 @@ export function getNewContract(
closeTime: number,
extraTags: string[],
resolutionType: resolutionType,
automaticResolution: resolution,
automaticResolutionTime: number,
// used for numeric markets
bucketCount: number,
@ -64,8 +67,9 @@ export function getNewContract(
isResolved: false,
createdTime: Date.now(),
closeTime,
resolutionType: 'manual',
resolution: undefined,
resolutionType,
automaticResolution,
automaticResolutionTime,
volume: 0,
volume24Hours: 0,

View File

@ -12,6 +12,7 @@ import {
MAX_TAG_LENGTH,
Numeric,
OUTCOME_TYPES,
RESOLUTIONS,
RESOLUTION_TYPES
} from '../../common/contract'
import { slugify } from '../../common/util/slugify'
@ -46,6 +47,8 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => {
max,
manaLimitPerUser,
resolutionType,
automaticResolution,
automaticResolutionTime
} = req.body || {}
if (!question || typeof question != 'string')
@ -94,6 +97,17 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => {
if (!RESOLUTION_TYPES.includes(resolutionType))
throw new APIError(400, 'Invalid resolutionType')
automaticResolution = automaticResolution ?? 'MANUAL'
if (!RESOLUTIONS.includes(automaticResolution))
throw new APIError(400, 'Invalid automaticResolution')
if (automaticResolution === 'MANUAL' && automaticResolutionTime)
throw new APIError(400, 'automaticResolutionTime specified even tho automaticResolution is \'MANUAL\'')
if (automaticResolutionTime && automaticResolutionTime < closeTime)
throw new APIError(400, 'resolutionTime < closeTime')
// Uses utc time on server:
const yesterday = new Date()
yesterday.setUTCDate(yesterday.getUTCDate() - 1)
@ -143,6 +157,8 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => {
closeTime,
tags ?? [],
resolutionType,
automaticResolution,
automaticResolutionTime,
NUMERIC_BUCKET_COUNT,
min ?? 0,
max ?? 0,

View File

@ -2,7 +2,7 @@ import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import { difference, uniq, mapValues, groupBy, sumBy } from 'lodash'
import { Contract } from '../../common/contract'
import { Contract, RESOLUTIONS } from '../../common/contract'
import { User } from '../../common/user'
import { Bet } from '../../common/bet'
import { getUser, isProd, payUser } from './utils'
@ -42,7 +42,7 @@ export const resolveMarket = functions
const { creatorId, outcomeType, closeTime } = contract
if (outcomeType === 'BINARY') {
if (!['YES', 'NO', 'MKT', 'CANCEL'].includes(outcome))
if (!RESOLUTIONS.includes(outcome))
return { status: 'error', message: 'Invalid outcome' }
} else if (outcomeType === 'FREE_RESPONSE') {
if (

View File

@ -13,6 +13,7 @@ import {
Binary,
NumericContract,
FreeResponseContract,
resolution,
} from 'common/contract'
import {
formatLargeNumber,
@ -269,7 +270,7 @@ export function getColor(contract: Contract, previewProb?: number) {
const { resolution } = contract
if (resolution) {
return (
OUTCOME_TO_COLOR[resolution as 'YES' | 'NO' | 'CANCEL' | 'MKT'] ??
OUTCOME_TO_COLOR[resolution as resolution] ??
// If resolved to a FR answer, use 'primary'
'primary'
)

View File

@ -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, resolution, resolutionType } from 'common/contract'
import { MAX_DESCRIPTION_LENGTH, outcomeType, RESOLUTIONS, resolution, 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'
@ -66,7 +66,7 @@ export function NewContract(props: { question: string; tag?: string }) {
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
const [resolutionType, setResolutionType] = useState<resolutionType>('MANUAL')
const [automaticResolution, setAutomaticResolution] = useState<resolution>('YES')
const [automaticResolution, setAutomaticResolution] = useState<resolution>('CANCEL')
const [initialProb, setInitialProb] = useState(50)
const [minString, setMinString] = useState('')
const [maxString, setMaxString] = useState('')
@ -97,7 +97,7 @@ export function NewContract(props: { question: string; tag?: string }) {
const [isSubmitting, setIsSubmitting] = useState(false)
const closeTime = closeDate ? dayjs(closeDate).valueOf() : undefined
const resolutionTime = resolutionDate ? dayjs(resolutionDate).valueOf() : undefined
const automaticResolutionTime = resolutionDate ? dayjs(resolutionDate).valueOf() : undefined
const balance = creator?.balance || 0
@ -154,7 +154,7 @@ export function NewContract(props: { question: string; tag?: string }) {
min,
max,
automaticResolution,
resolutionTime
automaticResolutionTime
})
)
await router.push(contractPath(result as Contract))
@ -422,7 +422,7 @@ export function NewContract(props: { question: string; tag?: string }) {
<ChoicesToggleGroup
currentChoice={automaticResolution}
setChoice={setAutomaticResolution}
choices={['YES', 'NO', 'MKT', 'CANCEL']}
choices={RESOLUTIONS}
titles={['YES', 'NO', 'PROB', 'N/A']}
isSubmitting={isSubmitting}
/>