From 9f1b7e8902f36a944a7791a38bed0001610e9ebd Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Thu, 29 Sep 2022 20:19:18 -0700 Subject: [PATCH] WIP change probability on contract page on chart hover --- web/components/contract/contract-card.tsx | 10 ++++++---- web/components/contract/contract-overview.tsx | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/web/components/contract/contract-card.tsx b/web/components/contract/contract-card.tsx index aa130321..0bdb55f5 100644 --- a/web/components/contract/contract-card.tsx +++ b/web/components/contract/contract-card.tsx @@ -2,7 +2,8 @@ import clsx from 'clsx' import Link from 'next/link' import { Row } from '../layout/row' import { formatLargeNumber, formatPercent } from 'common/util/format' -import { contractPath, getBinaryProbPercent } from 'web/lib/firebase/contracts' +import { getBinaryProb } from 'common/contract-details' +import { contractPath } from 'web/lib/firebase/contracts' import { Col } from '../layout/col' import { BinaryContract, @@ -200,13 +201,14 @@ export function BinaryResolutionOrChance(props: { contract: BinaryContract large?: boolean className?: string - probAfter?: number // 0 to 1 + probNow?: number + probAfter?: number }) { - const { contract, large, className, probAfter } = props + const { contract, large, className, probNow, probAfter } = props const { resolution } = contract const textColor = `text-${getColor(contract)}` - const before = getBinaryProbPercent(contract) + const before = formatPercent(probNow ?? getBinaryProb(contract)) const after = probAfter && formatPercent(probAfter) const probChanged = before !== after diff --git a/web/components/contract/contract-overview.tsx b/web/components/contract/contract-overview.tsx index add9ba48..991d404f 100644 --- a/web/components/contract/contract-overview.tsx +++ b/web/components/contract/contract-overview.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState } from 'react' import { tradingAllowed } from 'web/lib/firebase/contracts' import { Col } from '../layout/col' @@ -29,6 +29,7 @@ import { BinaryContract, } from 'common/contract' import { ContractDetails } from './contract-details' +import { useEvent } from 'web/hooks/use-event' const OverviewQuestion = (props: { text: string }) => ( @@ -73,6 +74,11 @@ const NumericOverview = (props: { contract: NumericContract }) => { const BinaryOverview = (props: { contract: BinaryContract; bets: Bet[] }) => { const { contract, bets } = props + const [displayProb, setDisplayProb] = useState() + const onChartMouseOver = useEvent((p: { y: number } | undefined) => { + setDisplayProb(p?.y) + }) + return ( @@ -82,11 +88,16 @@ const BinaryOverview = (props: { contract: BinaryContract; bets: Bet[] }) => { - + {tradingAllowed(contract) && (