Clean up portfolio sorts

This commit is contained in:
James Grugett 2022-04-13 18:56:28 -05:00
parent ec63464461
commit e58ec54546

View File

@ -32,14 +32,13 @@ import {
calculatePayout, calculatePayout,
calculateSaleAmount, calculateSaleAmount,
getOutcomeProbability, getOutcomeProbability,
getProbability,
getProbabilityAfterSale, getProbabilityAfterSale,
getContractBetMetrics, getContractBetMetrics,
resolvedPayout, resolvedPayout,
getContractBetNullMetrics, getContractBetNullMetrics,
} from '../../common/calculate' } from '../../common/calculate'
type BetSort = 'newest' | 'profit' | 'resolutionTime' | 'value' | 'closeTime' type BetSort = 'newest' | 'profit' | 'closeTime' | 'value'
type BetFilter = 'open' | 'closed' | 'resolved' | 'all' type BetFilter = 'open' | 'closed' | 'resolved' | 'all'
export function BetsList(props: { user: User }) { export function BetsList(props: { user: User }) {
@ -90,15 +89,16 @@ export function BetsList(props: { user: User }) {
!FILTERS.resolved(c) && (c.closeTime ?? Infinity) < Date.now(), !FILTERS.resolved(c) && (c.closeTime ?? Infinity) < Date.now(),
open: (c) => !(FILTERS.closed(c) || FILTERS.resolved(c)), open: (c) => !(FILTERS.closed(c) || FILTERS.resolved(c)),
all: () => true, all: () => true,
// Pepe notes: most users want "settled", to see when their bets or sold; or "realized profit"
} }
const SORTS: Record<BetSort, (c: Contract) => number> = { const SORTS: Record<BetSort, (c: Contract) => number> = {
profit: (c) => contractsMetrics[c.id].profit, profit: (c) => contractsMetrics[c.id].profit,
value: (c) => contractsMetrics[c.id].payout, value: (c) => contractsMetrics[c.id].payout,
newest: (c) => newest: (c) =>
Math.max(...contractBets[c.id].map((bet) => bet.createdTime)), Math.max(...contractBets[c.id].map((bet) => bet.createdTime)),
resolutionTime: (c) => -(c.resolutionTime ?? c.closeTime ?? Infinity), closeTime: (c) =>
closeTime: (c) => -(c.closeTime ?? Infinity), // This is in fact the intuitive sort direction.
(filter === 'open' ? -1 : 1) *
(c.resolutionTime ?? c.closeTime ?? Infinity),
} }
const displayedContracts = _.sortBy(contracts, SORTS[sort]) const displayedContracts = _.sortBy(contracts, SORTS[sort])
.reverse() .reverse()
@ -166,11 +166,10 @@ export function BetsList(props: { user: User }) {
value={sort} value={sort}
onChange={(e) => setSort(e.target.value as BetSort)} onChange={(e) => setSort(e.target.value as BetSort)}
> >
<option value="value">By value</option> <option value="value">Value</option>
<option value="profit">By profit</option> <option value="profit">Profit</option>
<option value="newest">Most recent</option> <option value="newest">Recent trade</option>
<option value="closeTime">Closing soonest</option> <option value="closeTime">Close date</option>
<option value="resolutionTime">Resolved soonest</option>
</select> </select>
</Row> </Row>
</Col> </Col>