From 29e13497bf6fc9c6c3d2d822c3a6477a03259f00 Mon Sep 17 00:00:00 2001 From: jahooma Date: Fri, 10 Dec 2021 22:09:32 -0600 Subject: [PATCH] Add volume calculation. Remove new bet button that was unnecessary. --- web/components/bet-panel.tsx | 26 +++++++------------------- web/components/contract-overview.tsx | 6 +++++- web/lib/util/format.ts | 6 +++++- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index e8bd6f20..afb5bfd2 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -21,6 +21,11 @@ export function BetPanel(props: { contract: Contract; className?: string }) { const [isSubmitting, setIsSubmitting] = useState(false) const [wasSubmitted, setWasSubmitted] = useState(false) + function onBetChoice(choice: 'YES' | 'NO') { + setBetChoice(choice) + setWasSubmitted(false) + } + function onBetChange(str: string) { const amount = parseInt(str) setBetAmount(isNaN(amount) ? undefined : amount) @@ -44,11 +49,6 @@ export function BetPanel(props: { contract: Contract; className?: string }) { setWasSubmitted(true) } - function newBet() { - setBetAmount(undefined) - setWasSubmitted(false) - } - const betDisabled = isSubmitting || wasSubmitted const initialProb = getProbability(contract.pot, betChoice) @@ -72,7 +72,7 @@ export function BetPanel(props: { contract: Contract; className?: string }) { onBetChoice(choice)} /> @@ -128,19 +128,7 @@ export function BetPanel(props: { contract: Contract; className?: string }) { Place bet - {wasSubmitted && ( - - - -
Bet submitted!
- - - - - - )} + {wasSubmitted &&
Bet submitted!
} ) } diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index 084827c6..41fea05b 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -14,6 +14,7 @@ import { Contract } from '../lib/firebase/contracts' import { Col } from './layout/col' import { Row } from './layout/row' import { Spacer } from './layout/spacer' +import { formatWithCommas } from '../lib/util/format' // Auto import doesn't work for some reason... // So we manually register ChartJS components instead: @@ -39,6 +40,9 @@ const chartData = { export const ContractOverview = (props: { contract: Contract }) => { const { contract } = props + const { pot, seedAmounts } = contract + + const volume = pot.YES + pot.NO - seedAmounts.YES - seedAmounts.NO return ( @@ -49,7 +53,7 @@ export const ContractOverview = (props: { contract: Contract }) => {
Dec 9
-
200,000 volume
+
{formatWithCommas(volume)} volume
diff --git a/web/lib/util/format.ts b/web/lib/util/format.ts index 04c7ee14..8f3a91e0 100644 --- a/web/lib/util/format.ts +++ b/web/lib/util/format.ts @@ -4,6 +4,10 @@ const formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0, }) -export const formatMoney = (amount: number) => { +export function formatMoney(amount: number) { return 'M$ ' + formatter.format(amount).substr(1) } + +export function formatWithCommas(amount: number) { + return formatter.format(amount).substr(1) +}