From 212f79aac97845b1b2ce7e5c356a3f2e72c6f1a3 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 15 Feb 2022 22:33:04 -0600 Subject: [PATCH] Resolved market UI --- web/components/answers-panel.tsx | 68 +++++++++++++++++++++++++------- web/components/outcome-label.tsx | 2 +- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/web/components/answers-panel.tsx b/web/components/answers-panel.tsx index 59651a17..e1990892 100644 --- a/web/components/answers-panel.tsx +++ b/web/components/answers-panel.tsx @@ -33,18 +33,28 @@ import { firebaseLogin } from '../lib/firebase/users' import { Bet } from '../../common/bet' import { useAnswers } from '../hooks/use-answers' import { ResolveConfirmationButton } from './confirmation-button' +import { tradingAllowed } from '../lib/firebase/contracts' +import { OutcomeLabel } from './outcome-label' export function AnswersPanel(props: { contract: Contract<'MULTI'> answers: Answer[] }) { const { contract } = props + const { creatorId, resolution } = contract const answers = useAnswers(contract.id) ?? props.answers - const sortedAnswers = _.sortBy( + const [chosenAnswer, otherAnswers] = _.partition( answers, - (answer) => -1 * getOutcomeProbability(contract.totalShares, answer.id) + (answer) => answer.id === resolution ) + const sortedAnswers = [ + ...chosenAnswer, + ..._.sortBy( + otherAnswers, + (answer) => -1 * getOutcomeProbability(contract.totalShares, answer.id) + ), + ] const user = useUser() @@ -55,6 +65,11 @@ export function AnswersPanel(props: { return ( + {resolution && ( +
+ Resolved to answer : +
+ )} {sortedAnswers.map((answer) => ( ))} - + {tradingAllowed(contract) && } - {user?.id === contract.creatorId && ( + {user?.id === creatorId && !resolution && ( void }) { const { answer, contract, showChoice, isChosen, onChoose } = props + const { resolution, totalShares } = contract const { username, avatarUrl, name, createdTime, number, text } = answer const createdDate = dayjs(createdTime).format('MMM D') - const prob = getOutcomeProbability(contract.totalShares, answer.id) + const prob = getOutcomeProbability(totalShares, answer.id) const probPercent = formatPercent(prob) + const wasResolvedTo = resolution === answer.id const [isBetting, setIsBetting] = useState(false) return ( - +
{text}
@@ -130,7 +156,14 @@ function AnswerItem(props: { /> ) : ( -
{probPercent}
+
+ {probPercent} +
{showChoice ? (
) : ( - { - setIsBetting(true) - }} - /> + <> + {tradingAllowed(contract) && ( + { + setIsBetting(true) + }} + /> + )} + {wasResolvedTo && ( +
Chosen
+ )} + )}
)} @@ -422,7 +462,7 @@ function AnswerResolvePanel(props: { return (
Resolve your market
- +