Skip to content

Commit 1da6811

Browse files
committed
feat: minor changes
1 parent 1961709 commit 1da6811

3 files changed

Lines changed: 28 additions & 41 deletions

File tree

src/containers/vote/index.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { toast } from 'sonner';
1111
interface VoteState {
1212
isLoading: boolean;
1313
deadline: number | null;
14-
voteFinishedAt: number | null;
1514
votes: Record<string, ['yes' | 'no', string]>;
1615
yesVotesCount: number | null;
1716
votedStakeAmount: Big.Big;
@@ -32,7 +31,7 @@ function useVoteContainer(): UseVoteContainer {
3231
const { viewFunction } = useNear();
3332

3433
const [deadline, setDeadline] = useState<number | null>(null);
35-
const [voteFinishedAt, setVoteFinishedAt] = useState<number | null>(null);
34+
// const [voteFinishedAt, setVoteFinishedAt] = useState<number | null>(null);
3635
const [votes, setVotes] = useState<Record<string, ['yes' | 'no', string]>>({});
3736
const [votedStakeAmount, setVotedStakeAmount] = useState(Big(0));
3837
const [totalVotedStakeAmount, setTotalVotedStakeAmount] = useState(Big(0));
@@ -44,14 +43,8 @@ function useVoteContainer(): UseVoteContainer {
4443
}, [votedStakeAmount, totalVotedStakeAmount]);
4544

4645
const votedPercent = useMemo(() => {
47-
const _percent = Number(_votedPercent);
48-
const lastProgress = PROGRESS[PROGRESS.length - 1];
49-
if (voteFinishedAt) {
50-
if (_percent >= lastProgress) return _votedPercent;
51-
return lastProgress.toFixed(2);
52-
}
5346
return _votedPercent;
54-
}, [_votedPercent, voteFinishedAt]);
47+
}, [_votedPercent]);
5548

5649
const getTotalVotedStake = useCallback(async () => {
5750
const data = await viewFunction({
@@ -67,14 +60,14 @@ function useVoteContainer(): UseVoteContainer {
6760
setTotalVotedStakeAmount(Big(data[2]));
6861
}, [viewFunction]);
6962

70-
const getResult = useCallback(async () => {
71-
const data = await viewFunction({
72-
contractId: contractId,
73-
method: 'get_result',
74-
});
75-
logger.debug('get_result', data);
76-
setVoteFinishedAt(data || null);
77-
}, [viewFunction]);
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]);
7871

7972
const getVotes = useCallback(async () => {
8073
const data = await viewFunction({
@@ -105,7 +98,7 @@ function useVoteContainer(): UseVoteContainer {
10598
const { isLoading, error } = useSWR(
10699
'vote_data',
107100
async () => {
108-
const promises = Promise.all([getTotalVotedStake(), getResult(), getVotes(), getDeadline()]);
101+
const promises = Promise.all([getTotalVotedStake(), getVotes(), getDeadline()]);
109102
return await promises;
110103
},
111104
// {
@@ -127,7 +120,6 @@ function useVoteContainer(): UseVoteContainer {
127120
return {
128121
isLoading,
129122
deadline,
130-
voteFinishedAt,
131123
votes,
132124
yesVotesCount,
133125
votedStakeAmount,

src/pages/home/components/Countdown.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ 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';
56

67
export interface CountdownProps {
78
votedPercent: string;
@@ -12,6 +13,8 @@ export default function Countdown({ deadline }: CountdownProps) {
1213
const [isPageVisible, setPageVisibility] = useState(!document.hidden);
1314
const [countdownSeconds, setCountdownSeconds] = useState<number | null>(null);
1415

16+
const finished = deadline && Date.now() > deadline;
17+
1518
const deadlineFromNow = useMemo(() => {
1619
if (!countdownSeconds) return null;
1720
const diffSeconds = countdownSeconds;
@@ -62,6 +65,17 @@ export default function Countdown({ deadline }: CountdownProps) {
6265

6366
if (!deadlineFromNow) return null;
6467

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+
}
78+
6579
return (
6680
<div className="flex flex-col items-center mb-10">
6781
{/* <h3 className="text-app-black-400 text-base sm:text-lg mb-4">

src/pages/home/index.tsx

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useNavigate } from 'react-router-dom';
55
import { PulseLoader } from 'react-spinners';
66

77
import NEARLogo from '@/assets/images/near-green.jpg';
8-
import ApprovedImg from '@/assets/images/approved.png';
98
import Bg1 from '@/assets/images/home-star-bg1.png';
109
import Bg2 from '@/assets/images/home-star-bg2.png';
1110
import Markdown from '@/components/markdown';
@@ -26,31 +25,13 @@ dayjs.extend(utc);
2625

2726
export default function Home() {
2827
const navigate = useNavigate();
29-
const {
30-
isLoading,
31-
deadline,
32-
votes,
33-
yesVotesCount,
34-
votedPercent,
35-
voteFinishedAt,
36-
votedStakeAmount,
37-
} = VoteContainer.useContainer();
28+
const { isLoading, deadline, votes, yesVotesCount, votedPercent, votedStakeAmount } =
29+
VoteContainer.useContainer();
3830

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

4133
const renderVoteProgressStatus = () => {
42-
if (!voteFinishedAt) {
43-
return <Countdown deadline={deadline} votedPercent={votedPercent} />;
44-
}
45-
46-
return (
47-
<div className="flex flex-col items-center mb-10">
48-
{/* <h3 className="text-app-black-400 text-base sm:text-lg mb-4">
49-
{votedPercent}% of Stake Voted for YEA
50-
</h3> */}
51-
<img src={ApprovedImg} className="h-[72px]" alt="" />
52-
</div>
53-
);
34+
return <Countdown deadline={deadline} votedPercent={votedPercent} />;
5435
};
5536

5637
const renderProgress = () => {

0 commit comments

Comments
 (0)