Skip to content
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PRISMA_URL="Url comes here"
PRISMA_URL="posgresql://postgres:treasurehunt_123_@db.siecxsbqymysnrfdinzh.supabase.co.5432/postgres"
NEXT_PUBLIC_SITE_URL=http://localhost:3000
NEXTAUTH_SECRET=secretishere
4 changes: 4 additions & 0 deletions .well-known/brave-rewards-verification.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a Brave Creators publisher verification file.

Domain: treasure-hunt-five.vercel.app
Token: e536af5c3ac28ee1ceaf866deab98665c7946837b1d0445e60ca64d602b58310
5 changes: 4 additions & 1 deletion app/_components/BtnStartGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import useSound from "./useSound";
import { useEffect } from "react";

const BtnStartGame = () => {
const walletAddress =
typeof window !== "undefined" ? localStorage.getItem("account") : null;

// const bgMusic = useSound("bg");
// useEffect(() => {
// window.addEventListener("click", () => {
Expand All @@ -20,7 +23,7 @@ const BtnStartGame = () => {
className="hover relative h-[80px] w-[80px] md:h-[100px] md:w-[100px]"
style={{ top: "38%", left: "5px" }}
>
<Link href={"/games/1"}>
<Link href={`/games/1/${walletAddress}`}>
<Image
src={"/startBtn.png"}
alt="start game"
Expand Down
50 changes: 48 additions & 2 deletions app/_components/GameScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import Icon from "./icons/Icon";
import { useRouter } from "next/navigation";
import { changeOrientation, debounce } from "@/constants";
import useSound from "../_components/useSound";
import { getContract } from "../ethereum";
import Lock from "../../artifacts/contracts/Lock.sol/Lock.json";
import { ethers } from "ethers";
import { parse } from "path";

const dummyItems = [
{
name: "skullArt",
Expand Down Expand Up @@ -53,15 +58,53 @@ const dummyItems = [
},
];

function GameScreen({ id, screen = "screen1", items = dummyItems }) {
function GameScreen({
id,
screen = "screen1",
walletAddress,
items = dummyItems,
}) {
const bgMusic = useSound("bg", 0, 0.05);
const [contract, setContract] = useState(null);
useEffect(() => {
bgMusic.play();
return () => {
bgMusic.pause();
bgMusic.currentTime = 0;
};
}, []);

useEffect(() => {
async function initContract() {
const contract = getContract(
"0xfB40daE09C54ec8eB653f8cb140e0569202e3ac2",
Lock.abi,
0
);
setContract(contract);
}
initContract();
}, []);

async function sendETH(walletAddress, amountToSend) {
try {
if (!contract) return;
const tx = await contract.sendEther(walletAddress, amountToSend, {
gasLimit: 50000,
});
const receipt = await tx.wait();
const transactionHash = receipt.transactionHash;
console.log("Transaction Hash:", transactionHash);
if (receipt.status === 1) {
console.log("ETH sent successfully!");
} else {
console.error("Transaction failed");
}
} catch (error) {
console.error(error);
}
}

const winSound = useSound("win", 0, 1, false);
const height = 672;
const router = useRouter();
Expand All @@ -76,7 +119,10 @@ function GameScreen({ id, screen = "screen1", items = dummyItems }) {
if (itemIndex > items.length - 1) {
setTimeout(() => {
alert("You won!");
router.push(`/games/${id}/result`);
const parsedAmount = ethers.parseEther("0.0001");
const stringAmount = parsedAmount.toString();
sendETH(walletAddress, stringAmount);
router.push(`/games/${id}/${walletAddress}/result`);
}, 3000);
return;
}
Expand Down
35 changes: 35 additions & 0 deletions app/_components/header.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
"use client";
import ButtonLogout from "./ButtonLogout";
import Logo from "./Logo";
import Image from "next/image";
import { useState, useEffect } from "react";

const Header = () => {
const [wallet, setWallet] = useState("");
const [account, setAccount] = useState("");

useEffect(() => {
const storedAccount = localStorage.getItem("account");
if (storedAccount) {
setAccount(storedAccount);
}
}, []);

async function Connect() {
console.log("connecting...");
if (window.ethereum) {
console.log("ethereum");
const accounts = await window.ethereum.request({
method: "eth_requestAccounts",
});
console.log(accounts);
setWallet(accounts[0]);
localStorage.setItem("account", accounts[0]);
} else {
console.log("not ethereum");
}
}
return (
<section className="flex items-center justify-between py-2 btmBorder">
<Logo />
<button style={{ display: "flex" }} onClick={Connect}>
<Image src="/metamask.png" height={24} width={24} />
{!wallet ? (
<span>Connect to Metamask</span>
) : (
<span>Welcome {wallet}</span>
)}
</button>
<ButtonLogout />
</section>
);
Expand Down
25 changes: 25 additions & 0 deletions app/ethereum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ethers } from "ethers";

const localProvider = new ethers.JsonRpcProvider(
"https://eth-sepolia.g.alchemy.com/v2/gYfnM2-fUz9hK-kuLqKisnmaU4U4xO8u"
);
const private_key =
"aa62de3f5c5de102bafe19bbc908b21e3d687bf426daf49ac361d75efcbca28a";

export const getProvider = () => {
return localProvider;
};

export const getSigner = () => {
const wallet = new ethers.Wallet(private_key, localProvider);
console.log(wallet);
const signer = wallet.connect(localProvider);

return signer;
};

export const getContract = (address, abi) => {
const signer = getSigner();
const contract = new ethers.Contract(address, abi, signer);
return contract;
};
13 changes: 13 additions & 0 deletions app/games/[id]/[walletAddress]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import GameScreen from "../../../_components/GameScreen";
const page = ({ params }) => {
const { id, walletAddress } = params;
return (
<>
<div className="flex flex-wrap w-full h-full justify-center content-end pb-5 mt-5">
<GameScreen id={id} walletAddress={walletAddress} />
</div>
</>
);
};

export default page;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const page = () => {
return (
<div className="fccc w-full h-full p-20 gap-y-10 max-w-[1000px] self-center">
<h1 className="">Congratulations! You have won the game!</h1>
<h3>Top 3 winners will get ethereum rewards.</h3>
<h3>You will get 0.0001 ETH.</h3>
<button
className="btnPrimary"
onClick={() => {
Expand Down
16 changes: 0 additions & 16 deletions app/games/[id]/page.js

This file was deleted.

2 changes: 2 additions & 0 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import Header from "./_components/header";
import Hero from "./_components/Hero";
import HeroImg from "./_components/HeroImg";
Expand Down
1 change: 0 additions & 1 deletion artifacts/build-info/0ba343146aa1a3861a39c5b209f50dc9.json

This file was deleted.

1 change: 1 addition & 0 deletions artifacts/build-info/414c8279420911d3fc65c57f34e8b19e.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifacts/contracts/Lock.sol/Lock.dbg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "..\\..\\build-info\\0ba343146aa1a3861a39c5b209f50dc9.json"
"buildInfo": "..\\..\\build-info\\414c8279420911d3fc65c57f34e8b19e.json"
}
Loading