Check balance before creation
This commit is contained in:
parent
ac4964f058
commit
0d6b18877f
|
@ -1,5 +1,5 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
import { Title } from '../title'
|
import { Title } from '../title'
|
||||||
|
@ -79,6 +79,7 @@ function CreateChallengeForm(props: {
|
||||||
const [isCreating, setIsCreating] = useState(false)
|
const [isCreating, setIsCreating] = useState(false)
|
||||||
const [finishedCreating, setFinishedCreating] = useState(false)
|
const [finishedCreating, setFinishedCreating] = useState(false)
|
||||||
const [copyPressed, setCopyPressed] = useState(false)
|
const [copyPressed, setCopyPressed] = useState(false)
|
||||||
|
const [error, setError] = useState<string>('')
|
||||||
setTimeout(() => setCopyPressed(false), 300)
|
setTimeout(() => setCopyPressed(false), 300)
|
||||||
const defaultExpire = 'week'
|
const defaultExpire = 'week'
|
||||||
const isBinary = contract.outcomeType === 'BINARY'
|
const isBinary = contract.outcomeType === 'BINARY'
|
||||||
|
@ -93,6 +94,9 @@ function CreateChallengeForm(props: {
|
||||||
prob: Math.round(getOutcomeProbability(contract, 'YES') * 100),
|
prob: Math.round(getOutcomeProbability(contract, 'YES') * 100),
|
||||||
message: defaultMessage,
|
message: defaultMessage,
|
||||||
})
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
setError('')
|
||||||
|
}, [challengeInfo])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -100,6 +104,10 @@ function CreateChallengeForm(props: {
|
||||||
<form
|
<form
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
if (user.balance < challengeInfo.amount) {
|
||||||
|
setError('You do not have enough mana to create this challenge')
|
||||||
|
return
|
||||||
|
}
|
||||||
setIsCreating(true)
|
setIsCreating(true)
|
||||||
onCreate(challengeInfo).finally(() => setIsCreating(false))
|
onCreate(challengeInfo).finally(() => setIsCreating(false))
|
||||||
setFinishedCreating(true)
|
setFinishedCreating(true)
|
||||||
|
@ -227,6 +235,7 @@ function CreateChallengeForm(props: {
|
||||||
Create
|
Create
|
||||||
</Button>
|
</Button>
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row className={'text-error'}>{error} </Row>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
{finishedCreating && (
|
{finishedCreating && (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user