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
2 changes: 1 addition & 1 deletion 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
51 changes: 44 additions & 7 deletions app/match/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 Toastify from 'toastify-js'

interface MatchProps {
params: {
Expand All @@ -15,6 +15,8 @@ interface MatchProps {

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

const [ethToBet, setEthToBet] = useState()

const [selectedMatch, setSelectedMatch] = useState<MatchElement>()
const [selectedTeam, setSelectedTeam] = useState<string>('')
const [winner, setwinner] = useState('')
Expand All @@ -41,10 +43,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}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this logs

setTimeout(() => {

if (selectedMatch?.intHomeScore && selectedMatch?.intAwayScore) {
if (selectedMatch?.intHomeScore > selectedMatch?.intAwayScore) {
if (selectedMatch?.strHomeTeam === team) {
Expand All @@ -65,6 +83,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,7 +109,7 @@ 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
Expand All @@ -100,17 +120,27 @@ const Match = ({params}: MatchProps) => {
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!}
alt='barca shield'
Expand All @@ -125,7 +155,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
16 changes: 10 additions & 6 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
import Image from "next/image";
import Link from "next/link";
import getAllEvents from "@/src/contracts/BetsContract";

import matchAPI from "@/src/mock/matches.json";
import {Match, MatchElement} from "@/src/config/interfaces/match";
export default async function Home() {
var matchFetch = await getAllEvents();
const matches = matchFetch;
//TODO: uncomment the 2 lines below
// var matchFetch = await getAllEvents();
// const matches = matchFetch;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to leave this commented?

const matches:Match = matchAPI;

return (
<div className='flex justify-evenly gap-10 flex-wrap p-10'>
{
matches.matches?.map((match: any) => (
{//TODO: chage the type of match
matches.matches?.map((match:MatchElement |any) => (
<div
key={match?.id}
className={'w-[43rem] h-[30.9rem] bg-lightGray rounded-xl p-10 flex flex-col justify-between items-center'}
Expand Down Expand Up @@ -45,7 +48,8 @@ export default async function Home() {

<Link
className={' bg-buttonOrange text-white text-2xl p-5 rounded-xl'}
href={`match/${match.id}`}
//TODO: href={`match/${match.id}`}
href={`match/${match.idEvent}`}
>
Bet
</Link>
Expand Down
Loading