Sell either type of share for dpm market
This commit is contained in:
parent
3f471e7e8e
commit
4e4ffe8e20
|
@ -23,7 +23,10 @@ export default function BetRow(props: {
|
|||
)
|
||||
const user = useUser()
|
||||
const userBets = useUserContractBets(user?.id, contract.id)
|
||||
const { yesFloorShares, noFloorShares } = useSaveShares(contract, userBets)
|
||||
const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares(
|
||||
contract,
|
||||
userBets
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -40,12 +43,22 @@ export default function BetRow(props: {
|
|||
}}
|
||||
replaceNoButton={
|
||||
yesFloorShares > 0 ? (
|
||||
<SellButton contract={contract} user={user} />
|
||||
<SellButton
|
||||
contract={contract}
|
||||
user={user}
|
||||
sharesOutcome={'YES'}
|
||||
shares={yesShares}
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
replaceYesButton={
|
||||
noFloorShares > 0 ? (
|
||||
<SellButton contract={contract} user={user} />
|
||||
<SellButton
|
||||
contract={contract}
|
||||
user={user}
|
||||
sharesOutcome={'NO'}
|
||||
shares={noShares}
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
|
|
|
@ -2,7 +2,6 @@ import { Binary, CPMM, DPM, FullContract } from '../../common/contract'
|
|||
import { User } from '../../common/user'
|
||||
import { useUserContractBets } from '../hooks/use-user-bets'
|
||||
import { useState } from 'react'
|
||||
import { useSaveShares } from './use-save-shares'
|
||||
import { Col } from './layout/col'
|
||||
import clsx from 'clsx'
|
||||
import { SellSharesModal } from './sell-modal'
|
||||
|
@ -10,23 +9,13 @@ import { SellSharesModal } from './sell-modal'
|
|||
export function SellButton(props: {
|
||||
contract: FullContract<DPM | CPMM, Binary>
|
||||
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 [showSellModal, setShowSellModal] = useState(false)
|
||||
|
||||
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') {
|
||||
return (
|
||||
|
@ -45,14 +34,14 @@ export function SellButton(props: {
|
|||
{'Sell ' + sharesOutcome}
|
||||
</button>
|
||||
<div className={'mt-1 w-24 text-center text-sm text-gray-500'}>
|
||||
{'(' + floorShares + ' shares)'}
|
||||
{'(' + Math.floor(shares) + ' shares)'}
|
||||
</div>
|
||||
{showSellModal && (
|
||||
<SellSharesModal
|
||||
contract={contract as FullContract<CPMM, Binary>}
|
||||
user={user}
|
||||
userBets={userBets ?? []}
|
||||
shares={yesShares || noShares}
|
||||
shares={shares}
|
||||
sharesOutcome={sharesOutcome}
|
||||
setOpen={setShowSellModal}
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue
Block a user