ensure bet amounts are positive

This commit is contained in:
mantikoros 2022-01-08 11:51:31 -06:00
parent 6398f93ffe
commit abb5d53431
4 changed files with 9 additions and 3 deletions

View File

@ -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(

View File

@ -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' }

View File

@ -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

View File

@ -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