Skip to content

Commit

Permalink
fix: ui was broken for some timer and treaty related things
Browse files Browse the repository at this point in the history
  • Loading branch information
rsproule committed Jan 5, 2024
1 parent 46a210f commit 18c6dd5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
Binary file modified frontend/bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@radix-ui/react-toast": "^1.1.4",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@vercel/analytics": "^1.0.1",
"@wagmi/cli": "^1.1.0",
"@wagmi/cli": "^1.5.2",
"autoprefixer": "^10.4.14",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
Expand All @@ -49,7 +49,7 @@
"tailwindcss-animate": "^1.0.6",
"tiled-hexagons": "^1.0.2",
"viem": "^1.16.6",
"wagmi": "^1.4.5",
"wagmi": "^1.4.5",
"zod": "^3.21.4"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/tankGame/TankGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ export function TankGame({ address }: { address: `0x${string}` }) {
boardSize={settings.data && settings.data!.boardSize}
gameAddress={address}
/>
<div className="block justify-evenly py-5 md:flex">
<Timer address={address} />
</div>
<Treaties gameAddress={address} />
<div className="block justify-evenly py-5 md:flex">
{gameState.data === 1 && <Timer address={address} />}
{/* {gameState.data === 1 && <Timer address={address} />} */}
{gameState.data === 2 && <GameOver gameAddress={address} />}
{gameState.data !== 2 && <Donate gameAddress={address} />}
</div>
Expand Down
40 changes: 25 additions & 15 deletions frontend/src/components/tankGame/Timer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
gameViewAddress,
useGameViewGetGameEpoch,
useGameViewGetEpoch,
useGameViewGetSettings,
usePrepareTankGameReveal,
Expand Down Expand Up @@ -28,6 +29,12 @@ export default function Timer({ address }: { address: `0x${string}` }) {
// @ts-ignore
address: address,
});
const currentGameEpoch = useGameViewGetGameEpoch({
watch: true,
// @ts-ignore
address: gameViewAddress[chain?.id as keyof typeof gameViewAddress],
args: [address],
});
const currentEpoch = useGameViewGetEpoch({
watch: true,
// @ts-ignore
Expand Down Expand Up @@ -71,22 +78,25 @@ export default function Timer({ address }: { address: `0x${string}` }) {
</CardHeader>
<CardContent>
<>
Current Epoch:{" "}
{currentEpoch.data &&
startEpoch.data &&
(currentEpoch.data! - startEpoch.data!).toString()}
Current Game Epoch: {currentGameEpoch.data?.toString()}
<br />
Current Epoch: {currentEpoch.data?.toString()}
<br />
Time till next epoch:{" "}
{currentEpoch.data &&
settings.data &&
secondsToHMS(
Number(
getTimeTillNextEpoch(
currentEpoch.data!,
settings.data?.epochSeconds!
)
)
)}
{currentGameEpoch ?? currentGameEpoch.data == BigInt(0) ?? (
<>
Time till next epoch:
{currentEpoch.data &&
settings.data &&
secondsToHMS(
Number(
getTimeTillNextEpoch(
currentEpoch.data!,
settings.data?.epochSeconds!
)
)
)}
</>
)}
</>
</CardContent>
<CardFooter>
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/components/treaties/NonAggression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
nonAggressionABI,
usePrepareNonAggressionAccept,
useNonAggressionAccept,
useGameViewGetEpoch,
gameViewAddress,
useGameViewGetGameEpoch,
usePrepareITreatyAccept,
} from "@/src/generated";
import { useState, useEffect } from "react";
import { Address, BaseError } from "viem";
Expand Down Expand Up @@ -94,9 +94,11 @@ export default function NonAggression({
};
getLogs();
}, [hookAddress, blockNumber, epoch]);

const tankName = useTankNameFromId(gameAddress, tankId);
const { config: acceptConfig } = usePrepareNonAggressionAccept({
args: [tankId, hookAddress],
address: ownerHookAddress, // should be MY hook address
args: [tankId, hookAddress], // the information for the treaty we want to accept
address: ownerHookAddress, // MY hook address
});
const { write: accept, data: acceptData } =
useNonAggressionAccept(acceptConfig);
Expand All @@ -119,7 +121,6 @@ export default function NonAggression({
},
});

const tankName = useTankNameFromId(gameAddress, tankId);
return (
<div className="">
{treaties &&
Expand Down Expand Up @@ -186,7 +187,9 @@ function BountyComponent({
<button
className="bg-white text-black px-2 disabled:opacity-50 enabled:cursor-pointer"
disabled={!accept}
onClick={() => accept?.()}
onClick={() => {
accept?.();
}}
>
Accept
</button>
Expand Down

0 comments on commit 18c6dd5

Please sign in to comment.