outcome label
This commit is contained in:
parent
39b745b25a
commit
17fca14084
|
@ -74,6 +74,17 @@ export const getMappedBucket = (value: number, contract: NumericContract) => {
|
||||||
return `${bucket}`
|
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(
|
export function getDpmOutcomeProbabilityAfterBet(
|
||||||
totalShares: {
|
totalShares: {
|
||||||
[outcome: string]: number
|
[outcome: string]: number
|
||||||
|
|
|
@ -48,7 +48,7 @@ export type Contract = FullContract<
|
||||||
>
|
>
|
||||||
export type BinaryContract = FullContract<DPM | CPMM, Binary>
|
export type BinaryContract = FullContract<DPM | CPMM, Binary>
|
||||||
export type FreeResponseContract = FullContract<DPM | CPMM, FreeResponse>
|
export type FreeResponseContract = FullContract<DPM | CPMM, FreeResponse>
|
||||||
export type NumericContract = FullContract<DPM, Numeric>
|
export type NumericContract = FullContract<any, Numeric>
|
||||||
|
|
||||||
export type DPM = {
|
export type DPM = {
|
||||||
mechanism: 'dpm-2'
|
mechanism: 'dpm-2'
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { DOMAIN, PROJECT_ID } from 'common/envs/constants'
|
||||||
import { Answer } from 'common/answer'
|
import { Answer } from 'common/answer'
|
||||||
import { Bet } from 'common/bet'
|
import { Bet } from 'common/bet'
|
||||||
import { getProbability } from 'common/calculate'
|
import { getProbability } from 'common/calculate'
|
||||||
|
import { getValueFromBucket } from 'common/calculate-dpm'
|
||||||
import { Comment } from 'common/comment'
|
import { Comment } from 'common/comment'
|
||||||
import { Contract, FreeResponseContract } from 'common/contract'
|
import { Contract, FreeResponseContract } from 'common/contract'
|
||||||
import { DPM_CREATOR_FEE } from 'common/fees'
|
import { DPM_CREATOR_FEE } from 'common/fees'
|
||||||
|
@ -105,6 +106,9 @@ const toDisplayResolution = (
|
||||||
if (resolution === 'MKT' && resolutions) return 'MULTI'
|
if (resolution === 'MKT' && resolutions) return 'MULTI'
|
||||||
if (resolution === 'CANCEL') return 'N/A'
|
if (resolution === 'CANCEL') return 'N/A'
|
||||||
|
|
||||||
|
if (contract.outcomeType === 'NUMERIC')
|
||||||
|
return getValueFromBucket(resolution, contract).toString()
|
||||||
|
|
||||||
const answer = (contract as FreeResponseContract).answers?.find(
|
const answer = (contract as FreeResponseContract).answers?.find(
|
||||||
(a) => a.id === resolution
|
(a) => a.id === resolution
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { Answer } from 'common/answer'
|
import { Answer } from 'common/answer'
|
||||||
import { getProbability } from 'common/calculate'
|
import { getProbability } from 'common/calculate'
|
||||||
|
import { getValueFromBucket } from 'common/calculate-dpm'
|
||||||
import {
|
import {
|
||||||
Binary,
|
Binary,
|
||||||
Contract,
|
Contract,
|
||||||
|
@ -23,6 +24,13 @@ export function OutcomeLabel(props: {
|
||||||
if (contract.outcomeType === 'BINARY')
|
if (contract.outcomeType === 'BINARY')
|
||||||
return <BinaryOutcomeLabel outcome={outcome as any} />
|
return <BinaryOutcomeLabel outcome={outcome as any} />
|
||||||
|
|
||||||
|
if (contract.outcomeType === 'NUMERIC')
|
||||||
|
return (
|
||||||
|
<span className="text-indigo-500">
|
||||||
|
{getValueFromBucket(outcome, contract)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FreeResponseOutcomeLabel
|
<FreeResponseOutcomeLabel
|
||||||
contract={contract as FullContract<DPM, FreeResponse>}
|
contract={contract as FullContract<DPM, FreeResponse>}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user