Skip to content

Commit 14d1056

Browse files
committed
feat: fetch vote result data
1 parent 1da6811 commit 14d1056

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

src/containers/vote/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { toast } from 'sonner';
1010

1111
interface VoteState {
1212
isLoading: boolean;
13+
voteResult: boolean;
1314
deadline: number | null;
1415
votes: Record<string, ['yes' | 'no', string]>;
1516
yesVotesCount: number | null;
@@ -31,7 +32,7 @@ function useVoteContainer(): UseVoteContainer {
3132
const { viewFunction } = useNear();
3233

3334
const [deadline, setDeadline] = useState<number | null>(null);
34-
// const [voteFinishedAt, setVoteFinishedAt] = useState<number | null>(null);
35+
const [voteResult, setVoteResult] = useState(false);
3536
const [votes, setVotes] = useState<Record<string, ['yes' | 'no', string]>>({});
3637
const [votedStakeAmount, setVotedStakeAmount] = useState(Big(0));
3738
const [totalVotedStakeAmount, setTotalVotedStakeAmount] = useState(Big(0));
@@ -60,14 +61,14 @@ function useVoteContainer(): UseVoteContainer {
6061
setTotalVotedStakeAmount(Big(data[2]));
6162
}, [viewFunction]);
6263

63-
// const getResult = useCallback(async () => {
64-
// const data = await viewFunction({
65-
// contractId: contractId,
66-
// method: 'get_result',
67-
// });
68-
// logger.debug('get_result', data);
69-
// setVoteFinishedAt(data || null);
70-
// }, [viewFunction]);
64+
const getResult = useCallback(async () => {
65+
const data = await viewFunction({
66+
contractId: contractId,
67+
method: 'get_result',
68+
});
69+
logger.debug('get_result', data);
70+
setVoteResult(data || false);
71+
}, [viewFunction]);
7172

7273
const getVotes = useCallback(async () => {
7374
const data = await viewFunction({
@@ -98,7 +99,7 @@ function useVoteContainer(): UseVoteContainer {
9899
const { isLoading, error } = useSWR(
99100
'vote_data',
100101
async () => {
101-
const promises = Promise.all([getTotalVotedStake(), getVotes(), getDeadline()]);
102+
const promises = Promise.all([getTotalVotedStake(), getVotes(), getDeadline(), getResult()]);
102103
return await promises;
103104
},
104105
// {
@@ -119,6 +120,7 @@ function useVoteContainer(): UseVoteContainer {
119120

120121
return {
121122
isLoading,
123+
voteResult,
122124
deadline,
123125
votes,
124126
yesVotesCount,

src/pages/home/components/Countdown.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useEffect, useMemo, useState } from 'react';
22

33
import dayjs from 'dayjs';
44
import { useInterval } from 'react-use';
5-
import ApprovedImg from '@/assets/images/approved.png';
65

76
export interface CountdownProps {
87
votedPercent: string;
@@ -64,17 +63,7 @@ export default function Countdown({ deadline }: CountdownProps) {
6463
);
6564

6665
if (!deadlineFromNow) return null;
67-
68-
if (finished) {
69-
return (
70-
<div className="flex flex-col items-center mb-10">
71-
{/* <h3 className="text-app-black-400 text-base sm:text-lg mb-4">
72-
{votedPercent}% of Stake Voted for YEA
73-
</h3> */}
74-
<img src={ApprovedImg} className="h-[72px]" alt="" />
75-
</div>
76-
);
77-
}
66+
if (finished) return null;
7867

7968
return (
8069
<div className="flex flex-col items-center mb-10">

src/pages/home/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { cn, formatBigNumber, isNotNullAndNumber } from '@/lib/utils';
1515
import { article } from './article';
1616
import YesIcon from '@/assets/icons/yes.svg?react';
1717
import NoIcon from '@/assets/icons/no.svg?react';
18+
import ApprovedImg from '@/assets/images/approved.png';
1819

1920
import Countdown from './components/Countdown';
2021
import dayjs from 'dayjs';
@@ -25,12 +26,22 @@ dayjs.extend(utc);
2526

2627
export default function Home() {
2728
const navigate = useNavigate();
28-
const { isLoading, deadline, votes, yesVotesCount, votedPercent, votedStakeAmount } =
29+
const { isLoading, deadline, votes, voteResult, yesVotesCount, votedPercent, votedStakeAmount } =
2930
VoteContainer.useContainer();
3031

3132
const NEAR_ENV = config.proposalContractId?.split('.').pop() === 'near' ? 'mainnet' : 'testnet';
3233

3334
const renderVoteProgressStatus = () => {
35+
if (voteResult) {
36+
return (
37+
<div className="flex flex-col items-center mb-10">
38+
{/* <h3 className="text-app-black-400 text-base sm:text-lg mb-4">
39+
{votedPercent}% of Stake Voted for YEA
40+
</h3> */}
41+
<img src={ApprovedImg} className="h-[72px]" alt="" />
42+
</div>
43+
);
44+
}
3445
return <Countdown deadline={deadline} votedPercent={votedPercent} />;
3546
};
3647

0 commit comments

Comments
 (0)