1
0

Added a security check in the Input.jsx

This commit is contained in:
Mathias Wagner 2023-11-20 21:19:53 +01:00
parent 3bb64ff767
commit b23504244e
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -4,7 +4,7 @@ import {useEffect, useState} from "react";
import {socket} from "@/common/utils/socket.js"; import {socket} from "@/common/utils/socket.js";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
export const Input = ({setState}) => { export const Input = ({setState, capital}) => {
const [price, setPrice] = useState(1000); const [price, setPrice] = useState(1000);
const [amount, setAmount] = useState(10); const [amount, setAmount] = useState(10);
@ -12,6 +12,11 @@ export const Input = ({setState}) => {
const [error, setError] = useState(""); const [error, setError] = useState("");
const submit = () => { const submit = () => {
if ((1000 * amount + 4000) > capital) {
setError("Zu wenig Kapital");
return;
}
socket.emit("SUBMIT", {price, amount}, (data) => { socket.emit("SUBMIT", {price, amount}, (data) => {
if (data) { if (data) {
setState("waiting"); setState("waiting");
@ -22,9 +27,10 @@ export const Input = ({setState}) => {
} }
useEffect(() => { useEffect(() => {
if (!error) return;
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
setError(""); setError("");
}, 30000); }, 5000);
return () => clearTimeout(timeout); return () => clearTimeout(timeout);
}, [error]); }, [error]);