Skip to content

Commit

Permalink
Enforce max bid to stop people ruining the demo (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmellor authored Jun 25, 2024
1 parent a132865 commit 2c08ece
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const ItemModal = () => {
const { activeItem, openModal, closeModal } = useContext(ModalsContext);
const [secondaryImageSrc, setSecondaryImageSrc] = useState("");
const minIncrease = 1;
const maxIncrease = 10;
const [bid, setBid] = useState();
const [valid, setValid] = useState("");
const [isSubmitting, setIsSubmitting] = useState("");
Expand Down Expand Up @@ -114,6 +115,13 @@ const ItemModal = () => {
setIsSubmitting(false);
return;
}
// Ensure input is small enough
if (amount > status.amount + maxIncrease) {
setFeedback(`For the demo you can only increase the price up to ${activeItem.currency}${maxIncrease} per bid.`);
setValid("is-invalid");
setIsSubmitting(false);
return;
}
// Finally, place bid
updateDoc(doc(db, "auction", "items"), {
[formatField(activeItem.id, status.bids + 1)]: {
Expand Down

0 comments on commit 2c08ece

Please sign in to comment.