Disallow selling after close time! Enforce no trading after close on server.

This commit is contained in:
jahooma 2022-01-10 10:32:20 -06:00
parent 01506fedeb
commit 829c8a4b75
3 changed files with 11 additions and 2 deletions

View File

@ -42,6 +42,10 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
return { status: 'error', message: 'Invalid contract' }
const contract = contractSnap.data() as Contract
const { closeTime } = contract
if (closeTime && Date.now() > closeTime)
return { status: 'error', message: 'Trading is closed' }
const newBetDoc = firestore
.collection(`contracts/${contractId}/bets`)
.doc()

View File

@ -33,6 +33,10 @@ export const sellBet = functions.runWith({ minInstances: 1 }).https.onCall(
return { status: 'error', message: 'Invalid contract' }
const contract = contractSnap.data() as Contract
const { closeTime } = contract
if (closeTime && Date.now() > closeTime)
return { status: 'error', message: 'Trading is closed' }
const betDoc = firestore.doc(`contracts/${contractId}/bets/${betId}`)
const betSnap = await transaction.get(betDoc)
if (!betSnap.exists) return { status: 'error', message: 'Invalid bet' }

View File

@ -308,7 +308,8 @@ function BetRow(props: { bet: Bet; contract: Contract; sale?: Bet }) {
shares,
isSold,
} = bet
const { isResolved } = contract
const { isResolved, closeTime } = contract
const isClosed = closeTime && Date.now() > closeTime
return (
<tr>
@ -333,7 +334,7 @@ function BetRow(props: { bet: Bet; contract: Contract; sale?: Bet }) {
)}
</td>
{!isResolved && !isSold && (
{!isResolved && !isClosed && !isSold && (
<td className="text-neutral">
<SellButton contract={contract} bet={bet} />
</td>