From b39e0f304f7472e0e3e2ae2539b9c0f56d26b430 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Sat, 10 Sep 2022 17:07:23 -0600 Subject: [PATCH] Yes and no buttons on contract page (#868) * Yes and no buttons on contract page * Cheating by adding 0.05 to max shares but gives better quickbet UX --- web/components/bet-button.tsx | 23 ++-- web/components/contract/contract-card.tsx | 8 +- web/components/contract/contract-overview.tsx | 41 ++++-- .../{quick-bet.tsx => quick-bet-arrows.tsx} | 4 +- web/components/contract/quick-bet-button.tsx | 128 ++++++++++++++++++ 5 files changed, 179 insertions(+), 25 deletions(-) rename web/components/contract/{quick-bet.tsx => quick-bet-arrows.tsx} (98%) create mode 100644 web/components/contract/quick-bet-button.tsx diff --git a/web/components/bet-button.tsx b/web/components/bet-button.tsx index 0bd3702f..2aadbc78 100644 --- a/web/components/bet-button.tsx +++ b/web/components/bet-button.tsx @@ -32,6 +32,17 @@ export default function BetButton(props: { return ( <> + {user && ( +
+ {hasYesShares + ? `(${Math.floor(yesShares)} ${ + isPseudoNumeric ? 'HIGHER' : 'YES' + })` + : hasNoShares + ? `(${Math.floor(noShares)} ${isPseudoNumeric ? 'LOWER' : 'NO'})` + : ''} +
+ )} {user ? ( + ) +} + +// Return a number from 0 to 1 for this contract +// Resolved contracts are set to 1, for coloring purposes (even if NO) +function getProb(contract: Contract) { + const { outcomeType, resolution, resolutionProbability } = contract + return resolutionProbability + ? resolutionProbability + : resolution + ? 1 + : outcomeType === 'BINARY' + ? getBinaryProb(contract) + : outcomeType === 'PSEUDO_NUMERIC' + ? getProbability(contract) + : outcomeType === 'FREE_RESPONSE' || outcomeType === 'MULTIPLE_CHOICE' + ? getOutcomeProbability(contract, getTopAnswer(contract)?.id || '') + : outcomeType === 'NUMERIC' + ? getNumericScale(contract) + : 1 // Should not happen +} + +function getNumericScale(contract: NumericContract) { + const { min, max } = contract + const ev = getExpectedValue(contract) + return (ev - min) / (max - min) +}