From 5648595272d65fb0268eb44d125b58cd6eeeaf3e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 9 Jul 2022 16:39:48 -0500 Subject: [PATCH] Simplify mobile betting dialog --- web/components/bet-panel.tsx | 125 ++++++----------------------------- web/components/bet-row.tsx | 5 +- 2 files changed, 22 insertions(+), 108 deletions(-) diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index ba19d41a..7653ba45 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -23,7 +23,7 @@ import { APIError, placeBet } from 'web/lib/firebase/api-call' import { sellShares } from 'web/lib/firebase/api-call' import { AmountInput, BuyAmountInput } from './amount-input' import { InfoTooltip } from './info-tooltip' -import { BinaryOutcomeLabel, PseudoNumericOutcomeLabel } from './outcome-label' +import { BinaryOutcomeLabel } from './outcome-label' import { getProbability } from 'common/calculate' import { useFocus } from 'web/hooks/use-focus' import { useUserContractBets } from 'web/hooks/use-user-bets' @@ -111,128 +111,43 @@ export function BetPanel(props: { ) } -export function BetPanelSwitcher(props: { +export function SimpleBetPanel(props: { contract: CPMMBinaryContract | PseudoNumericContract className?: string - title?: string // Set if BetPanel is on a feed modal selected?: 'YES' | 'NO' onBetSuccess?: () => void }) { - const { contract, className, title, selected, onBetSuccess } = props - - const { mechanism, outcomeType } = contract - const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC' + const { contract, className, selected, onBetSuccess } = props const user = useUser() - const userBets = useUserContractBets(user?.id, contract.id) const unfilledBets = useUnfilledBets(contract.id) ?? [] - - const [tradeType, setTradeType] = useState<'BUY' | 'SELL'>('BUY') const [isLimitOrder, setIsLimitOrder] = useState(false) - const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares( - contract, - userBets - ) - - const floorShares = yesFloorShares || noFloorShares - const sharesOutcome = yesFloorShares - ? 'YES' - : noFloorShares - ? 'NO' - : undefined - - useEffect(() => { - // Switch back to BUY if the user has sold all their shares. - if (tradeType === 'SELL' && sharesOutcome === undefined) { - setTradeType('BUY') - } - }, [tradeType, sharesOutcome]) - return ( - {sharesOutcome && mechanism === 'cpmm-1' && ( - - -
- You have {formatWithCommas(floorShares)}{' '} - {isPseudoNumeric ? ( - - ) : ( - - )}{' '} - shares -
- - {tradeType === 'BUY' && ( - - )} -
- - )} - - + - {tradeType === 'BUY' && ( - <button - className="btn btn-ghost btn-sm text-sm normal-case" - onClick={() => setIsLimitOrder(!isLimitOrder)} - > - <SwitchHorizontalIcon className="inline h-6 w-6" /> - </button> - )} + <button + className="btn btn-ghost btn-sm text-sm normal-case" + onClick={() => setIsLimitOrder(!isLimitOrder)} + > + <SwitchHorizontalIcon className="inline h-6 w-6" /> + </button> </Row> - {tradeType === 'SELL' && user && sharesOutcome && ( - <SellPanel - contract={contract} - shares={yesShares || noShares} - sharesOutcome={sharesOutcome} - user={user} - userBets={userBets ?? []} - onSellSuccess={onBetSuccess} - /> - )} - - {tradeType === 'BUY' && ( - <BuyPanel - contract={contract} - user={user} - unfilledBets={unfilledBets} - selected={selected} - onBuySuccess={onBetSuccess} - isLimitOrder={isLimitOrder} - /> - )} + <BuyPanel + contract={contract} + user={user} + unfilledBets={unfilledBets} + selected={selected} + onBuySuccess={onBetSuccess} + isLimitOrder={isLimitOrder} + /> <SignUpPrompt /> </Col> diff --git a/web/components/bet-row.tsx b/web/components/bet-row.tsx index fe7a2843..23f458ea 100644 --- a/web/components/bet-row.tsx +++ b/web/components/bet-row.tsx @@ -1,7 +1,7 @@ import { useState } from 'react' import clsx from 'clsx' -import { BetPanelSwitcher } from './bet-panel' +import { SimpleBetPanel } from './bet-panel' import { YesNoSelector } from './yes-no-selector' import { CPMMBinaryContract, PseudoNumericContract } from 'common/contract' import { Modal } from './layout/modal' @@ -63,10 +63,9 @@ export default function BetRow(props: { } /> <Modal open={open} setOpen={setOpen}> - <BetPanelSwitcher + <SimpleBetPanel className={betPanelClassName} contract={contract} - title={contract.question} selected={betChoice} onBetSuccess={() => setOpen(false)} />