added union type for resolution

This commit is contained in:
Milli 2022-05-25 20:27:26 +02:00
parent 9b6e551bad
commit 4ddeaa1241
5 changed files with 15 additions and 12 deletions

View File

@ -26,9 +26,10 @@ export type FullContract<
closeTime?: number // When no more trading is allowed closeTime?: number // When no more trading is allowed
isResolved: boolean isResolved: boolean
resolutionTime?: number // When the contract creator resolved the market resolutionTime?: number // When the market is resolved
resolution?: string resolution?: resolution
resolutionType: 'manual' | 'combined' resolutionType: 'manual' | 'combined'
automaticResolutionTime?: number
closeEmailsSent?: number closeEmailsSent?: number
@ -72,7 +73,7 @@ export type Binary = {
outcomeType: 'BINARY' outcomeType: 'BINARY'
initialProbability: number initialProbability: number
resolutionProbability?: number // Used for BINARY markets resolved to MKT resolutionProbability?: number // Used for BINARY markets resolved to MKT
resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL' resolution?: resolution
} }
export type Multi = { export type Multi = {
@ -99,6 +100,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 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

@ -65,6 +65,7 @@ export function getNewContract(
createdTime: Date.now(), createdTime: Date.now(),
closeTime, closeTime,
resolutionType: 'manual', resolutionType: 'manual',
resolution: undefined,
volume: 0, volume: 0,
volume24Hours: 0, volume24Hours: 0,

View File

@ -11,13 +11,14 @@ import {
FreeResponseContract, FreeResponseContract,
FullContract, FullContract,
NumericContract, NumericContract,
resolution,
} from 'common/contract' } from 'common/contract'
import { formatPercent } from 'common/util/format' import { formatPercent } from 'common/util/format'
import { ClientRender } from './client-render' import { ClientRender } from './client-render'
export function OutcomeLabel(props: { export function OutcomeLabel(props: {
contract: Contract contract: Contract
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' | string outcome: resolution | string
truncate: 'short' | 'long' | 'none' truncate: 'short' | 'long' | 'none'
value?: number value?: number
}) { }) {
@ -44,7 +45,7 @@ export function OutcomeLabel(props: {
} }
export function BinaryOutcomeLabel(props: { export function BinaryOutcomeLabel(props: {
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' outcome: resolution
}) { }) {
const { outcome } = props const { outcome } = props
@ -56,7 +57,7 @@ export function BinaryOutcomeLabel(props: {
export function BinaryContractOutcomeLabel(props: { export function BinaryContractOutcomeLabel(props: {
contract: FullContract<DPM | CPMM, Binary> contract: FullContract<DPM | CPMM, Binary>
resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT' resolution: resolution
}) { }) {
const { contract, resolution } = props const { contract, resolution } = props

View File

@ -10,7 +10,7 @@ import { resolveMarket } from 'web/lib/firebase/fn-call'
import { ProbabilitySelector } from './probability-selector' import { ProbabilitySelector } from './probability-selector'
import { DPM_CREATOR_FEE } from 'common/fees' import { DPM_CREATOR_FEE } from 'common/fees'
import { getProbability } from 'common/calculate' import { getProbability } from 'common/calculate'
import { Binary, CPMM, DPM, FullContract } from 'common/contract' import { Binary, CPMM, DPM, FullContract, resolution } from 'common/contract'
import { formatMoney } from 'common/util/format' import { formatMoney } from 'common/util/format'
export function ResolutionPanel(props: { export function ResolutionPanel(props: {
@ -30,9 +30,7 @@ export function ResolutionPanel(props: {
? `${DPM_CREATOR_FEE * 100}% of trader profits` ? `${DPM_CREATOR_FEE * 100}% of trader profits`
: `${formatMoney(contract.collectedFees.creatorFee)} in fees` : `${formatMoney(contract.collectedFees.creatorFee)} in fees`
const [outcome, setOutcome] = useState< const [outcome, setOutcome] = useState<resolution | undefined>()
'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined
>()
const [prob, setProb] = useState(getProbability(contract) * 100) const [prob, setProb] = useState(getProbability(contract) * 100)

View File

@ -3,6 +3,7 @@ import React from 'react'
import { formatMoney } from 'common/util/format' import { formatMoney } from 'common/util/format'
import { Col } from './layout/col' import { Col } from './layout/col'
import { Row } from './layout/row' import { Row } from './layout/row'
import { resolution } from 'common/contract'
export function YesNoSelector(props: { export function YesNoSelector(props: {
selected?: 'YES' | 'NO' selected?: 'YES' | 'NO'
@ -65,8 +66,8 @@ export function YesNoSelector(props: {
} }
export function YesNoCancelSelector(props: { export function YesNoCancelSelector(props: {
selected: 'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined selected: resolution | undefined
onSelect: (selected: 'YES' | 'NO' | 'MKT' | 'CANCEL') => void onSelect: (selected: resolution) => void
className?: string className?: string
btnClassName?: string btnClassName?: string
}) { }) {