Skip to content

Commit

Permalink
Merge branch 'main' of github.com-personal:Vota-Protocol/core
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgo0018 committed Mar 17, 2024
2 parents f76b8a0 + 748493b commit 4909f4c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
17 changes: 11 additions & 6 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { contracts } from "~~/utils/scaffold-eth/contract";

export default function VoterPage() {
const router = useRouter();

const [isLoading, setIsLoading] = useState(true);
useAuthUserOnly({});

const { data: totalPolls } = useScaffoldContractRead({
Expand All @@ -27,15 +27,20 @@ export default function VoterPage() {

const chainId = useChainId();

const { data: pollsRaw, isLoading } = useContractReads({
const { data: pollsRaw } = useContractReads({
contracts: Array.from(Array(Number(totalPolls || 0n)).keys()).map((_, i) => ({
address: (contracts && contracts[chainId] && contracts[chainId]["PollManager"]?.address) || undefined,
abi: (contracts && contracts[chainId] && contracts[chainId]["PollManager"]?.abi) || undefined,
functionName: "polls",
args: [BigInt(i + 1)],
onSuccess() {
setIsLoading(false);
},
})),
});

console.log("isLoading in mainpage", isLoading);

useEffect(() => {
if (!pollsRaw || pollsRaw.length == 0 || pollsRaw.filter(({ status }) => status !== "success").length !== 0) {
setPollsFormatted([]);
Expand All @@ -59,7 +64,7 @@ export default function VoterPage() {
setPollsFormatted(dataList);
}, [pollsRaw]);

console.log(pollsFormatted);
console.log("pollsFormatted", pollsFormatted);

// useEffect(() => {
// console.log("isRegistered", isRegistered);
Expand All @@ -82,9 +87,7 @@ export default function VoterPage() {
</div>
)}

{isLoading ? (
<LoaderPage message="Fetching Current Poll's .... " />
) : (
{pollsFormatted ? (
<div className="grid lg:grid-cols-2">
{pollsFormatted?.map(voter => (
<div className="mb-4 mx-2" key={voter.title}>
Expand All @@ -111,6 +114,8 @@ export default function VoterPage() {
</div>
))}
</div>
) : (
<LoaderPage message="Fetching Current Poll's .... " />
)}
</div>
);
Expand Down
12 changes: 9 additions & 3 deletions packages/nextjs/app/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ export default function RegisterPage() {

useEffect(() => {
if (!encodedProof) return;
writeAsync();
//TODO ; add a way to make it rgisteration true
refetchIsRegistered();
(async () => {
try {
await writeAsync();
refetchIsRegistered();
console.log("Registered");
} catch (e) {
console.error(e);
}
})();
}, [encodedProof]);

const style = {
Expand Down
6 changes: 5 additions & 1 deletion packages/nextjs/app/vote/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useScaffoldContractRead } from "~~/hooks/scaffold-eth";
import { decodeOptions } from "~~/utils/crypto";

const Vote = () => {
const [isLoading, setIsLoading] = useState(true);
const [loaderMessage, setLoaderMessage] = useState("Casting the vote, please wait...");

const router = useRouter();
Expand All @@ -28,6 +29,9 @@ const Vote = () => {
contractName: "PollManager",
functionName: "polls",
args: [BigInt(id)],
onSuccess() {
setIsLoading(false);
},
});

useEffect(() => {
Expand Down Expand Up @@ -81,7 +85,7 @@ const Vote = () => {

console.log("message", message);

const { writeAsync, isLoading } = useContractWrite({
const { writeAsync } = useContractWrite({
abi: PollAbi,
address: pollRaw?.[4]?.poll,
functionName: "publishMessage",
Expand Down

0 comments on commit 4909f4c

Please sign in to comment.