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
isResolved: boolean
resolutionTime?: number // When the contract creator resolved the market
resolution?: string
resolutionTime?: number // When the market is resolved
resolution?: resolution
resolutionType: 'manual' | 'combined'
automaticResolutionTime?: number
closeEmailsSent?: number
@ -72,7 +73,7 @@ export type Binary = {
outcomeType: 'BINARY'
initialProbability: number
resolutionProbability?: number // Used for BINARY markets resolved to MKT
resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL'
resolution?: resolution
}
export type Multi = {
@ -99,6 +100,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 OUTCOME_TYPES = ['BINARY', 'MULTI', 'FREE_RESPONSE', 'NUMERIC']
export const RESOLUTION_TYPES = ['MANUAL', 'COMBINED']

View File

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

View File

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

View File

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

View File

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