Disallow selling after close time! Enforce no trading after close on server.
This commit is contained in:
parent
01506fedeb
commit
829c8a4b75
|
@ -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()
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user