ed5f69db7a
* Split BuyAmountInput out of AmountInput * Buy and sell tabs. Compute some sell info * In progress * BuyPanel & SellPanel with banner above that shows current shares and toggle button * Remove "Remaining balance" * Bring back 'Place a trade'. Tweaks * Sell shares cloud function. * Sell all shares by default. Switch back to buy if sell all your shares. * Cache your shares in local storage so sell banner doesn't flicker. * Compute sale value of shares with binary search to keep k constant. * Update bets table to show BUY or SELL * Fixes from Stephen's review * Don't allow selling more than max shares in cloud function * Use modal for sell shares on desktop. * Handle floating point precision in max shares you can sell.
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import clsx from 'clsx'
|
|
import { useState } from 'react'
|
|
|
|
import { BetPanelSwitcher } from './bet-panel'
|
|
import { Row } from './layout/row'
|
|
import { YesNoSelector } from './yes-no-selector'
|
|
import { Binary, CPMM, DPM, FullContract } from '../../common/contract'
|
|
import { Modal } from './layout/modal'
|
|
|
|
// Inline version of a bet panel. Opens BetPanel in a new modal.
|
|
export default function BetRow(props: {
|
|
contract: FullContract<DPM | CPMM, Binary>
|
|
className?: string
|
|
labelClassName?: string
|
|
}) {
|
|
const { className, labelClassName } = props
|
|
const [open, setOpen] = useState(false)
|
|
const [betChoice, setBetChoice] = useState<'YES' | 'NO' | undefined>(
|
|
undefined
|
|
)
|
|
|
|
return (
|
|
<>
|
|
<div className={className}>
|
|
<Row className="items-center justify-end gap-2">
|
|
<div className={clsx('mr-2 text-gray-400', labelClassName)}>
|
|
Place a trade
|
|
</div>
|
|
<YesNoSelector
|
|
btnClassName="btn-sm w-24"
|
|
onSelect={(choice) => {
|
|
setOpen(true)
|
|
setBetChoice(choice)
|
|
}}
|
|
/>
|
|
</Row>
|
|
<Modal open={open} setOpen={setOpen}>
|
|
<BetPanelSwitcher
|
|
contract={props.contract}
|
|
title={props.contract.question}
|
|
selected={betChoice}
|
|
onBetSuccess={() => setOpen(false)}
|
|
/>
|
|
</Modal>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|