ensure bet amounts are positive
This commit is contained in:
parent
6398f93ffe
commit
abb5d53431
|
@ -32,7 +32,10 @@ export const createContract = functions
|
|||
if (!question || !initialProb)
|
||||
return { status: 'error', message: 'Missing contract attributes' }
|
||||
|
||||
if (ante !== undefined && (ante < 0 || ante > creator.balance))
|
||||
if (
|
||||
ante !== undefined &&
|
||||
(ante < 0 || ante > creator.balance || isNaN(ante) || !isFinite(ante))
|
||||
)
|
||||
return { status: 'error', message: 'Invalid ante' }
|
||||
|
||||
console.log(
|
||||
|
|
|
@ -19,6 +19,9 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
|||
|
||||
const { amount, outcome, contractId } = data
|
||||
|
||||
if (amount <= 0 || isNaN(amount) || !isFinite(amount))
|
||||
return { status: 'error', message: 'Invalid amount' }
|
||||
|
||||
if (outcome !== 'YES' && outcome !== 'NO')
|
||||
return { status: 'error', message: 'Invalid outcome' }
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ export function BetPanel(props: { contract: Contract; className?: string }) {
|
|||
function onBetChange(str: string) {
|
||||
setWasSubmitted(false)
|
||||
|
||||
const amount = parseInt(str)
|
||||
const amount = parseInt(str.replace(/[^\d]/, ''))
|
||||
|
||||
if (str && isNaN(amount)) return
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ export default function NewContract() {
|
|||
}
|
||||
|
||||
function onAnteChange(str: string) {
|
||||
const amount = parseInt(str)
|
||||
const amount = parseInt(str.replace(/[^\d]/, ''))
|
||||
|
||||
if (str && isNaN(amount)) return
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user