From e58ec5454611a23e76eda5d749a6c7b1dd37cda3 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 13 Apr 2022 18:56:28 -0500 Subject: [PATCH] Clean up portfolio sorts --- web/components/bets-list.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 362b4ea5..b7f6d339 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -32,14 +32,13 @@ import { calculatePayout, calculateSaleAmount, getOutcomeProbability, - getProbability, getProbabilityAfterSale, getContractBetMetrics, resolvedPayout, getContractBetNullMetrics, } from '../../common/calculate' -type BetSort = 'newest' | 'profit' | 'resolutionTime' | 'value' | 'closeTime' +type BetSort = 'newest' | 'profit' | 'closeTime' | 'value' type BetFilter = 'open' | 'closed' | 'resolved' | 'all' export function BetsList(props: { user: User }) { @@ -90,15 +89,16 @@ export function BetsList(props: { user: User }) { !FILTERS.resolved(c) && (c.closeTime ?? Infinity) < Date.now(), open: (c) => !(FILTERS.closed(c) || FILTERS.resolved(c)), all: () => true, - // Pepe notes: most users want "settled", to see when their bets or sold; or "realized profit" } const SORTS: Record number> = { profit: (c) => contractsMetrics[c.id].profit, value: (c) => contractsMetrics[c.id].payout, newest: (c) => Math.max(...contractBets[c.id].map((bet) => bet.createdTime)), - resolutionTime: (c) => -(c.resolutionTime ?? c.closeTime ?? Infinity), - closeTime: (c) => -(c.closeTime ?? Infinity), + closeTime: (c) => + // This is in fact the intuitive sort direction. + (filter === 'open' ? -1 : 1) * + (c.resolutionTime ?? c.closeTime ?? Infinity), } const displayedContracts = _.sortBy(contracts, SORTS[sort]) .reverse() @@ -166,11 +166,10 @@ export function BetsList(props: { user: User }) { value={sort} onChange={(e) => setSort(e.target.value as BetSort)} > - - - - - + + + +