contract type
This commit is contained in:
parent
b05d8b3d3c
commit
d91abf4faf
|
@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||||
import { XIcon } from '@heroicons/react/solid'
|
import { XIcon } from '@heroicons/react/solid'
|
||||||
|
|
||||||
import { Answer } from '../../../common/answer'
|
import { Answer } from '../../../common/answer'
|
||||||
import { Contract } from '../../../common/contract'
|
import { DPM, FreeResponse, FullContract } from '../../../common/contract'
|
||||||
import { AmountInput } from '../amount-input'
|
import { AmountInput } from '../amount-input'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { placeBet } from '../../lib/firebase/api-call'
|
import { placeBet } from '../../lib/firebase/api-call'
|
||||||
|
@ -28,7 +28,7 @@ import { Bet } from '../../../common/bet'
|
||||||
|
|
||||||
export function AnswerBetPanel(props: {
|
export function AnswerBetPanel(props: {
|
||||||
answer: Answer
|
answer: Answer
|
||||||
contract: Contract
|
contract: FullContract<DPM, FreeResponse>
|
||||||
closePanel: () => void
|
closePanel: () => void
|
||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import _ from 'lodash'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
import { Answer } from '../../../common/answer'
|
import { Answer } from '../../../common/answer'
|
||||||
import { Contract } from '../../../common/contract'
|
import { DPM, FreeResponse, FullContract } from '../../../common/contract'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
import { Avatar } from '../avatar'
|
import { Avatar } from '../avatar'
|
||||||
|
@ -18,7 +18,7 @@ import { Linkify } from '../linkify'
|
||||||
|
|
||||||
export function AnswerItem(props: {
|
export function AnswerItem(props: {
|
||||||
answer: Answer
|
answer: Answer
|
||||||
contract: Contract
|
contract: FullContract<DPM, FreeResponse>
|
||||||
showChoice: 'radio' | 'checkbox' | undefined
|
showChoice: 'radio' | 'checkbox' | undefined
|
||||||
chosenProb: number | undefined
|
chosenProb: number | undefined
|
||||||
totalChosenProb?: number
|
totalChosenProb?: number
|
||||||
|
|
|
@ -2,7 +2,7 @@ import clsx from 'clsx'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
import { Contract } from '../../../common/contract'
|
import { DPM, FreeResponse, FullContract } from '../../../common/contract'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { resolveMarket } from '../../lib/firebase/api-call'
|
import { resolveMarket } from '../../lib/firebase/api-call'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
|
@ -11,7 +11,7 @@ import { ResolveConfirmationButton } from '../confirmation-button'
|
||||||
import { removeUndefinedProps } from '../../../common/util/object'
|
import { removeUndefinedProps } from '../../../common/util/object'
|
||||||
|
|
||||||
export function AnswerResolvePanel(props: {
|
export function AnswerResolvePanel(props: {
|
||||||
contract: Contract
|
contract: FullContract<DPM, FreeResponse>
|
||||||
resolveOption: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined
|
resolveOption: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined
|
||||||
setResolveOption: (
|
setResolveOption: (
|
||||||
option: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined
|
option: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined
|
||||||
|
|
|
@ -2,7 +2,7 @@ import _ from 'lodash'
|
||||||
import { useLayoutEffect, useState } from 'react'
|
import { useLayoutEffect, useState } from 'react'
|
||||||
|
|
||||||
import { Answer } from '../../../common/answer'
|
import { Answer } from '../../../common/answer'
|
||||||
import { Contract } from '../../../common/contract'
|
import { DPM, FreeResponse, FullContract } from '../../../common/contract'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { formatPercent } from '../../../common/util/format'
|
import { formatPercent } from '../../../common/util/format'
|
||||||
import { useUser } from '../../hooks/use-user'
|
import { useUser } from '../../hooks/use-user'
|
||||||
|
@ -13,7 +13,10 @@ import { AnswerItem } from './answer-item'
|
||||||
import { CreateAnswerPanel } from './create-answer-panel'
|
import { CreateAnswerPanel } from './create-answer-panel'
|
||||||
import { AnswerResolvePanel } from './answer-resolve-panel'
|
import { AnswerResolvePanel } from './answer-resolve-panel'
|
||||||
|
|
||||||
export function AnswersPanel(props: { contract: Contract; answers: Answer[] }) {
|
export function AnswersPanel(props: {
|
||||||
|
contract: FullContract<DPM, FreeResponse>
|
||||||
|
answers: Answer[]
|
||||||
|
}) {
|
||||||
const { contract } = props
|
const { contract } = props
|
||||||
const { creatorId, resolution, resolutions, totalBets } = contract
|
const { creatorId, resolution, resolutions, totalBets } = contract
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,12 @@ import _ from 'lodash'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import Textarea from 'react-expanding-textarea'
|
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 { AmountInput } from '../amount-input'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { createAnswer } from '../../lib/firebase/api-call'
|
import { createAnswer } from '../../lib/firebase/api-call'
|
||||||
|
@ -23,7 +28,9 @@ import {
|
||||||
import { firebaseLogin } from '../../lib/firebase/users'
|
import { firebaseLogin } from '../../lib/firebase/users'
|
||||||
import { Bet } from '../../../common/bet'
|
import { Bet } from '../../../common/bet'
|
||||||
|
|
||||||
export function CreateAnswerPanel(props: { contract: Contract }) {
|
export function CreateAnswerPanel(props: {
|
||||||
|
contract: FullContract<DPM, FreeResponse>
|
||||||
|
}) {
|
||||||
const { contract } = props
|
const { contract } = props
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const [text, setText] = useState('')
|
const [text, setText] = useState('')
|
||||||
|
|
|
@ -42,6 +42,7 @@ import BetRow from './bet-row'
|
||||||
import { parseTags } from '../../common/util/parse'
|
import { parseTags } from '../../common/util/parse'
|
||||||
import { Avatar } from './avatar'
|
import { Avatar } from './avatar'
|
||||||
import { useAdmin } from '../hooks/use-admin'
|
import { useAdmin } from '../hooks/use-admin'
|
||||||
|
import { FreeResponse, FullContract } from '../../common/contract'
|
||||||
|
|
||||||
function FeedComment(props: {
|
function FeedComment(props: {
|
||||||
activityItem: any
|
activityItem: any
|
||||||
|
@ -384,7 +385,10 @@ function FeedDescription(props: { contract: Contract }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function FeedAnswer(props: { contract: Contract; outcome: string }) {
|
function FeedAnswer(props: {
|
||||||
|
contract: FullContract<any, FreeResponse>
|
||||||
|
outcome: string
|
||||||
|
}) {
|
||||||
const { contract, outcome } = props
|
const { contract, outcome } = props
|
||||||
const answer = contract?.answers?.[Number(outcome) - 1]
|
const answer = contract?.answers?.[Number(outcome) - 1]
|
||||||
if (!answer) return null
|
if (!answer) return null
|
||||||
|
|
|
@ -17,9 +17,10 @@ import _ from 'lodash'
|
||||||
|
|
||||||
import { app } from './init'
|
import { app } from './init'
|
||||||
import { getValues, listenForValue, listenForValues } from './utils'
|
import { getValues, listenForValue, listenForValues } from './utils'
|
||||||
import { Contract } from '../../../common/contract'
|
import { Binary, Contract, FullContract } from '../../../common/contract'
|
||||||
import { getProbability } from '../../../common/calculate'
|
import { getProbability } from '../../../common/calculate'
|
||||||
import { createRNG, shuffle } from '../../../common/util/random'
|
import { createRNG, shuffle } from '../../../common/util/random'
|
||||||
|
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
||||||
export type { Contract }
|
export type { Contract }
|
||||||
|
|
||||||
export function contractPath(contract: Contract) {
|
export function contractPath(contract: Contract) {
|
||||||
|
@ -40,12 +41,15 @@ export function contractMetrics(contract: Contract) {
|
||||||
return { truePool, createdDate, resolvedDate }
|
return { truePool, createdDate, resolvedDate }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBinaryProbPercent(contract: Contract) {
|
export function getBinaryProbPercent(contract: FullContract<any, Binary>) {
|
||||||
const { totalShares, resolutionProbability } = contract
|
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) + '%'
|
const probPercent = Math.round(prob * 100) + '%'
|
||||||
|
|
||||||
return probPercent
|
return probPercent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user