From d91abf4faf59b7d7ebb9f0329812462c979609e4 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Wed, 2 Mar 2022 17:02:38 -0500 Subject: [PATCH] contract type --- web/components/answers/answer-bet-panel.tsx | 4 ++-- web/components/answers/answer-item.tsx | 4 ++-- web/components/answers/answer-resolve-panel.tsx | 4 ++-- web/components/answers/answers-panel.tsx | 7 +++++-- web/components/answers/create-answer-panel.tsx | 11 +++++++++-- web/components/contract-feed.tsx | 6 +++++- web/lib/firebase/contracts.ts | 14 +++++++++----- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/web/components/answers/answer-bet-panel.tsx b/web/components/answers/answer-bet-panel.tsx index 26939b35..bddaa609 100644 --- a/web/components/answers/answer-bet-panel.tsx +++ b/web/components/answers/answer-bet-panel.tsx @@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from 'react' import { XIcon } from '@heroicons/react/solid' import { Answer } from '../../../common/answer' -import { Contract } from '../../../common/contract' +import { DPM, FreeResponse, FullContract } from '../../../common/contract' import { AmountInput } from '../amount-input' import { Col } from '../layout/col' import { placeBet } from '../../lib/firebase/api-call' @@ -28,7 +28,7 @@ import { Bet } from '../../../common/bet' export function AnswerBetPanel(props: { answer: Answer - contract: Contract + contract: FullContract closePanel: () => void className?: string }) { diff --git a/web/components/answers/answer-item.tsx b/web/components/answers/answer-item.tsx index 46fd0ead..7919f84d 100644 --- a/web/components/answers/answer-item.tsx +++ b/web/components/answers/answer-item.tsx @@ -3,7 +3,7 @@ import _ from 'lodash' import { useState } from 'react' import { Answer } from '../../../common/answer' -import { Contract } from '../../../common/contract' +import { DPM, FreeResponse, FullContract } from '../../../common/contract' import { Col } from '../layout/col' import { Row } from '../layout/row' import { Avatar } from '../avatar' @@ -18,7 +18,7 @@ import { Linkify } from '../linkify' export function AnswerItem(props: { answer: Answer - contract: Contract + contract: FullContract showChoice: 'radio' | 'checkbox' | undefined chosenProb: number | undefined totalChosenProb?: number diff --git a/web/components/answers/answer-resolve-panel.tsx b/web/components/answers/answer-resolve-panel.tsx index b1146e19..a1f8b1d1 100644 --- a/web/components/answers/answer-resolve-panel.tsx +++ b/web/components/answers/answer-resolve-panel.tsx @@ -2,7 +2,7 @@ import clsx from 'clsx' import _ from 'lodash' import { useState } from 'react' -import { Contract } from '../../../common/contract' +import { DPM, FreeResponse, FullContract } from '../../../common/contract' import { Col } from '../layout/col' import { resolveMarket } from '../../lib/firebase/api-call' import { Row } from '../layout/row' @@ -11,7 +11,7 @@ import { ResolveConfirmationButton } from '../confirmation-button' import { removeUndefinedProps } from '../../../common/util/object' export function AnswerResolvePanel(props: { - contract: Contract + contract: FullContract resolveOption: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined setResolveOption: ( option: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined diff --git a/web/components/answers/answers-panel.tsx b/web/components/answers/answers-panel.tsx index 5fc30595..3781311a 100644 --- a/web/components/answers/answers-panel.tsx +++ b/web/components/answers/answers-panel.tsx @@ -2,7 +2,7 @@ import _ from 'lodash' import { useLayoutEffect, useState } from 'react' import { Answer } from '../../../common/answer' -import { Contract } from '../../../common/contract' +import { DPM, FreeResponse, FullContract } from '../../../common/contract' import { Col } from '../layout/col' import { formatPercent } from '../../../common/util/format' import { useUser } from '../../hooks/use-user' @@ -13,7 +13,10 @@ import { AnswerItem } from './answer-item' import { CreateAnswerPanel } from './create-answer-panel' import { AnswerResolvePanel } from './answer-resolve-panel' -export function AnswersPanel(props: { contract: Contract; answers: Answer[] }) { +export function AnswersPanel(props: { + contract: FullContract + answers: Answer[] +}) { const { contract } = props const { creatorId, resolution, resolutions, totalBets } = contract diff --git a/web/components/answers/create-answer-panel.tsx b/web/components/answers/create-answer-panel.tsx index 2dbadd9e..dc21dcc7 100644 --- a/web/components/answers/create-answer-panel.tsx +++ b/web/components/answers/create-answer-panel.tsx @@ -3,7 +3,12 @@ import _ from 'lodash' import { useState } from 'react' import Textarea from 'react-expanding-textarea' -import { Contract } from '../../../common/contract' +import { + Contract, + DPM, + FreeResponse, + FullContract, +} from '../../../common/contract' import { AmountInput } from '../amount-input' import { Col } from '../layout/col' import { createAnswer } from '../../lib/firebase/api-call' @@ -23,7 +28,9 @@ import { import { firebaseLogin } from '../../lib/firebase/users' import { Bet } from '../../../common/bet' -export function CreateAnswerPanel(props: { contract: Contract }) { +export function CreateAnswerPanel(props: { + contract: FullContract +}) { const { contract } = props const user = useUser() const [text, setText] = useState('') diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx index 5a3be62f..faafa2b3 100644 --- a/web/components/contract-feed.tsx +++ b/web/components/contract-feed.tsx @@ -42,6 +42,7 @@ import BetRow from './bet-row' import { parseTags } from '../../common/util/parse' import { Avatar } from './avatar' import { useAdmin } from '../hooks/use-admin' +import { FreeResponse, FullContract } from '../../common/contract' function FeedComment(props: { activityItem: any @@ -384,7 +385,10 @@ function FeedDescription(props: { contract: Contract }) { ) } -function FeedAnswer(props: { contract: Contract; outcome: string }) { +function FeedAnswer(props: { + contract: FullContract + outcome: string +}) { const { contract, outcome } = props const answer = contract?.answers?.[Number(outcome) - 1] if (!answer) return null diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index eb1b65e1..362d8139 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -17,9 +17,10 @@ import _ from 'lodash' import { app } from './init' import { getValues, listenForValue, listenForValues } from './utils' -import { Contract } from '../../../common/contract' +import { Binary, Contract, FullContract } from '../../../common/contract' import { getProbability } from '../../../common/calculate' import { createRNG, shuffle } from '../../../common/util/random' +import { getCpmmProbability } from '../../../common/calculate-cpmm' export type { Contract } export function contractPath(contract: Contract) { @@ -40,12 +41,15 @@ export function contractMetrics(contract: Contract) { return { truePool, createdDate, resolvedDate } } -export function getBinaryProbPercent(contract: Contract) { - const { totalShares, resolutionProbability } = contract +export function getBinaryProbPercent(contract: FullContract) { + const { totalShares, pool, resolutionProbability, mechanism } = contract + + const prob = + resolutionProbability ?? mechanism === 'cpmm-1' + ? getCpmmProbability(pool) + : getProbability(totalShares) - const prob = resolutionProbability ?? getProbability(totalShares) const probPercent = Math.round(prob * 100) + '%' - return probPercent }