-
Notifications
You must be signed in to change notification settings - Fork 1
/
BetForm.js
60 lines (49 loc) · 1.97 KB
/
BetForm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { useState, useEffect } from 'react';
const BetForm = ({currentMatch, theContract}) => {
const [betAmount, setBetAmount] = useState('');
const [team, setTeam] = useState('');
const matchName = currentMatch[0]
const [potentialWinnings, setPotentialWinnings] = useState(0.0);
const handleSubmit = (e) => {
e.preventDefault();
theContract.makeBet(matchName, team, betAmount)
}
useEffect(() => {
setTeam('default');
setBetAmount('')
}, [currentMatch]);
useEffect(() => {
if (betAmount == '') {
setPotentialWinnings(0)
}
if (team != 'default' && team != '' && betAmount != '' ) {
console.log(team)
theContract.getPotentialWinnings({ matchId: matchName, team: team, betAmount: betAmount }).then(setPotentialWinnings)
}
}, [team, betAmount]);
return (
<div className='box'>
<form onSubmit={handleSubmit}>
<label className='bet-text'>Ⓝ Bet Amount</label>
<input className='bet-input'
type='text'
required
value = { betAmount }
onChange={(e) => setBetAmount(e.target.value)}/>
<label className='bet-text'>Team</label>
<select
className='bet-select'
value={ team }
onChange={(e) => setTeam(e.target.value)}
>
<option value={'default'}>Select Team</option>
<option value={ currentMatch[1] }>{ currentMatch[1] }</option>
<option value={ currentMatch[3] }>{ currentMatch[3] }</option>
</select>
<p className='pot-win'>Ⓝ Potential Winnings <br />{ potentialWinnings }</p>
<button className='bet-button' disabled={(team == 'default')}>Make bet</button>
</form>
</div>
);
}
export default BetForm;