Sell bets. Various fixes
This commit is contained in:
parent
6f5ac2d1d1
commit
fad1c8aaea
|
@ -68,8 +68,8 @@ export function getFreeAnswerAnte(
|
|||
anteBetId: string
|
||||
) {
|
||||
const { totalBets, totalShares } = contract
|
||||
const amount = totalBets.NONE
|
||||
const shares = totalShares.NONE
|
||||
const amount = totalBets['0']
|
||||
const shares = totalShares['0']
|
||||
|
||||
const { createdTime } = contract
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Bet } from './bet'
|
||||
import { calculateShareValue, deductFees, getProbability } from './calculate'
|
||||
import { Contract } from './contract'
|
||||
import { CREATOR_FEE, FEES } from './fees'
|
||||
import { CREATOR_FEE } from './fees'
|
||||
import { User } from './user'
|
||||
|
||||
export const getSellBetInfo = (
|
||||
|
@ -10,30 +10,21 @@ export const getSellBetInfo = (
|
|||
contract: Contract,
|
||||
newBetId: string
|
||||
) => {
|
||||
const { pool, totalShares, totalBets } = contract
|
||||
const { id: betId, amount, shares, outcome } = bet
|
||||
|
||||
const { YES: yesPool, NO: noPool } = contract.pool
|
||||
const { YES: yesShares, NO: noShares } = contract.totalShares
|
||||
const { YES: yesBets, NO: noBets } = contract.totalBets
|
||||
|
||||
const adjShareValue = calculateShareValue(contract, bet)
|
||||
|
||||
const newPool =
|
||||
outcome === 'YES'
|
||||
? { YES: yesPool - adjShareValue, NO: noPool }
|
||||
: { YES: yesPool, NO: noPool - adjShareValue }
|
||||
const newPool = { ...pool, [outcome]: pool[outcome] - adjShareValue }
|
||||
|
||||
const newTotalShares =
|
||||
outcome === 'YES'
|
||||
? { YES: yesShares - shares, NO: noShares }
|
||||
: { YES: yesShares, NO: noShares - shares }
|
||||
const newTotalShares = {
|
||||
...totalShares,
|
||||
[outcome]: totalShares[outcome] - shares,
|
||||
}
|
||||
|
||||
const newTotalBets =
|
||||
outcome === 'YES'
|
||||
? { YES: yesBets - amount, NO: noBets }
|
||||
: { YES: yesBets, NO: noBets - amount }
|
||||
const newTotalBets = { ...totalBets, [outcome]: totalBets[outcome] - amount }
|
||||
|
||||
const probBefore = getProbability(contract.totalShares)
|
||||
const probBefore = getProbability(totalShares)
|
||||
const probAfter = getProbability(newTotalShares)
|
||||
|
||||
const profit = adjShareValue - amount
|
||||
|
|
|
@ -36,7 +36,7 @@ export const resolveMarket = functions
|
|||
if (!['YES', 'NO', 'MKT', 'CANCEL'].includes(outcome))
|
||||
return { status: 'error', message: 'Invalid outcome' }
|
||||
} else if (outcomeType === 'MULTI') {
|
||||
if (isNaN(+outcome))
|
||||
if (outcome !== 'CANCEL' && isNaN(+outcome))
|
||||
return { status: 'error', message: 'Invalid outcome' }
|
||||
} else {
|
||||
return { status: 'error', message: 'Invalid contract outcomeType' }
|
||||
|
|
|
@ -401,8 +401,9 @@ function CreateAnswerInput(props: { contract: Contract<'MULTI'> }) {
|
|||
)}
|
||||
<button
|
||||
className={clsx(
|
||||
'btn btn-sm self-end mt-2',
|
||||
canSubmit ? 'btn-outline' : 'btn-disabled'
|
||||
'btn self-end mt-2',
|
||||
canSubmit ? 'btn-outline' : 'btn-disabled',
|
||||
isSubmitting && 'loading'
|
||||
)}
|
||||
disabled={!canSubmit}
|
||||
onClick={submitAnswer}
|
||||
|
@ -434,12 +435,12 @@ function AnswerResolvePanel(props: {
|
|||
const [error, setError] = useState<string | undefined>(undefined)
|
||||
|
||||
const onResolve = async () => {
|
||||
if (answer === undefined) return
|
||||
if (resolveOption === 'CHOOSE' && answer === undefined) return
|
||||
|
||||
setIsSubmitting(true)
|
||||
|
||||
const result = await resolveMarket({
|
||||
outcome: answer,
|
||||
outcome: resolveOption === 'CHOOSE' ? (answer as string) : 'CANCEL',
|
||||
contractId: contract.id,
|
||||
}).then((r) => r.data as any)
|
||||
|
||||
|
|
|
@ -302,8 +302,10 @@ function TruncatedComment(props: {
|
|||
|
||||
function FeedQuestion(props: { contract: Contract }) {
|
||||
const { contract } = props
|
||||
const { creatorName, creatorUsername, question, resolution } = contract
|
||||
const { creatorName, creatorUsername, question, resolution, outcomeType } =
|
||||
contract
|
||||
const { truePool } = contractMetrics(contract)
|
||||
const isBinary = outcomeType === 'BINARY'
|
||||
|
||||
// Currently hidden on mobile; ideally we'd fit this in somewhere.
|
||||
const closeMessage =
|
||||
|
@ -339,11 +341,13 @@ function FeedQuestion(props: { contract: Contract }) {
|
|||
>
|
||||
{question}
|
||||
</SiteLink>
|
||||
<ResolutionOrChance
|
||||
className="items-center"
|
||||
resolution={resolution}
|
||||
probPercent={getBinaryProbPercent(contract)}
|
||||
/>
|
||||
{(isBinary || resolution) && (
|
||||
<ResolutionOrChance
|
||||
className="items-center"
|
||||
resolution={resolution}
|
||||
probPercent={getBinaryProbPercent(contract)}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
<TruncatedComment
|
||||
comment={contract.description}
|
||||
|
|
|
@ -111,7 +111,7 @@ export const ContractOverview = (props: {
|
|||
)}
|
||||
|
||||
{/* Show a delete button for contracts without any trading */}
|
||||
{isCreator && (isBinary ? bets.length <= 2 : bets.length <= 1) && (
|
||||
{isCreator && bets.length === 0 && (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-xs btn-error btn-outline mt-1 max-w-fit self-end"
|
||||
|
|
Loading…
Reference in New Issue
Block a user