Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17] adding draw button #23

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion BetsByteCode.bin

This file was deleted.

26 changes: 22 additions & 4 deletions backend/contracts/Bets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
pragma solidity ^0.8.24;

contract Bets {
// lets use eventType as the following:
// 0: soccer
// 1: basketball
// 2: football
// we will be betting only these sports for the moment
// IMAGES:
// when creating an event pls use this site only:
// https://www.thesportsdb.com/
struct Event {
uint id;
uint eventType;
string name;
string team1;
string team2;
string team1name;
string team2name;
string team1imgurl;
string team2imgurl;
string time;
uint8 result; // 0: Not set, 1: Team1 wins, 2: Team2 wins, 3: Draw
bool isActive;
Expand Down Expand Up @@ -38,11 +49,13 @@ contract Bets {
_;
}

function createEvent(string memory name, string memory team1, string memory team2,string memory time) public onlyOwner {
function createEvent(uint eventType, string memory name, string memory team1name,
string memory team2name, string memory team1imgurl, string memory team2imgurl,
string memory time) public onlyOwner {
// method for event creation
// params: name: name of the event, team1: team1 name, team2: team2 name
// returns: none
events[nextEventId] = Event(nextEventId, name, team1, team2,time, 0, true);
events[nextEventId] = Event(nextEventId, eventType, name, team1name, team2name, team1imgurl, team2imgurl, time, 0, true);
nextEventId++;
}

Expand Down Expand Up @@ -110,4 +123,9 @@ contract Bets {
}
return allEvents;
}

function getEventById(uint _id) public view returns (Event memory) {
Event memory retEvent = events[_id];
return retEvent;
}
}
File renamed without changes.
File renamed without changes.
128 changes: 122 additions & 6 deletions BetsAbi.json → frontend/BetsAbi.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,34 @@
},
{
"inputs": [
{
"internalType": "uint256",
"name": "eventType",
"type": "uint256"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "team1",
"name": "team1name",
"type": "string"
},
{
"internalType": "string",
"name": "team2",
"name": "team2name",
"type": "string"
},
{
"internalType": "string",
"name": "team1imgurl",
"type": "string"
},
{
"internalType": "string",
"name": "team2imgurl",
"type": "string"
},
{
Expand Down Expand Up @@ -147,19 +162,34 @@
"name": "id",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "eventType",
"type": "uint256"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "team1",
"name": "team1name",
"type": "string"
},
{
"internalType": "string",
"name": "team2name",
"type": "string"
},
{
"internalType": "string",
"name": "team1imgurl",
"type": "string"
},
{
"internalType": "string",
"name": "team2",
"name": "team2imgurl",
"type": "string"
},
{
Expand Down Expand Up @@ -192,19 +222,34 @@
"name": "id",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "eventType",
"type": "uint256"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "team1",
"name": "team1name",
"type": "string"
},
{
"internalType": "string",
"name": "team2name",
"type": "string"
},
{
"internalType": "string",
"name": "team1imgurl",
"type": "string"
},
{
"internalType": "string",
"name": "team2",
"name": "team2imgurl",
"type": "string"
},
{
Expand All @@ -231,6 +276,77 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_id",
"type": "uint256"
}
],
"name": "getEventById",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "eventType",
"type": "uint256"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "team1name",
"type": "string"
},
{
"internalType": "string",
"name": "team2name",
"type": "string"
},
{
"internalType": "string",
"name": "team1imgurl",
"type": "string"
},
{
"internalType": "string",
"name": "team2imgurl",
"type": "string"
},
{
"internalType": "string",
"name": "time",
"type": "string"
},
{
"internalType": "uint8",
"name": "result",
"type": "uint8"
},
{
"internalType": "bool",
"name": "isActive",
"type": "bool"
}
],
"internalType": "struct Bets.Event",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
1 change: 1 addition & 0 deletions frontend/BetsByteCode.bin

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/layout.tsx → frontend/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Roboto} from "next/font/google";
import "./globals.css";
import SideBar from "@/src/components/SideBar";
import TopBar from "@/src/components/TopBar";

import "toastify-js/src/toastify.css"
const roboto = Roboto({weight: ["400", "500", "700"], subsets: ["latin"]});

