From 8e461b63f148e9cedacde972ace139aa793ac043 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Tue, 29 Aug 2023 20:14:14 +0530 Subject: [PATCH] added elections date --- src/components/common/ProgressTracker.jsx | 26 +++++++++++++---- .../fractalVerification/TabScreens.jsx | 28 ++++++++++++------- src/utils/constants.js | 5 ++++ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/components/common/ProgressTracker.jsx b/src/components/common/ProgressTracker.jsx index 9b36119..946e396 100644 --- a/src/components/common/ProgressTracker.jsx +++ b/src/components/common/ProgressTracker.jsx @@ -3,7 +3,12 @@ import { wallet } from '../..'; import { getConfig } from '../../utils/config'; import { formatNumberWithComma } from '../../utils/utilityFunctions'; import { useSelector } from 'react-redux'; -import { Links, ReducerNames } from '../../utils/constants'; +import { + IAHShutDownEndTime, + IAHShutDownStartTime, + Links, + ReducerNames, +} from '../../utils/constants'; import moment from 'moment-timezone'; const ProgressTracker = () => { @@ -11,6 +16,7 @@ const ProgressTracker = () => { const [humansRegistered, setHumansRegistered] = useState(0); const { showTracker } = useSelector((state) => state[ReducerNames.PROGRESS]); const { fvToken } = useSelector((state) => state[ReducerNames.SBT]); + const [electionStarted, setElectionStarted] = useState(false); const fetchHumansRegistered = async () => { try { @@ -57,8 +63,6 @@ const ProgressTracker = () => { const ReadableNumber = formatNumberWithComma(ProgressMeterMax); - const futureDateUtc = moment.unix(1693612799); // September 1 @ 23:59:59 - // Get the user's local timezone const userTimezone = moment.tz.guess(); const [countdown, setCountdown] = useState({ @@ -70,7 +74,10 @@ const ProgressTracker = () => { function updateCountdown() { const nowLocal = moment(); // Get the current local time - const futureDateLocal = futureDateUtc.clone().tz(userTimezone); + const timestamp = electionStarted + ? IAHShutDownEndTime + : IAHShutDownStartTime; + const futureDateLocal = timestamp.clone().tz(userTimezone); // Calculate the time remaining const countdownDuration = moment.duration(futureDateLocal.diff(nowLocal)); @@ -84,6 +91,10 @@ const ProgressTracker = () => { } useEffect(() => { + const isElectionStarted = moment().isSameOrAfter( + IAHShutDownStartTime.clone().tz(userTimezone) + ); + setElectionStarted(isElectionStarted); updateCountdown(); const interval = setInterval(updateCountdown, 1000); @@ -160,7 +171,12 @@ const ProgressTracker = () => { style={{ backgroundColor: '#F29BC0' }} className="p-2 text-white font-semibold flex gap-x-8 justify-center items-center" > -

VOTER REGISTRATION ENDS

+

+ {electionStarted + ? 'TIME REMAINING IN CURRENT ELECTION' + : 'VOTER REGISTRATION END'} + S +

diff --git a/src/components/fractalVerification/TabScreens.jsx b/src/components/fractalVerification/TabScreens.jsx index 8ca0c3d..ba96a8b 100644 --- a/src/components/fractalVerification/TabScreens.jsx +++ b/src/components/fractalVerification/TabScreens.jsx @@ -17,7 +17,13 @@ import { SuccesVerification } from './SuccessPage'; import { useSelector, useDispatch } from 'react-redux'; import { verifyUser } from '../../services/api'; import { updateResponse } from '../../redux/reducer/oracleReducer'; -import { ImageSrc, OneE21, ReducerNames } from '../../utils/constants'; +import { + IAHShutDownEndTime, + IAHShutDownStartTime, + ImageSrc, + OneE21, + ReducerNames, +} from '../../utils/constants'; import { setActivePageIndex } from '../../redux/reducer/commonReducer'; import { Link } from '../common/Link'; import { fpPromise } from '../../utils/fingerprint'; @@ -278,18 +284,19 @@ export const ScanFace = () => { } }, [responseData?.token]); - const electionStartDate = moment - .unix(process.env.REACT_APP_ELECTION_START_DATE) - .local(); - const electionEndDate = moment - .unix(process.env.REACT_APP_ELECTION_END_DATE) - .local(); + const userTimezone = moment.tz.guess(); + const electionEndDate = IAHShutDownEndTime; + const electionStartDate = IAHShutDownStartTime; const formatString = 'MMMM D, HH:mm:ss [UTC]'; // Format string return (

- {moment().isBetween(electionStartDate, electionEndDate) && ( + {/* compare using the local dates */} + {moment().isBetween( + electionStartDate.clone().tz(userTimezone), + electionEndDate.clone().tz(userTimezone) + ) && ( {}}> {

I-AM-HUMAN Voter Registration is paused during the NDC Election between{' '} - {moment(electionStartDate).format(formatString)} and{' '} - {moment(electionEndDate).format(formatString)}. + {moment(electionStartDate).utc().format(formatString)}{' '} + and {moment(electionEndDate).utc().format(formatString)} + .

diff --git a/src/utils/constants.js b/src/utils/constants.js index f2e9807..428457f 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -1,3 +1,5 @@ +import moment from 'moment-timezone'; + // OneE18 is an amount of 1 microNEAR export const OneE18 = 1_000_000_000_000_000_000n; // OneE21 is an amount of 1 miliNEAR @@ -122,3 +124,6 @@ export const AccountFlag = { Blacklisted: 'Blacklisted', Verified: 'Verified', }; + +export const IAHShutDownStartTime = moment.unix(1693612799); // September 1 @ 23:59:59 +export const IAHShutDownEndTime = moment.unix(1695427199); // September 22 @ 23:59:59