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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ import { FIXED_ANTE, MINIMUM_ANTE } from 'common/antes'
import { InfoTooltip } from 'web/components/info-tooltip' import { InfoTooltip } from 'web/components/info-tooltip'
import { Page } from 'web/components/page' import { Page } from 'web/components/page'
import { Row } from 'web/components/layout/row' 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 { formatMoney } from 'common/util/format'
import { useHasCreatedContractToday } from 'web/hooks/use-has-created-contract-today' import { useHasCreatedContractToday } from 'web/hooks/use-has-created-contract-today'
import { removeUndefinedProps } from 'common/util/object' 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 [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
const [resolutionType, setResolutionType] = useState<resolutionType>('MANUAL') const [resolutionType, setResolutionType] = useState<resolutionType>('MANUAL')
const [automaticResolution, setAutomaticResolution] = useState<resolution>('YES') const [automaticResolution, setAutomaticResolution] = useState<resolution>('CANCEL')
const [initialProb, setInitialProb] = useState(50) const [initialProb, setInitialProb] = useState(50)
const [minString, setMinString] = useState('') const [minString, setMinString] = useState('')
const [maxString, setMaxString] = useState('') const [maxString, setMaxString] = useState('')
@ -97,7 +97,7 @@ export function NewContract(props: { question: string; tag?: string }) {
const [isSubmitting, setIsSubmitting] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false)
const closeTime = closeDate ? dayjs(closeDate).valueOf() : undefined 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 const balance = creator?.balance || 0
@ -154,7 +154,7 @@ export function NewContract(props: { question: string; tag?: string }) {
min, min,
max, max,
automaticResolution, automaticResolution,
resolutionTime automaticResolutionTime
}) })
) )
await router.push(contractPath(result as Contract)) await router.push(contractPath(result as Contract))
@ -422,7 +422,7 @@ export function NewContract(props: { question: string; tag?: string }) {
<ChoicesToggleGroup <ChoicesToggleGroup
currentChoice={automaticResolution} currentChoice={automaticResolution}
setChoice={setAutomaticResolution} setChoice={setAutomaticResolution}
choices={['YES', 'NO', 'MKT', 'CANCEL']} choices={RESOLUTIONS}
titles={['YES', 'NO', 'PROB', 'N/A']} titles={['YES', 'NO', 'PROB', 'N/A']}
isSubmitting={isSubmitting} isSubmitting={isSubmitting}
/> />