Add 'sold' filter option in portfolio page

This commit is contained in:
James Grugett 2022-05-27 15:51:55 -05:00
parent 15d203977a
commit 279b139556

View File

@ -50,7 +50,7 @@ import { trackLatency } from 'web/lib/firebase/tracking'
import { NumericContract } from 'common/contract' import { NumericContract } from 'common/contract'
type BetSort = 'newest' | 'profit' | 'closeTime' | 'value' type BetSort = 'newest' | 'profit' | 'closeTime' | 'value'
type BetFilter = 'open' | 'closed' | 'resolved' | 'all' type BetFilter = 'open' | 'sold' | 'closed' | 'resolved' | 'all'
export function BetsList(props: { user: User }) { export function BetsList(props: { user: User }) {
const { user } = props const { user } = props
@ -107,6 +107,7 @@ 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,
sold: () => true,
} }
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,
@ -122,9 +123,14 @@ export function BetsList(props: { user: User }) {
.reverse() .reverse()
.filter(FILTERS[filter]) .filter(FILTERS[filter])
.filter((c) => { .filter((c) => {
// TODO: Expose a user setting to toggle whether to show contracts you sold out of. if (filter === 'all') return true
// Filter out contracts where you don't have shares anymore.
const metrics = contractsMetrics[c.id] const metrics = contractsMetrics[c.id]
// Filter for contracts you sold out of.
if (filter === 'sold') return metrics.payout === 0
// Filter for contracts where you currently have shares.
return metrics.payout > 0 return metrics.payout > 0
}) })
@ -180,6 +186,7 @@ export function BetsList(props: { user: User }) {
onChange={(e) => setFilter(e.target.value as BetFilter)} onChange={(e) => setFilter(e.target.value as BetFilter)}
> >
<option value="open">Open</option> <option value="open">Open</option>
<option value="sold">Sold</option>
<option value="closed">Closed</option> <option value="closed">Closed</option>
<option value="resolved">Resolved</option> <option value="resolved">Resolved</option>
<option value="all">All</option> <option value="all">All</option>