Simplify bet buttons (#644)

* mono-button bet row

* "bet yes" => "yes"

* prettier
This commit is contained in:
mantikoros 2022-07-12 17:34:10 -05:00 committed by GitHub
parent dd9fdc381f
commit 38aad40569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 42 deletions

View File

@ -109,9 +109,10 @@ export function SimpleBetPanel(props: {
contract: CPMMBinaryContract | PseudoNumericContract contract: CPMMBinaryContract | PseudoNumericContract
className?: string className?: string
selected?: 'YES' | 'NO' selected?: 'YES' | 'NO'
hasShares?: boolean
onBetSuccess?: () => void onBetSuccess?: () => void
}) { }) {
const { contract, className, selected, onBetSuccess } = props const { contract, className, selected, hasShares, onBetSuccess } = props
const user = useUser() const user = useUser()
const [isLimitOrder, setIsLimitOrder] = useState(false) const [isLimitOrder, setIsLimitOrder] = useState(false)
@ -121,7 +122,17 @@ export function SimpleBetPanel(props: {
return ( return (
<Col className={className}> <Col className={className}>
<Col className={clsx('rounded-b-md rounded-t-md bg-white px-8 py-6')}> <SellRow
contract={contract}
user={user}
className={'rounded-t-md bg-gray-100 px-4 py-5'}
/>
<Col
className={clsx(
!hasShares && 'rounded-t-md',
'rounded-b-md bg-white px-8 py-6'
)}
>
<Row className="justify-between"> <Row className="justify-between">
<div className="mb-6 text-2xl"> <div className="mb-6 text-2xl">
{isLimitOrder ? <>Limit order</> : <>Place your bet</>} {isLimitOrder ? <>Limit order</> : <>Place your bet</>}

View File

@ -2,13 +2,12 @@ import { useState } from 'react'
import clsx from 'clsx' import clsx from 'clsx'
import { SimpleBetPanel } from './bet-panel' import { SimpleBetPanel } from './bet-panel'
import { YesNoSelector } from './yes-no-selector'
import { CPMMBinaryContract, PseudoNumericContract } from 'common/contract' import { CPMMBinaryContract, PseudoNumericContract } from 'common/contract'
import { Modal } from './layout/modal' import { Modal } from './layout/modal'
import { SellButton } from './sell-button'
import { useUser } from 'web/hooks/use-user' import { useUser } from 'web/hooks/use-user'
import { useUserContractBets } from 'web/hooks/use-user-bets' import { useUserContractBets } from 'web/hooks/use-user-bets'
import { useSaveBinaryShares } from './use-save-binary-shares' import { useSaveBinaryShares } from './use-save-binary-shares'
import { Col } from './layout/col'
// Inline version of a bet panel. Opens BetPanel in a new modal. // Inline version of a bet panel. Opens BetPanel in a new modal.
export default function BetRow(props: { export default function BetRow(props: {
@ -19,9 +18,7 @@ export default function BetRow(props: {
}) { }) {
const { className, btnClassName, betPanelClassName, contract } = props const { className, btnClassName, betPanelClassName, contract } = props
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(
undefined
)
const user = useUser() const user = useUser()
const userBets = useUserContractBets(user?.id, contract.id) const userBets = useUserContractBets(user?.id, contract.id)
const { yesShares, noShares, hasYesShares, hasNoShares } = const { yesShares, noShares, hasYesShares, hasNoShares } =
@ -29,43 +26,33 @@ export default function BetRow(props: {
return ( return (
<> <>
<YesNoSelector <Col className={clsx('items-center', className)}>
isPseudoNumeric={contract.outcomeType === 'PSEUDO_NUMERIC'} <button
className={clsx('justify-end', className)} className={clsx(
btnClassName={clsx('btn-sm w-24', btnClassName)} 'btn btn-lg btn-outline my-auto inline-flex h-10 min-h-0 w-24',
onSelect={(choice) => { btnClassName
setOpen(true) )}
setBetChoice(choice) onClick={() => setOpen(true)}
}} >
replaceNoButton={ Bet
hasYesShares ? ( </button>
<SellButton
panelClassName={betPanelClassName} <div className={'mt-1 w-24 text-center text-sm text-gray-500'}>
contract={contract} {hasYesShares
user={user} ? `(${Math.floor(yesShares)} YES)`
sharesOutcome={'YES'} : hasNoShares
shares={yesShares} ? `(${Math.floor(noShares)} NO)`
/> : ''}
) : undefined </div>
} </Col>
replaceYesButton={
hasNoShares ? (
<SellButton
panelClassName={betPanelClassName}
contract={contract}
user={user}
sharesOutcome={'NO'}
shares={noShares}
/>
) : undefined
}
/>
<Modal open={open} setOpen={setOpen}> <Modal open={open} setOpen={setOpen}>
<SimpleBetPanel <SimpleBetPanel
className={betPanelClassName} className={betPanelClassName}
contract={contract} contract={contract}
selected={betChoice} selected={undefined}
onBetSuccess={() => setOpen(false)} onBetSuccess={() => setOpen(false)}
hasShares={hasYesShares || hasNoShares}
/> />
</Modal> </Modal>
</> </>

View File

@ -30,7 +30,9 @@ export function LimitBets(props: {
'gap-2 overflow-hidden rounded bg-white px-4 py-3' 'gap-2 overflow-hidden rounded bg-white px-4 py-3'
)} )}
> >
{!hideLabel && <div className="px-2 py-3 text-2xl">Your limit orders</div>} {!hideLabel && (
<div className="px-2 py-3 text-2xl">Your limit orders</div>
)}
<table className="table-compact table w-full rounded text-gray-500"> <table className="table-compact table w-full rounded text-gray-500">
<tbody> <tbody>
{recentBets.map((bet) => ( {recentBets.map((bet) => (

View File

@ -43,7 +43,7 @@ export function YesNoSelector(props: {
)} )}
onClick={() => onSelect('YES')} onClick={() => onSelect('YES')}
> >
{isPseudoNumeric ? 'HIGHER' : 'Bet YES'} {isPseudoNumeric ? 'HIGHER' : 'YES'}
</button> </button>
)} )}
{replaceNoButton ? ( {replaceNoButton ? (
@ -60,7 +60,7 @@ export function YesNoSelector(props: {
)} )}
onClick={() => onSelect('NO')} onClick={() => onSelect('NO')}
> >
{isPseudoNumeric ? 'LOWER' : 'Bet NO'} {isPseudoNumeric ? 'LOWER' : 'NO'}
</button> </button>
)} )}
</Row> </Row>