Skip to content

Commit

Permalink
added elections date
Browse files Browse the repository at this point in the history
  • Loading branch information
Megha-Dev-19 committed Aug 29, 2023
1 parent ef5b5b9 commit 8e461b6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
26 changes: 21 additions & 5 deletions src/components/common/ProgressTracker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ 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 = () => {
const ProgressMeterMax = process.env.REACT_APP_PROGRESS_METER_MAX ?? 3000;
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 {
Expand Down Expand Up @@ -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({
Expand All @@ -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));
Expand All @@ -84,6 +91,10 @@ const ProgressTracker = () => {
}

useEffect(() => {
const isElectionStarted = moment().isSameOrAfter(
IAHShutDownStartTime.clone().tz(userTimezone)
);
setElectionStarted(isElectionStarted);
updateCountdown();

const interval = setInterval(updateCountdown, 1000);
Expand Down Expand Up @@ -160,7 +171,12 @@ const ProgressTracker = () => {
style={{ backgroundColor: '#F29BC0' }}
className="p-2 text-white font-semibold flex gap-x-8 justify-center items-center"
>
<p>VOTER REGISTRATION ENDS</p>
<p>
{electionStarted
? 'TIME REMAINING IN CURRENT ELECTION'
: 'VOTER REGISTRATION END'}
S
</p>
<p className="text-lg flex gap-x-3 items-end">
<NumberContainer number={countdown.days} text="D" />
<NumberContainer number={countdown.hours} text="H" />
Expand Down
28 changes: 18 additions & 10 deletions src/components/fractalVerification/TabScreens.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
<div className="w-full">
{moment().isBetween(electionStartDate, electionEndDate) && (
{/* compare using the local dates */}
{moment().isBetween(
electionStartDate.clone().tz(userTimezone),
electionEndDate.clone().tz(userTimezone)
) && (
<Transition.Root show={true} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={() => {}}>
<Transition.Child
Expand Down Expand Up @@ -320,8 +327,9 @@ export const ScanFace = () => {
<p>
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)}
.
</p>
</div>
</Dialog.Panel>
Expand Down
5 changes: 5 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 8e461b6

Please sign in to comment.