Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash Goyal authored and Yash Goyal committed May 25, 2024
1 parent 158d154 commit 943a86a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/nextjs/app/polls/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import { useParams } from "next/navigation";
import PollDetail from "~~/components/PollDetail";
import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly";

export default function PollDetailPage() {
const { id } = useParams<{ id: string }>();
useAuthUserOnly({});

return <PollDetail id={BigInt(id)} />;
}
2 changes: 2 additions & 0 deletions packages/nextjs/app/polls/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from "react";
import { useRouter } from "next/navigation";
import Paginator from "~~/components/Paginator";
import HoverBorderCard from "~~/components/card/HoverBorderCard";
import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly";
import { useFetchPolls } from "~~/hooks/useFetchPolls";
import { useTotalPages } from "~~/hooks/useTotalPages";

Expand All @@ -12,6 +13,7 @@ export default function Polls() {
const [limit] = useState(10);
const { totalPolls, polls } = useFetchPolls(currentPage, limit);
const totalPages = useTotalPages(totalPolls, limit);
useAuthUserOnly({});

console.log(polls);

Expand Down
3 changes: 0 additions & 3 deletions packages/nextjs/components/PollDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useContractRead, useContractWrite } from "wagmi";
import PollAbi from "~~/abi/Poll";
import VoteCard from "~~/components/card/VoteCard";
import { useAuthContext } from "~~/contexts/AuthContext";
import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly";
import { useFetchPoll } from "~~/hooks/useFetchPoll";
import { getPollStatus } from "~~/hooks/useFetchPolls";
import { PollStatus, PollType } from "~~/types/poll";
Expand All @@ -18,8 +17,6 @@ export default function PollDetail({ id }: { id: bigint }) {
const { data: poll, error, isLoading } = useFetchPoll(id);
const [pollType, setPollType] = useState(PollType.NOT_SELECTED);

useAuthUserOnly({});

const { keypair, stateIndex } = useAuthContext();

const [votes, setVotes] = useState<{ index: number; votes: number }[]>([]);
Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ export default function AuthContextProvider({ children }: { children: React.Reac
return;
}

const lastSignUpEvent = SignUpEvents[SignUpEvents.length - 1];
setStateIndex(lastSignUpEvent.args._stateIndex || null);
const event = SignUpEvents.filter(
log =>
log.args._userPubKeyX?.toString() === keypair.pubKey.asContractParam().x &&
log.args._userPubKeyY?.toString() === keypair.pubKey.asContractParam().y,
)[0];
setStateIndex(event?.args?._stateIndex || null);
}, [keypair, SignUpEvents]);

useScaffoldEventSubscriber({
Expand Down

0 comments on commit 943a86a

Please sign in to comment.