export const metadata: Metadata = {
Expand Down
67 changes: 51 additions & 16 deletions app/match/[id]/page.tsx → frontend/app/match/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import React, {useEffect, useState} from 'react'
import MatchAPI from '@/src/mock/matches.json'
import {MatchElement} from '@/src/config/interfaces/match'
import {setTimeout} from 'timers'

import Bets from '@/src/contracts/BetsContract'
import Toastify from 'toastify-js'

interface MatchProps {
params: {
Expand All @@ -15,24 +16,23 @@ interface MatchProps {

const Match = ({params}: MatchProps) => {

const [ethToBet, setEthToBet] = useState()

const [selectedMatch, setSelectedMatch] = useState<MatchElement>()
const [selectedTeam, setSelectedTeam] = useState<string>('')
const [winner, setwinner] = useState('')
const {matches} = MatchAPI
useEffect(() => {
const filterMatches = () => {
const filteredMatch = matches.filter((match: MatchElement) => {
console.log(match)
return match.idEvent === params.id
})
setSelectedMatch(filteredMatch[0])
const filterMatches = async () => {
const filteredMatch = await Bets.getEventById(parseInt(params.id))
console.log(filteredMatch);
setSelectedMatch(filteredMatch)
}

filterMatches()
}, [])

useEffect(() => {
console.log(selectedTeam)
}, [selectedTeam])

const setBet = (team: string) => {
Expand All @@ -41,10 +41,26 @@ const Match = ({params}: MatchProps) => {
}

const determineWinner = (team: string) => {
if(ethToBet === undefined || ethToBet === 0) {
Toastify({
text: "You can not bet 0 ETH",
duration: 3000,
newWindow: true,
close: true,
gravity: "top", // `top` or `bottom`
position: "left", // `left`, `center` or `right`
stopOnFocus: true, // Prevents dismissing of toast on hover
style: {
background: "linear-gradient(to right, #d9b0b0, #cf1b1b)",
},
onClick: function(){} // Callback after click
}).showToast();
return
}
console.log(`${team} - ${selectedMatch?.strHomeTeam}`)
console.log(`${selectedMatch?.intHomeScore} - ${selectedMatch?.intAwayScore}`)
setTimeout(() => {

if (selectedMatch?.intHomeScore && selectedMatch?.intAwayScore) {
if (selectedMatch?.intHomeScore > selectedMatch?.intAwayScore) {
if (selectedMatch?.strHomeTeam === team) {
Expand All @@ -65,6 +81,8 @@ const Match = ({params}: MatchProps) => {
}, 4000);
}



return (
<div
className=' z-0 w-full h-full flex justify-center items-center py-[5%]'
Expand All @@ -89,30 +107,40 @@ const Match = ({params}: MatchProps) => {
className='flex justify-center items-center gap-10 mt-10'
>
<div
className={`${selectedTeam === selectedMatch?.strHomeTeam ? 'bg-buttonOrange' : 'bg-lightOrange'} cursor-pointer w-[35.4rem] h-[40.9rem] rounded-xl p-10 flex flex-col justify-center items-center`}
className={`${selectedTeam === selectedMatch?.strHomeTeam || selectedTeam === 'draw' ? 'bg-buttonOrange' : 'bg-lightOrange'} cursor-pointer w-[35.4rem] h-[40.9rem] rounded-xl p-10 flex flex-col justify-center items-center`}
onClick={() => setBet(selectedMatch?.strHomeTeam!)}
>
<Image
src={selectedMatch?.strHomeTeamBadge!}
src={selectedMatch?.team1imgurl!}
alt='barca shield'
width={300}
height={300}
className={'drop-shadow-xl'}
/>
</div>
<div className='w-[18.2rem] h-[13.5rem] bg-lightOrange text-white text-5xl flex justify-center items-center rounded-xl'>
<p>
<div className='flex flex-col items-center justify-center gap-10'>
<p className='w-[18.2rem] h-[13.5rem] bg-lightOrange text-white text-5xl flex justify-center items-center rounded-xl'>
{
winner === '' ? 'VS' : winner
}
</p>
<button
className={'bg-buttonOrange text-white text-2xl py-4 px-10 rounded-xl w-[18.2rem] '}
onClick={() => {
setSelectedTeam('draw')
determineWinner('draw')
}}
>
Draw
</button>
</div>
<div
className={`${selectedTeam === selectedMatch?.strAwayTeam ? 'bg-buttonOrange' : 'bg-lightOrange'} cursor-pointer w-[35.4rem] h-[40.9rem] rounded-xl p-10 flex flex-col justify-center items-center`}
className={`${selectedTeam === selectedMatch?.strAwayTeam || selectedTeam === 'draw' ? 'bg-buttonOrange' : 'bg-lightOrange'} cursor-pointer w-[35.4rem] h-[40.9rem] rounded-xl p-10 flex flex-col justify-center items-center`}
onClick={() => setBet(selectedMatch?.strAwayTeam!)}
>

<Image
src={selectedMatch?.strAwayTeamBadge!}
src={selectedMatch?.team2imgurl!}
alt='barca shield'
width={300}
height={300}
Expand All @@ -125,7 +153,14 @@ const Match = ({params}: MatchProps) => {
<div
className='flex flex-col justify-center items-center gap-10 mt-10'
>
<input type="number" max={10} min={0} className='bg-stone-400 placeholder:text-gray-600 p-5 text-2xl w-[17rem] h-[5rem] rounded-xl' placeholder='Place your ETH bet' />
<input
type="number"
max={10}
min={0}
className='bg-stone-400 placeholder:text-gray-600 p-5 text-2xl w-[17rem] h-[5rem] rounded-xl' placeholder='Place your ETH bet'
value={ethToBet}
onChange={(e) => setEthToBet(Number(e.target.value))}
/>
<button
className='bg-buttonOrange text-white text-2xl py-4 px-10 rounded-xl'
>
Expand Down
File renamed without changes.
Loading