Add most likely, least likely sort options
This commit is contained in:
parent
5f4908b072
commit
434c7b6b97
|
@ -7,6 +7,8 @@ import {
|
||||||
contractMetrics,
|
contractMetrics,
|
||||||
Contract,
|
Contract,
|
||||||
listContracts,
|
listContracts,
|
||||||
|
getBinaryProbPercent,
|
||||||
|
getBinaryProb,
|
||||||
} from '../lib/firebase/contracts'
|
} from '../lib/firebase/contracts'
|
||||||
import { User } from '../lib/firebase/users'
|
import { User } from '../lib/firebase/users'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
|
@ -14,6 +16,7 @@ import { SiteLink } from './site-link'
|
||||||
import { ContractCard } from './contract-card'
|
import { ContractCard } from './contract-card'
|
||||||
import { Sort, useQueryAndSortParams } from '../hooks/use-sort-and-query-params'
|
import { Sort, useQueryAndSortParams } from '../hooks/use-sort-and-query-params'
|
||||||
import { Answer } from '../../common/answer'
|
import { Answer } from '../../common/answer'
|
||||||
|
import { getProbability } from '../../common/calculate'
|
||||||
|
|
||||||
export function ContractsGrid(props: {
|
export function ContractsGrid(props: {
|
||||||
contracts: Contract[]
|
contracts: Contract[]
|
||||||
|
@ -254,6 +257,12 @@ export function SearchableGrid(props: {
|
||||||
matches = _.sortBy(matches, ({ volume24Hours }) => -1 * volume24Hours)
|
matches = _.sortBy(matches, ({ volume24Hours }) => -1 * volume24Hours)
|
||||||
} else if (sort === 'creator' || sort === 'tag') {
|
} else if (sort === 'creator' || sort === 'tag') {
|
||||||
matches.sort((a, b) => b.volume7Days - a.volume7Days)
|
matches.sort((a, b) => b.volume7Days - a.volume7Days)
|
||||||
|
} else if (sort === 'most-likely') {
|
||||||
|
matches = _.sortBy(matches, (contract) => -getBinaryProb(contract))
|
||||||
|
} else if (sort === 'least-likely') {
|
||||||
|
// Exclude non-binary contracts
|
||||||
|
matches = matches.filter((contract) => getBinaryProb(contract) !== 0)
|
||||||
|
matches = _.sortBy(matches, (contract) => getBinaryProb(contract))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sort !== 'all') {
|
if (sort !== 'all') {
|
||||||
|
@ -290,6 +299,8 @@ export function SearchableGrid(props: {
|
||||||
<option value="closed">Closed</option>
|
<option value="closed">Closed</option>
|
||||||
<option value="newest">Newest</option>
|
<option value="newest">Newest</option>
|
||||||
<option value="oldest">Oldest</option>
|
<option value="oldest">Oldest</option>
|
||||||
|
<option value="most-likely">Most likely</option>
|
||||||
|
<option value="least-likely">Least likely</option>
|
||||||
|
|
||||||
<option value="tag">By tag</option>
|
<option value="tag">By tag</option>
|
||||||
{!byOneCreator && <option value="creator">By creator</option>}
|
{!byOneCreator && <option value="creator">By creator</option>}
|
||||||
|
|
|
@ -50,15 +50,16 @@ export function contractMetrics(contract: Contract) {
|
||||||
return { truePool, liquidityLabel, createdDate, resolvedDate }
|
return { truePool, liquidityLabel, createdDate, resolvedDate }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBinaryProbPercent(contract: FullContract<any, Binary>) {
|
export function getBinaryProb(contract: FullContract<any, Binary>) {
|
||||||
const { totalShares, pool, p, resolutionProbability, mechanism } = contract
|
const { totalShares, pool, p, resolutionProbability, mechanism } = contract
|
||||||
|
|
||||||
const prob =
|
return resolutionProbability ?? mechanism === 'cpmm-1'
|
||||||
resolutionProbability ?? mechanism === 'cpmm-1'
|
|
||||||
? getCpmmProbability(pool, p)
|
? getCpmmProbability(pool, p)
|
||||||
: getDpmProbability(totalShares)
|
: getDpmProbability(totalShares)
|
||||||
|
}
|
||||||
|
|
||||||
return formatPercent(prob)
|
export function getBinaryProbPercent(contract: FullContract<any, Binary>) {
|
||||||
|
return formatPercent(getBinaryProb(contract))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tradingAllowed(contract: Contract) {
|
export function tradingAllowed(contract: Contract) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user