Sell either type of share for dpm market

This commit is contained in:
Ian Philips 2022-04-22 04:43:34 -06:00
parent 3f471e7e8e
commit 4e4ffe8e20
2 changed files with 21 additions and 19 deletions

View File

@ -23,7 +23,10 @@ export default function BetRow(props: {
) )
const user = useUser() const user = useUser()
const userBets = useUserContractBets(user?.id, contract.id) const userBets = useUserContractBets(user?.id, contract.id)
const { yesFloorShares, noFloorShares } = useSaveShares(contract, userBets) const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares(
contract,
userBets
)
return ( return (
<> <>
@ -40,12 +43,22 @@ export default function BetRow(props: {
}} }}
replaceNoButton={ replaceNoButton={
yesFloorShares > 0 ? ( yesFloorShares > 0 ? (
<SellButton contract={contract} user={user} /> <SellButton
contract={contract}
user={user}
sharesOutcome={'YES'}
shares={yesShares}
/>
) : undefined ) : undefined
} }
replaceYesButton={ replaceYesButton={
noFloorShares > 0 ? ( noFloorShares > 0 ? (
<SellButton contract={contract} user={user} /> <SellButton
contract={contract}
user={user}
sharesOutcome={'NO'}
shares={noShares}
/>
) : undefined ) : undefined
} }
/> />

View File

@ -2,7 +2,6 @@ import { Binary, CPMM, DPM, FullContract } from '../../common/contract'
import { User } from '../../common/user' import { User } from '../../common/user'
import { useUserContractBets } from '../hooks/use-user-bets' import { useUserContractBets } from '../hooks/use-user-bets'
import { useState } from 'react' import { useState } from 'react'
import { useSaveShares } from './use-save-shares'
import { Col } from './layout/col' import { Col } from './layout/col'
import clsx from 'clsx' import clsx from 'clsx'
import { SellSharesModal } from './sell-modal' import { SellSharesModal } from './sell-modal'
@ -10,23 +9,13 @@ import { SellSharesModal } from './sell-modal'
export function SellButton(props: { export function SellButton(props: {
contract: FullContract<DPM | CPMM, Binary> contract: FullContract<DPM | CPMM, Binary>
user: User | null | undefined user: User | null | undefined
sharesOutcome: 'YES' | 'NO' | undefined
shares: number
}) { }) {
const { contract, user } = props const { contract, user, sharesOutcome, shares } = props
const userBets = useUserContractBets(user?.id, contract.id) const userBets = useUserContractBets(user?.id, contract.id)
const [showSellModal, setShowSellModal] = useState(false) const [showSellModal, setShowSellModal] = useState(false)
const { mechanism } = contract const { mechanism } = contract
const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares(
contract,
userBets
)
const floorShares = yesFloorShares || noFloorShares
const sharesOutcome = yesFloorShares
? 'YES'
: noFloorShares
? 'NO'
: undefined
if (sharesOutcome && user && mechanism === 'cpmm-1') { if (sharesOutcome && user && mechanism === 'cpmm-1') {
return ( return (
@ -45,14 +34,14 @@ export function SellButton(props: {
{'Sell ' + sharesOutcome} {'Sell ' + sharesOutcome}
</button> </button>
<div className={'mt-1 w-24 text-center text-sm text-gray-500'}> <div className={'mt-1 w-24 text-center text-sm text-gray-500'}>
{'(' + floorShares + ' shares)'} {'(' + Math.floor(shares) + ' shares)'}
</div> </div>
{showSellModal && ( {showSellModal && (
<SellSharesModal <SellSharesModal
contract={contract as FullContract<CPMM, Binary>} contract={contract as FullContract<CPMM, Binary>}
user={user} user={user}
userBets={userBets ?? []} userBets={userBets ?? []}
shares={yesShares || noShares} shares={shares}
sharesOutcome={sharesOutcome} sharesOutcome={sharesOutcome}
setOpen={setShowSellModal} setOpen={setShowSellModal}
/> />