Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/src/components/Navbar.tsx
  • Loading branch information
dwiedenmann committed Mar 17, 2024
2 parents 30bbdb5 + 058cb70 commit 565d093
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"antd": "^5.15.2",
"hardhat-ethers": "^1.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down
91 changes: 89 additions & 2 deletions frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,64 @@ import { Button, Modal, notification } from "antd";
import React, { useState } from "react";
import { useSDK } from "@metamask/sdk-react";
import { Typography } from "antd";
import { FhenixClient, generatePermit } from 'fhenixjs';
import { Contract, Eip1193Provider, ethers } from 'ethers';
import type { SupportedProvider, HardhatEthersProvider } from "fhenixjs";
import { BrowserProvider } from "ethers";


type ExtendedProvider = SupportedProvider & {
getTransactionReceipt(txHash: string): Promise<ethers.TransactionReceipt>;
send(method: string, params: any[] | Record<string, any>): Promise<any>;
getSigner(): Promise<any>;
getBalance(address: string): Promise<any>;
};


const Navbar: React.FC = () => {
const [api] = notification.useNotification();

const { Text, Link } = Typography;
const [account, setAccount] = useState<string>();
const { sdk, connected, connecting, provider, chainId } = useSDK();
const { sdk, connected, connecting, chainId } = useSDK();
const metaMaskAccount = (
<Button shape="round" type="primary" className={"bg-primary"}>
{account}
</Button>
);
var provider = new BrowserProvider(window.ethereum as Eip1193Provider);
// const client = new FhenixClient({provider});

//const provider = new BrowserProvider(window.ethereum);


const abi = ["function startGame() public", "function joinGame() public", "function bet() public"]
//const signer = account;

//const signer = await provider.getSigner();


const contract = new Contract("0x0", abi);
//const auctionContract = new ethers.Contract(TokenContractDeployment.address, ExampleToken.abi, signer);


function getProvider() {
if (provider === null) {
// @ts-ignore
provider = new BrowserProvider(window.ethereum);
}
return provider;
}

//function initFHEClient() {
// fheClient.value = new FhenixClient({ provider: provider as HardhatEthersProvider as SupportedProvider });
//}

//function getFheClient() {
// return fheClient.value;
// }


const connect = async () => {
try {
const accounts = await sdk?.connect();
Expand All @@ -27,6 +72,48 @@ const Navbar: React.FC = () => {
}
};

const startGame = async () => {
try {
provider = getProvider();
const signer = await provider.getSigner();
const contract = new Contract("0x82FBF91aE0093Eeac15D7941cD2a2Db6B4bbbAd2", abi, signer);
const tx = await contract.startGame();
await tx.wait();
console.log(tx);
} catch (err) {
console.warn("failed to start game..", err);
openNotification();
}
}

const joinGame = async () => {
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 tx = await contract.joinGame();
await tx.wait();
console.log(tx);
} catch (err) {
console.warn("failed to join game..", err);
openNotification();
}
}

const openNotification = () => {
api.info({
message: `Connection failed`,
Expand All @@ -41,7 +128,7 @@ const Navbar: React.FC = () => {
<Button type={"primary"} className="text-table_black bg-cgrey">
{account}
</Button>
<Button type={"primary"} className="text-table_black bg-cgrey">
<Button type={"primary"} className="text-table_black bg-cgrey" onClick={joinGame}>
{account}
</Button>

Expand Down

0 comments on commit 565d093

Please sign in to comment.