outcome label

This commit is contained in:
mantikoros 2022-05-12 16:52:37 -04:00
parent 39b745b25a
commit 17fca14084
4 changed files with 24 additions and 1 deletions

View File

@ -74,6 +74,17 @@ export const getMappedBucket = (value: number, contract: NumericContract) => {
return `${bucket}`
}
export const getValueFromBucket = (
bucket: string,
contract: NumericContract
) => {
const { bucketCount, min, max } = contract
const index = parseInt(bucket)
const value = min + (index / bucketCount) * (max - min)
const rounded = Math.round(value * 1e4) / 1e4
return rounded
}
export function getDpmOutcomeProbabilityAfterBet(
totalShares: {
[outcome: string]: number

View File

@ -48,7 +48,7 @@ export type Contract = FullContract<
>
export type BinaryContract = FullContract<DPM | CPMM, Binary>
export type FreeResponseContract = FullContract<DPM | CPMM, FreeResponse>
export type NumericContract = FullContract<DPM, Numeric>
export type NumericContract = FullContract<any, Numeric>
export type DPM = {
mechanism: 'dpm-2'

View File

@ -4,6 +4,7 @@ import { DOMAIN, PROJECT_ID } from 'common/envs/constants'
import { Answer } from 'common/answer'
import { Bet } from 'common/bet'
import { getProbability } from 'common/calculate'
import { getValueFromBucket } from 'common/calculate-dpm'
import { Comment } from 'common/comment'
import { Contract, FreeResponseContract } from 'common/contract'
import { DPM_CREATOR_FEE } from 'common/fees'
@ -105,6 +106,9 @@ const toDisplayResolution = (
if (resolution === 'MKT' && resolutions) return 'MULTI'
if (resolution === 'CANCEL') return 'N/A'
if (contract.outcomeType === 'NUMERIC')
return getValueFromBucket(resolution, contract).toString()
const answer = (contract as FreeResponseContract).answers?.find(
(a) => a.id === resolution
)

View File

@ -1,6 +1,7 @@
import clsx from 'clsx'
import { Answer } from 'common/answer'
import { getProbability } from 'common/calculate'
import { getValueFromBucket } from 'common/calculate-dpm'
import {
Binary,
Contract,
@ -23,6 +24,13 @@ export function OutcomeLabel(props: {
if (contract.outcomeType === 'BINARY')
return <BinaryOutcomeLabel outcome={outcome as any} />
if (contract.outcomeType === 'NUMERIC')
return (
<span className="text-indigo-500">
{getValueFromBucket(outcome, contract)}
</span>
)
return (
<FreeResponseOutcomeLabel
contract={contract as FullContract<DPM, FreeResponse>}