diff --git a/src/components/account/account-ui.tsx b/src/components/account/account-ui.tsx index 70d7d93..e3e38e5 100644 --- a/src/components/account/account-ui.tsx +++ b/src/components/account/account-ui.tsx @@ -198,7 +198,7 @@ export function AccountTransactions({ address }: { address: PublicKey }) { return (
-

Transaction History

+

Voting History

{query.isLoading ? ( @@ -213,7 +213,7 @@ export function AccountTransactions({ address }: { address: PublicKey }) { {query.isSuccess && (
{query.data.length === 0 ? ( -
No transactions found.
+
No votes found.
) : ( diff --git a/src/components/results/results-data-access.tsx b/src/components/results/results-data-access.tsx index bd666f6..38be93d 100644 --- a/src/components/results/results-data-access.tsx +++ b/src/components/results/results-data-access.tsx @@ -15,8 +15,6 @@ export function useCandidateScores() { const scores: any[] = [] - console.log(candidates) - candidates.map((cand) => { if (!cand.voters.length) { scores.push({ diff --git a/src/components/results/results-feature.tsx b/src/components/results/results-feature.tsx index 91bc51c..56d7d5d 100644 --- a/src/components/results/results-feature.tsx +++ b/src/components/results/results-feature.tsx @@ -6,15 +6,28 @@ import { useVotingdappProgram } from '../votingdapp/votingdapp-data-access' import { ResultsChart } from "./results-ui" import { WalletButton } from '../solana/solana-provider' import getUnixInDate from '@/utils/getUnixInDate' +import { AccountTransactions } from '../account/account-ui' +import { useState, useEffect } from 'react' export default function ResultsFeature() { const { publicKey } = useWallet() const { accounts, programId } = useVotingdappProgram() + const [electionHasFinished, setElectionHasFinished] = useState(false) + const [endTime, setEndTime] = useState(null) - // const title = accounts.data && accounts.data.length ? accounts.data[0].account?.name : "Unintialized Blockchain Presidental Election" - // const subtitle = accounts.data && accounts.data.length ? `${accounts.data[0].account?.description}` : "No description yet" - // const start_time = accounts.data && accounts.data.length ? `${getUnixInDate(accounts.data[0].account?.startTime.toNumber())}` : "No data" - // const end_time = accounts.data && accounts.data.length ? `${getUnixInDate(accounts.data[0].account?.endTime.toNumber())}` : "No data" + // Extract and parse the election end time + useEffect(() => { + if (accounts.data && accounts.data.length) { + const endTimeUnix = accounts.data[0].account?.endTime.toNumber() + const parsedDate = getUnixInDate(endTimeUnix) + if (!parsedDate) setEndTime(parsedDate) + + const endDate = new Date(parsedDate) + if (endDate < new Date()) { + setElectionHasFinished(true) + } + } + }, [accounts.data]) return publicKey ? (
@@ -22,16 +35,26 @@ export default function ResultsFeature() { title={"Election results"} subtitle={'This page displays the election results'} > - {/*

- Election starts: {start_time}
- Election ends: {end_time} -

*/}

- {/* */} - + {electionHasFinished ? ( +
+
+ +
+
+ +
+
+ ) : ( +
+

+ The election is still taking place. Please come back after the election has finished. +

+
+ )}
) : (
diff --git a/src/utils/getUnixInDate.ts b/src/utils/getUnixInDate.ts index 95479da..3d9dc9b 100644 --- a/src/utils/getUnixInDate.ts +++ b/src/utils/getUnixInDate.ts @@ -1,3 +1,3 @@ -export default function getUnixInDate(timestamp: number) { +export default function getUnixInDate(timestamp: number): Date { return new Date(timestamp * 1000) } \ No newline at end of file