From 4ddeaa1241ccd3ee602129a3f4f496235b6c7c65 Mon Sep 17 00:00:00 2001 From: Milli Date: Wed, 25 May 2022 20:27:26 +0200 Subject: [PATCH] added union type for resolution --- common/contract.ts | 8 +++++--- common/new-contract.ts | 1 + web/components/outcome-label.tsx | 7 ++++--- web/components/resolution-panel.tsx | 6 ++---- web/components/yes-no-selector.tsx | 5 +++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/common/contract.ts b/common/contract.ts index 0ba3624b..898cd103 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -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'] diff --git a/common/new-contract.ts b/common/new-contract.ts index 0f7db794..4476a522 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -65,6 +65,7 @@ export function getNewContract( createdTime: Date.now(), closeTime, resolutionType: 'manual', + resolution: undefined, volume: 0, volume24Hours: 0, diff --git a/web/components/outcome-label.tsx b/web/components/outcome-label.tsx index 394fb6ae..39f3be84 100644 --- a/web/components/outcome-label.tsx +++ b/web/components/outcome-label.tsx @@ -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 - resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT' + resolution: resolution }) { const { contract, resolution } = props diff --git a/web/components/resolution-panel.tsx b/web/components/resolution-panel.tsx index d37e9084..eb207595 100644 --- a/web/components/resolution-panel.tsx +++ b/web/components/resolution-panel.tsx @@ -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() const [prob, setProb] = useState(getProbability(contract) * 100) diff --git a/web/components/yes-no-selector.tsx b/web/components/yes-no-selector.tsx index 38723060..ff4a18c5 100644 --- a/web/components/yes-no-selector.tsx +++ b/web/components/yes-no-selector.tsx @@ -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 }) {