import React from "react"; import { Status } from "../../types"; const timeLeft = (blocks: number) => { const seconds = blocks * 6; const days = Math.floor(seconds / 86400); const hours = Math.floor((seconds - days * 86400) / 3600); const minutes = Math.floor(seconds / 60); return days ? `${days}d` : hours ? `${hours}h` : `${minutes}min`; }; const ElectionStage = (props: { block: number; council: { stage; termEndsAt: number }; domain: string; }) => { const { block, council, domain } = props; if (!council) return Loading..; const { stage, termEndsAt } = council; if (!stage) { if (!block || !termEndsAt) return ; const left = timeLeft(termEndsAt - block); return election starts in {left}; } let stageString = Object.keys(stage)[0]; const left = timeLeft(stage[stageString] - block); if (stageString === "announcing") return {left} to apply; if (stageString === "voting") return {left} to vote; if (stageString === "revealing") return {left} to reveal votes; return {JSON.stringify(stage)}; }; const ElectionStatus = (props: { block; domain: string; status: Status }) => { const { domain, status } = props; if (!status.block || !status.council) return
; return (