From 68120ec2b2f01a8d687626d7cf29dc3a3e5268b5 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sun, 25 Sep 2022 23:29:13 -0400 Subject: [PATCH] Revert "Clean up and fix stuff on answers panel (#914)" This reverts commit 721448f40811889cb8780f7c1ea5c537fbbc4fb1. --- web/components/answers/answers-panel.tsx | 41 ++++++++++++++++-------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/web/components/answers/answers-panel.tsx b/web/components/answers/answers-panel.tsx index 51cf5799..a1cef4c3 100644 --- a/web/components/answers/answers-panel.tsx +++ b/web/components/answers/answers-panel.tsx @@ -38,13 +38,26 @@ export function AnswersPanel(props: { const answers = (useAnswers(contract.id) ?? contract.answers).filter( (a) => a.number != 0 || contract.outcomeType === 'MULTIPLE_CHOICE' ) - const [winningAnswers, notWinningAnswers] = partition( - answers, - (a) => a.id === resolution || (resolutions && resolutions[a.id]) + const hasZeroBetAnswers = answers.some((answer) => totalBets[answer.id] < 1) + + const [winningAnswers, losingAnswers] = partition( + answers.filter((a) => (showAllAnswers ? true : totalBets[a.id] > 0)), + (answer) => + answer.id === resolution || (resolutions && resolutions[answer.id]) ) - const [visibleAnswers, invisibleAnswers] = partition( - sortBy(notWinningAnswers, (a) => -getOutcomeProbability(contract, a.id)), - (a) => showAllAnswers || totalBets[a.id] > 0 + const sortedAnswers = [ + ...sortBy(winningAnswers, (answer) => + resolutions ? -1 * resolutions[answer.id] : 0 + ), + ...sortBy( + resolution ? [] : losingAnswers, + (answer) => -1 * getDpmOutcomeProbability(contract.totalShares, answer.id) + ), + ] + + const answerItems = sortBy( + losingAnswers.length > 0 ? losingAnswers : sortedAnswers, + (answer) => -getOutcomeProbability(contract, answer.id) ) const user = useUser() @@ -94,13 +107,13 @@ export function AnswersPanel(props: { return ( {(resolveOption || resolution) && - sortBy(winningAnswers, (a) => -(resolutions?.[a.id] ?? 0)).map((a) => ( + sortedAnswers.map((answer) => ( - {visibleAnswers.map((a) => ( - + {answerItems.map((item) => ( + ))} - {invisibleAnswers.length > 0 && !showAllAnswers && ( + {hasZeroBetAnswers && !showAllAnswers && (