From 1cf7b425976c510e157ac30b7bf3fdf59311d79d Mon Sep 17 00:00:00 2001 From: James Grugett Date: Mon, 7 Feb 2022 22:48:36 -0600 Subject: [PATCH] Better handle graphs of resolved markets that had an earlier close time. --- web/components/contract-prob-graph.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/components/contract-prob-graph.tsx b/web/components/contract-prob-graph.tsx index 24fef00b..3edab2a6 100644 --- a/web/components/contract-prob-graph.tsx +++ b/web/components/contract-prob-graph.tsx @@ -9,7 +9,7 @@ import { Contract } from '../lib/firebase/contracts' export function ContractProbGraph(props: { contract: Contract }) { const { contract } = props - const { id, phantomShares, resolutionTime } = contract + const { id, phantomShares, resolutionTime, closeTime } = contract let bets = useBets(id) ?? [] bets = withoutAnteBets(contract, bets) @@ -22,9 +22,16 @@ export function ContractProbGraph(props: { contract: Contract }) { ].map((time) => new Date(time)) const probs = [startProb, ...bets.map((bet) => bet.probAfter)] - const latestTime = dayjs(resolutionTime ? resolutionTime : Date.now()) + const latestTime = dayjs( + resolutionTime && closeTime + ? Math.min(resolutionTime, closeTime) + : closeTime ?? resolutionTime ?? Date.now() + ) - if (!resolutionTime) { + if (resolutionTime) { + times.push(latestTime.toDate()) + probs.push(probs[probs.length - 1]) + } else { // Add a fake datapoint in future so the line continues horizontally // to the right. times.push(latestTime.add(1, 'month').toDate())