From eee21513c75aaca63cfcdda966f0a5009339e276 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 17 Mar 2024 07:26:22 +0100 Subject: [PATCH] fixes --- contracts/poker.sol | 2 +- frontend/src/components/Navbar.tsx | 20 ++------ frontend/src/components/Table.tsx | 81 ++++++++++++++++++++++++++++-- 3 files changed, 80 insertions(+), 23 deletions(-) diff --git a/contracts/poker.sol b/contracts/poker.sol index 23c1a55..05f0140 100644 --- a/contracts/poker.sol +++ b/contracts/poker.sol @@ -370,7 +370,7 @@ contract Poker is Permissioned { } function gameState() - public + external view returns ( uint256 playerCount, diff --git a/frontend/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx index eda5d85..9d7e12b 100644 --- a/frontend/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -33,7 +33,7 @@ const Navbar: React.FC = () => { //const provider = new BrowserProvider(window.ethereum); - const abi = ["function startGame() public", "function joinGame() public", "function bet() public"] + const abi = ["function startGame() public", "function joinGame() public", "function bet() public"]; //const signer = account; //const signer = await provider.getSigner(); @@ -76,7 +76,7 @@ const Navbar: React.FC = () => { try { provider = getProvider(); const signer = await provider.getSigner(); - const contract = new Contract("0x82FBF91aE0093Eeac15D7941cD2a2Db6B4bbbAd2", abi, signer); + const contract = new Contract("0xd386fD42c8C65A345646F4E0683DfF9EcA0c2716", abi, signer); const tx = await contract.startGame(); await tx.wait(); console.log(tx); @@ -90,21 +90,7 @@ const Navbar: React.FC = () => { try { provider = getProvider(); const signer = await provider.getSigner(); - const contract = new Contract("0x82FBF91aE0093Eeac15D7941cD2a2Db6B4bbbAd2", abi, signer); - const tx = await contract.joinGame(); - await tx.wait(); - console.log(tx); - } catch (err) { - console.warn("failed to join game..", err); - openNotification(); - } - } - - const bet = async () => { - try { - provider = getProvider(); - const signer = await provider.getSigner(); - const contract = new Contract("0x82FBF91aE0093Eeac15D7941cD2a2Db6B4bbbAd2", abi, signer); + const contract = new Contract("0xd386fD42c8C65A345646F4E0683DfF9EcA0c2716", abi, signer); const tx = await contract.joinGame(); await tx.wait(); console.log(tx); diff --git a/frontend/src/components/Table.tsx b/frontend/src/components/Table.tsx index 1d42a51..d6208a9 100644 --- a/frontend/src/components/Table.tsx +++ b/frontend/src/components/Table.tsx @@ -1,14 +1,85 @@ -import React, {useState} from "react" +import React, {useState, useEffect} from "react" import cardBackground from "../CryptoHoldem_assests/Cards new/Card Background.png" +import { Button, Modal, notification } from "antd"; + + import playerOne from "../CryptoHoldem_assests/Player/head-cat.png" import playerPlaceholder from "../CryptoHoldem_assests/Player/Placeholder Player/Placeholder Player 3.svg" import mainPlayer from "../CryptoHoldem_assests/Player/head-whale-alive.png" import roundTable from "../CryptoHoldem_assests/Rest/Pixel Table.png" +import { Contract, Eip1193Provider, ethers } from 'ethers'; + +import { BrowserProvider } from "ethers"; +import { use } from "chai"; + const Table: React.FC = () => { + const [api] = notification.useNotification(); + + useEffect(() => { + const interval = setInterval(() => { + getState(); + }, 500); + + return () => clearInterval(interval); + }, []); + + const abi = ["function bet() public", "function fold() public", "function getState() public view"]; + + var provider = new BrowserProvider(window.ethereum as Eip1193Provider); + function getProvider() { + if (provider === null) { + // @ts-ignore + provider = new BrowserProvider(window.ethereum); + } + return provider; + } + + const bet = async () => { + try { + provider = getProvider(); + const signer = await provider.getSigner(); + const contract = new Contract("0xd386fD42c8C65A345646F4E0683DfF9EcA0c2716", abi, signer); + const tx = await contract.bet(); + await tx.wait(); + console.log(tx); + } catch (err) { + console.warn("failed to bet..", err); + //openNotification(); + } + } + + const getState = async () => { + try { + provider = getProvider(); + const signer = await provider.getSigner(); + const contract = new Contract("0xd386fD42c8C65A345646F4E0683DfF9EcA0c2716", abi, signer); + const tx = await contract.getState(); + await tx.wait(); + console.log(tx); + } catch (err) { + console.warn("failed to get state...", err); + //openNotification(); + } + } + + const fold = async () => { + try { + provider = getProvider(); + const signer = await provider.getSigner(); + const contract = new Contract("0xd386fD42c8C65A345646F4E0683DfF9EcA0c2716", abi, signer); + const tx = await contract.fold(); + await tx.wait(); + console.log(tx); + } catch (err) { + console.warn("failed to fold..", err); + //openNotification(); + } + } + return (
@@ -19,15 +90,15 @@ const Table: React.FC = () => {

2000$

-