diff --git a/common/antes.ts b/common/antes.ts index 52499f1d..979b9d87 100644 --- a/common/antes.ts +++ b/common/antes.ts @@ -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 diff --git a/common/sell-bet.ts b/common/sell-bet.ts index 88191742..cc824386 100644 --- a/common/sell-bet.ts +++ b/common/sell-bet.ts @@ -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 diff --git a/functions/src/resolve-market.ts b/functions/src/resolve-market.ts index 561af9f8..201087d2 100644 --- a/functions/src/resolve-market.ts +++ b/functions/src/resolve-market.ts @@ -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' } diff --git a/web/components/answers-panel.tsx b/web/components/answers-panel.tsx index c41ffded..c269adcb 100644 --- a/web/components/answers-panel.tsx +++ b/web/components/answers-panel.tsx @@ -401,8 +401,9 @@ function CreateAnswerInput(props: { contract: Contract<'MULTI'> }) { )}