1 | import React from 'react'
|
---|
2 |
|
---|
3 | import { GiTwoCoins } from 'react-icons/gi'
|
---|
4 | import { AiOutlineClose } from 'react-icons/ai'
|
---|
5 |
|
---|
6 | import { useSelector, useDispatch } from 'react-redux'
|
---|
7 | import { setRoulette } from '../../redux/reducers/styleSlice';
|
---|
8 |
|
---|
9 | import axios from 'axios';
|
---|
10 | import { setPlayer, setRouletteGame } from '../../redux/reducers/playerSlice';
|
---|
11 |
|
---|
12 | const BetModal = () => {
|
---|
13 | const dispatch = useDispatch();
|
---|
14 |
|
---|
15 | const playerState = useSelector(state => state.player);
|
---|
16 | const styleState = useSelector(state => state.style);
|
---|
17 |
|
---|
18 | function chooseBet(e) {
|
---|
19 | dispatch(setRoulette({
|
---|
20 | ...styleState.roulette,
|
---|
21 | inputControls: {
|
---|
22 | ...styleState.roulette.inputControls,
|
---|
23 | bet: {
|
---|
24 | ...styleState.roulette.inputControls.bet,
|
---|
25 | chosenCredits: parseInt(e.target.value),
|
---|
26 | }
|
---|
27 | }
|
---|
28 | }));
|
---|
29 | }
|
---|
30 |
|
---|
31 | function placeBet() {
|
---|
32 | axios.get(`/api/roulette?action=place_bet&session_id=${localStorage.CAESSINO_SESSION_ID}&betAmount=${styleState.roulette.inputControls.bet.chosenCredits}&whichBets=${styleState.roulette.whichBets.toString()}&coinPlacedX=${styleState.roulette.coinPlaced.x}&coinPlacedY=${styleState.roulette.coinPlaced.y}`);
|
---|
33 |
|
---|
34 | closeModal();
|
---|
35 | }
|
---|
36 |
|
---|
37 | function closeModal() {
|
---|
38 | dispatch(setRoulette({
|
---|
39 | ...styleState.roulette,
|
---|
40 | displays: {
|
---|
41 | ...styleState.roulette.displays,
|
---|
42 | betModal: false,
|
---|
43 | },
|
---|
44 | }));
|
---|
45 | }
|
---|
46 |
|
---|
47 | return (
|
---|
48 | <div className="rouletteBetModal" style={{display: styleState.roulette.displays.betModal && playerState.rouletteGame.game.timeToStart > 10 && playerState.rouletteGame.game.timeToStart <= playerState.rouletteGame.game.COUNTDOWN_FROM ? 'flex' : 'none'}}>
|
---|
49 | <p>You have chosen to bet on: <span>{styleState.roulette.whichBets.map((bet, i) => `${bet} `)}</span><br/>Please select the amount you will bet</p>
|
---|
50 | <div>
|
---|
51 | <div>
|
---|
52 | <input type="range" className="primarySlider" min={0} max={playerState.player.credits} step={1} value={styleState.roulette.inputControls.bet.chosenCredits} onChange={(e) => chooseBet(e)} />
|
---|
53 | <div style={{marginTop: '15px', marginBottom: '-30px'}}>
|
---|
54 | <span>${styleState.roulette.inputControls.bet.chosenCredits}</span>
|
---|
55 | </div>
|
---|
56 | </div>
|
---|
57 | <button style={{marginTop: '50px'}} className="primaryButton" onClick={() => placeBet()}>Place Bet <GiTwoCoins style={{marginTop: '3px', marginBottom: '-3px'}} /></button>
|
---|
58 | <br/>
|
---|
59 | <button style={{position: 'absolute', bottom: '10%', left: '50%', transform: 'translateX(-50%)'}} className="tertiaryButton" onClick={() => closeModal()}>Cancel <AiOutlineClose style={{marginTop: '3px', marginBottom: '-3px'}} /></button>
|
---|
60 | </div>
|
---|
61 | </div>
|
---|
62 | )
|
---|
63 | }
|
---|
64 |
|
---|
65 | export default BetModal |
---|