Bring back 'Place a trade'. Tweaks
This commit is contained in:
parent
7683ebc0b8
commit
618bdf76a6
|
@ -237,7 +237,7 @@ export function SellAmountInput(props: {
|
||||||
<AmountInput
|
<AmountInput
|
||||||
amount={amount}
|
amount={amount}
|
||||||
onChange={onAmountChange}
|
onChange={onAmountChange}
|
||||||
label="Shares"
|
label="Qty"
|
||||||
error={error}
|
error={error}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={className}
|
className={className}
|
||||||
|
|
|
@ -42,6 +42,8 @@ export function BetPanel(props: {
|
||||||
}) {
|
}) {
|
||||||
const { contract, className, title, selected, onBetSuccess } = props
|
const { contract, className, title, selected, onBetSuccess } = props
|
||||||
|
|
||||||
|
const { mechanism } = contract
|
||||||
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const userBets = useUserContractBets(user?.id, contract.id) ?? []
|
const userBets = useUserContractBets(user?.id, contract.id) ?? []
|
||||||
|
|
||||||
|
@ -59,10 +61,10 @@ export function BetPanel(props: {
|
||||||
const sharesOutcome = yesShares ? 'YES' : noShares ? 'NO' : undefined
|
const sharesOutcome = yesShares ? 'YES' : noShares ? 'NO' : undefined
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col>
|
<Col className={className}>
|
||||||
{sharesOutcome && (
|
{sharesOutcome && mechanism === 'cpmm-1' && (
|
||||||
<Col className="rounded-t-md px-6 py-6 bg-gray-100">
|
<Col className="rounded-t-md bg-gray-100 px-6 py-6">
|
||||||
<Row className="justify-between items-center gap-2">
|
<Row className="items-center justify-between gap-2">
|
||||||
<div>
|
<div>
|
||||||
You have {formatWithCommas(Math.floor(yesShares || noShares))}{' '}
|
You have {formatWithCommas(Math.floor(yesShares || noShares))}{' '}
|
||||||
<OutcomeLabel outcome={sharesOutcome} /> shares
|
<OutcomeLabel outcome={sharesOutcome} /> shares
|
||||||
|
@ -97,7 +99,7 @@ export function BetPanel(props: {
|
||||||
'!mt-0',
|
'!mt-0',
|
||||||
tradeType === 'BUY' && title ? '!text-xl' : ''
|
tradeType === 'BUY' && title ? '!text-xl' : ''
|
||||||
)}
|
)}
|
||||||
text={tradeType === 'BUY' ? title ?? 'Buy' : 'Sell'}
|
text={tradeType === 'BUY' ? title ?? 'Place a trade' : 'Sell shares'}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{tradeType === 'SELL' && user && sharesOutcome && (
|
{tradeType === 'SELL' && user && sharesOutcome && (
|
||||||
|
@ -145,17 +147,21 @@ function BuyPanel(props: {
|
||||||
|
|
||||||
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(selected)
|
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(selected)
|
||||||
const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
|
const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
|
||||||
const [inputRef, focusAmountInput] = useFocus()
|
|
||||||
|
|
||||||
const [error, setError] = useState<string | undefined>()
|
const [error, setError] = useState<string | undefined>()
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
const [wasSubmitted, setWasSubmitted] = useState(false)
|
const [wasSubmitted, setWasSubmitted] = useState(false)
|
||||||
|
|
||||||
|
const [inputRef, focusAmountInput] = useFocus()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// warm up cloud function
|
// warm up cloud function
|
||||||
placeBet({}).catch()
|
placeBet({}).catch()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selected) focusAmountInput()
|
||||||
|
}, [selected, focusAmountInput])
|
||||||
|
|
||||||
function onBetChoice(choice: 'YES' | 'NO') {
|
function onBetChoice(choice: 'YES' | 'NO') {
|
||||||
setBetChoice(choice)
|
setBetChoice(choice)
|
||||||
setWasSubmitted(false)
|
setWasSubmitted(false)
|
||||||
|
@ -219,10 +225,6 @@ function BuyPanel(props: {
|
||||||
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
|
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
|
||||||
const currentReturnPercent = formatPercent(currentReturn)
|
const currentReturnPercent = formatPercent(currentReturn)
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
focusAmountInput()
|
|
||||||
}, [focusAmountInput])
|
|
||||||
|
|
||||||
const dpmTooltip =
|
const dpmTooltip =
|
||||||
contract.mechanism === 'dpm-2'
|
contract.mechanism === 'dpm-2'
|
||||||
? `Current payout for ${formatWithCommas(shares)} / ${formatWithCommas(
|
? `Current payout for ${formatWithCommas(shares)} / ${formatWithCommas(
|
||||||
|
|
|
@ -28,7 +28,6 @@ export default function BetRow(props: {
|
||||||
</div>
|
</div>
|
||||||
<YesNoSelector
|
<YesNoSelector
|
||||||
btnClassName="btn-sm w-20"
|
btnClassName="btn-sm w-20"
|
||||||
showBuyLabel
|
|
||||||
onSelect={(choice) => {
|
onSelect={(choice) => {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
setBetChoice(choice)
|
setBetChoice(choice)
|
||||||
|
|
|
@ -7,11 +7,10 @@ import { Row } from './layout/row'
|
||||||
export function YesNoSelector(props: {
|
export function YesNoSelector(props: {
|
||||||
selected?: 'YES' | 'NO'
|
selected?: 'YES' | 'NO'
|
||||||
onSelect: (selected: 'YES' | 'NO') => void
|
onSelect: (selected: 'YES' | 'NO') => void
|
||||||
showBuyLabel?: boolean
|
|
||||||
className?: string
|
className?: string
|
||||||
btnClassName?: string
|
btnClassName?: string
|
||||||
}) {
|
}) {
|
||||||
const { selected, onSelect, showBuyLabel, className, btnClassName } = props
|
const { selected, onSelect, className, btnClassName } = props
|
||||||
|
|
||||||
const commonClassNames =
|
const commonClassNames =
|
||||||
'inline-flex flex-1 items-center justify-center rounded-3xl border-2 p-2'
|
'inline-flex flex-1 items-center justify-center rounded-3xl border-2 p-2'
|
||||||
|
@ -29,7 +28,7 @@ export function YesNoSelector(props: {
|
||||||
)}
|
)}
|
||||||
onClick={() => onSelect('YES')}
|
onClick={() => onSelect('YES')}
|
||||||
>
|
>
|
||||||
{showBuyLabel ? 'Buy' : ''} YES
|
Buy YES
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
@ -42,7 +41,7 @@ export function YesNoSelector(props: {
|
||||||
)}
|
)}
|
||||||
onClick={() => onSelect('NO')}
|
onClick={() => onSelect('NO')}
|
||||||
>
|
>
|
||||||
{showBuyLabel ? 'Buy' : ''} NO
|
Buy NO
|
||||||
</button>
|
</button>
|
||||||
</Row>
|
</Row>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user