Skip to content

Commit

Permalink
feat: ui updates, check joined
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasgrusz committed Jun 2, 2024
1 parent 9a672db commit ade83cb
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 159 deletions.
15 changes: 13 additions & 2 deletions packages/nextjs/app/_components/Bounty/Bounty.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import styles from "./Bounty.module.scss";
import { IoIosLock } from "react-icons/io";
import { IoCheckmarkCircleOutline } from "react-icons/io5";
import { useAccount } from "wagmi";
import { Bounty as BountyType } from "~~/types/bounty";

export type BountyProps = BountyType & {
progress: number;
};

const Bounty: React.FC<BountyProps> = ({ title, description, creator, reward, duration, progress, maxProgress }) => {
const joined = Math.random() > 0.5 ? false : true;
const Bounty: React.FC<BountyProps> = ({
title,
description,
creator,
reward,
duration,
progress,
maxProgress,
submissions,
}) => {
const account = useAccount();
const joined = submissions.some(submission => submission.submitter.toLowerCase() === account.address?.toLowerCase());
const finished = progress >= maxProgress;

return (
Expand Down
5 changes: 4 additions & 1 deletion packages/nextjs/app/_components/BountyInfo/BountyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react";
import styles from "./BountyInfo.module.scss";
import { IoIosDownload, IoIosLock } from "react-icons/io";
import { IoCheckmarkCircleOutline, IoCloudUpload } from "react-icons/io5";
import { useAccount } from "wagmi";
import { Bounty } from "~~/types/bounty";

export type BountyInfoProps = Bounty & {
Expand All @@ -16,6 +17,7 @@ const BountyInfo: React.FC<BountyInfoProps> = ({
duration,
progress,
maxProgress,
submissions,
}) => {
const [file, setFile] = useState<File | null>(null);
const uploadFile = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -26,7 +28,8 @@ const BountyInfo: React.FC<BountyInfoProps> = ({
}
};

const joined = Math.random() > 0.5 ? false : true;
const account = useAccount();
const joined = submissions.some(submission => submission.submitter.toLowerCase() === account.address?.toLowerCase());
const finished = progress >= maxProgress;

return (
Expand Down
8 changes: 2 additions & 6 deletions packages/nextjs/app/_components/BountyList/BountyList.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { useState } from "react";
import Backdrop from "../Backdrop/Backdrop";
import Bounty, { BountyProps } from "../Bounty/Bounty";
import Bounty from "../Bounty/Bounty";
import BountyInfo from "../BountyInfo";
import { AnimatePresence, motion } from "framer-motion";
import useBounties from "~~/hooks/useBounties";

type BountyListProps = {
bounties: BountyProps[];
};

const BountyList: React.FC<BountyListProps> = () => {
const BountyList = () => {
const [selectedId, setSelectedId] = useState<number | null>(null);

const { bounties, bountyCount } = useBounties();
Expand Down
122 changes: 0 additions & 122 deletions packages/nextjs/app/_components/BountyList/data.json

This file was deleted.

3 changes: 1 addition & 2 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import BountyCreator from "./_components/BountyCreator";
import BountyList from "./_components/BountyList";
import data from "./_components/BountyList/data.json";
import type { NextPage } from "next";

const Home: NextPage = () => {
Expand All @@ -16,7 +15,7 @@ const Home: NextPage = () => {
</h2>
<p></p>
<BountyCreator />
<BountyList bounties={data} />
<BountyList />
</div>
</div>
</>
Expand Down
4 changes: 3 additions & 1 deletion packages/nextjs/hooks/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export const GET_BOUNTIES = gql`
duration
judgeTime
maxProgress
mediaURIHash
mediaURI
name
numAcceptedSubmissions
reward
submissions {
eegDataHash
id
submitter
}
}
}
Expand Down
39 changes: 15 additions & 24 deletions packages/nextjs/hooks/useBounties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,11 @@ import Think2Earn from "../../hardhat/deployments/localhost/Think2Earn.json";
import { GET_BOUNTIES } from "./queries";
import { useQuery } from "@apollo/client";
import { formatEther, parseEther } from "viem";
import { useAccount, useBalance, useContractReads, useWriteContract } from "wagmi";
import { useAccount, useBalance, useWriteContract } from "wagmi";
import { Bounty } from "~~/types/bounty";

const MAXUINT256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935n;

export interface Asset {
priceFeed: string;
tokenNum: string;
tokenDen: string;
tokenAmount: bigint;
initPrice: bigint;
}

type ContractReadsOutput = {
data?: any[];
isError: boolean;
isLoading: boolean;
};

const useBounties = () => {
const account = useAccount();
const fundEthBalance = useBalance({
Expand All @@ -46,8 +32,8 @@ const useBounties = () => {

const createBounty = async (bountyData: any) => {
await writeContract({
address: Think2Earn.address,
abi: Think2Earn.abi,
address: bountiesContract.address,
abi: bountiesContract.abi,
functionName: "createBounty",
value: parseEther(bountyData.reward),
args: [
Expand All @@ -63,12 +49,16 @@ const useBounties = () => {
};

const approve = async () => {
writeContract({
address: Think2Earn.address,
abi: Think2Earn.abi,
functionName: "approve",
args: [account.address, MAXUINT256],
});
if (account.address) {
writeContract({
address: bountiesContract.address,
abi: bountiesContract.abi,
functionName: "approve",
args: [account.address, MAXUINT256],
});
} else {
alert("Please connect your wallet to approve the contract");
}
};

useEffect(() => {
Expand All @@ -94,7 +84,8 @@ const useBounties = () => {
reward: parseInt(formatEther(bounty.reward)),
duration: bounty.duration,
maxProgress: parseInt(bounty.maxProgress),
progress: parseInt(bounty.numAcceptedSubmissions),
progress: bounty.submissions.length,
submissions: bounty.submissions,
} as Bounty;
}) || [],
);
Expand Down
7 changes: 7 additions & 0 deletions packages/nextjs/types/bounty.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export type Submission = {
id: string;
submitter: string;
eegDataHash: string;
};

export type Bounty = {
title: string;
description: string;
Expand All @@ -6,4 +12,5 @@ export type Bounty = {
duration: string;
maxProgress: number;
progress: number;
submissions: Submission[];
};
2 changes: 1 addition & 1 deletion packages/subgraph/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
}
}
}
}

0 comments on commit ade83cb

Please sign in to comment.