Skip to content

Commit

Permalink
fix leaderboard + update notice
Browse files Browse the repository at this point in the history
  • Loading branch information
sirnicolaz committed Oct 28, 2024
1 parent 757e400 commit 6a9ff4e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion eth/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "@nomicfoundation/hardhat-verify";
import { HardhatUserConfig } from "hardhat/types";

import "solidity-coverage";
//import "./tasks";
import "./tasks";

//import("./tasks").catch((e) => console.log("Cannot load tasks", e.toString()));

Expand Down
14 changes: 7 additions & 7 deletions eth/tasks/admin.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { task } from "hardhat/config";
import { TreasureHuntCreator } from "../typechain";
import { CID } from "multiformats";
import { loadChapters, loadContract } from "./utils";

task("root-set", "Set root CID")
.addPositionalParam("cid", "The file with all chapters")
.setAction(async ({ cid }: { cid: string }, hre) => {
throw "not implemented";
.addPositionalParam("root", "The file with all chapters")
.setAction(async ({ root }: { root: string }, hre) => {
//throw "not implemented";
const thcContract = (await loadContract(
hre,
"TreasureHuntCreator"
)) as TreasureHuntCreator;
console.log(
`Setting root CID ${cid} for contract ${thcContract.getAddress()}`
`Setting root ${root} for contract ${thcContract.getAddress()}`
);
const cidBytes = CID.parse(cid).bytes;
const tx = await thcContract.setup(cidBytes);
const tx = await thcContract.setup(root);

console.log(` Transaction submitted. Waiting for 3 confirmation....`);
const receipt = await tx.wait(3);
console.log(` Root CID successfully set. Receipt: ${receipt?.hash}`);
});

/*
import * as readline from "readline";
const rl = readline.createInterface({
input: process.stdin,
Expand Down Expand Up @@ -87,3 +86,4 @@ task("leaderboard", "Check leaderboard")
const leaderboard = await thcContract.getLeaderboard(page);
console.log(leaderboard);
});
*/
9 changes: 4 additions & 5 deletions web/src/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ function Leaderboard() {
});

useEffect(() => {
console.log(data);
console.log(status);
if (data) {
const bitmaps = data as unknown as bigint[];
const pageContent: LeaderBoardEntry[] = [];
Expand Down Expand Up @@ -70,7 +68,7 @@ function Leaderboard() {
pages[Number(page)] = pageContent;
setPages(pages);
} else {
setPages(pages.concat([pageContent]));
setPages((prevPages) => [...prevPages, ...[pageContent]]);
}

if (pageContent.length === 32) {
Expand All @@ -81,7 +79,8 @@ function Leaderboard() {
}, [data]);

function sortedLeaderboard() {
return pages.flat().sort((x, y) => y.chapter - x.chapter);
const flattened = pages.flat().sort((x, y) => y.chapter - x.chapter);
return flattened;
}

function shortenAddress(address: string | undefined) {
Expand All @@ -103,7 +102,7 @@ function Leaderboard() {
<Tbody>
{sortedLeaderboard().map((entry: LeaderBoardEntry) => {
return (
<Tr>
<Tr key={entry.address}>
<Td>
<ENSName
customDisplay={shortenAddress}
Expand Down
26 changes: 23 additions & 3 deletions web/src/hooks/useChapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,46 @@ import {
} from "../generated";
import { CHAIN_ID } from "../env";
import { useAccount } from "./useAccount";
import { useToast } from "@chakra-ui/react";

function prefixedPasswordKey(key: string) {
return `${import.meta.env.VITE_ALCHEMY_APP_PREFIX}/${key}`;
}

function useRootCID() {
const toast = useToast();
const [root, setRoot] = useState("");
const result = useReadContract({
abi: treasureHuntCreatorAbi,
address:
treasureHuntCreatorAddress[
CHAIN_ID as keyof typeof treasureHuntCreatorAddress
],
functionName: "questsRootCid",
query: {
refetchInterval: 20000,
refetchOnMount: true,
},
});

// fix: use only sporadically, not at every mount and check when it changes
useEffect(() => {
if (result.data !== root) {
if (root !== "" && root !== undefined) {
toast({
title: "Info",
description: "Chapters have been updated!",
status: "info",
duration: 9000,
isClosable: true,
});
}

setRoot(result.data as string);
}
}, [result.data]);

return result.data;
return root;
}

function useCurrentSmartContractChapterIndex(address?: string) {
Expand All @@ -52,7 +74,6 @@ function useCurrentSmartContractChapterIndex(address?: string) {
useEffect(() => {
if (result.data !== undefined) {
setChapter(Number(result.data as bigint));
console.log(result.data);
}
});

Expand Down Expand Up @@ -86,7 +107,6 @@ export function useChapter() {
async function updateChapterContent(chapter: number) {
const response = await fetch(`game-data/${rootCID}/${chapter}`);
const data = await response.text();
console.log(currentSmartContractChapterIndex);
if (chapter > 0) {
const chapterPassword = getChapterPassword(chapter - 1);
const text = await decrypt(data, chapterPassword);
Expand Down
1 change: 0 additions & 1 deletion web/src/hooks/useInterval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export function useInterval(isOn: boolean, interval: number) {
const [rounds, setRounds] = useState(0);

useEffect(() => {
console.log(`${rounds} rounds ${isOn}`);
if (isOn) {
const intervalTimer = setTimeout(() => {
setRounds(rounds + 1);
Expand Down
1 change: 0 additions & 1 deletion web/src/hooks/useSideQuest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function useCurrentSmartContractSideQuestIndex(address?: string) {
.split("")
.filter((k) => k === "1").length;
setSideQuest(solvedKeys);
console.log(solvedKeys);
}
});

Expand Down
1 change: 0 additions & 1 deletion web/src/hooks/useUnifiedAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function useAccount(): UnifiedSigner | undefined {
const { burnerWallet, mnemonic } = useBurnerWallet(); // Your custom HDAccount
const seed = mnemonicToSeedSync(mnemonic);
const { privateKey } = HDKey.fromMasterSeed(seed);
console.log(burnerWallet, privateKey);
/*const { data: wagmiSigner } = useSigner(); // Wagmi's signer
const account = useWagmiAccount();
Expand Down

0 comments on commit 6a9ff4e

Please sign in to comment.