Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/app/governance/components/DistributionCountdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
differenceInDays,
differenceInHours,
differenceInMinutes,
} from "date-fns";

export const DistributionCountdown = ({ end }: { end: Date }) => {
const getTimeDisplay = () => {
const now = new Date();
const days = differenceInDays(end, now);

if (days >= 1) return `${days} ${days === 1 ? "day" : "days"}`;

const hours = differenceInHours(end, now);

if (hours >= 1) return `${hours} ${hours === 1 ? "hour" : "hours"}`;

const minutes = differenceInMinutes(end, now);

if (minutes >= 1)
return `${minutes} ${minutes === 1 ? "minute" : "minutes"}`;

return "0 days";
};

return <>{getTimeDisplay()}</>;
};
4 changes: 2 additions & 2 deletions src/app/governance/components/DistributionOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getChain } from "@/chainConfig";
import { formatUnits } from "viem";
import clsx from "clsx";
import { useDistributions } from '../useDistributions';
import { DistributionCountdown } from "./DistributionCountdown";

export function DistributionOverview({
cycleDates,
Expand Down Expand Up @@ -192,8 +193,7 @@ export function DistributionOverview({
) : (
<div className="pt-3 flex flex-col gap-3">
<p className="font-bold dark:text-breadgray-ultra-white">
Distributing in{" "}
{differenceInDays(cycleDates.end, new Date())} days
Distributing in <DistributionCountdown end={cycleDates.end} />
</p>
<div className="flex gap-0.5 bg-breadgray-white border-breadgray-white dark:bg-black border-2 dark:border-black rounded-full overflow-clip">
{completedDays &&
Expand Down
8 changes: 4 additions & 4 deletions src/app/governance/components/VotingPower.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CycleDatesSuccess } from "../useCycleDates";
import { CycleLengthSuccess } from "../useCycleLength";
import { FistIcon } from "@/app/core/components/Icons/FistIcon";
import { formatUnits } from "viem";
import { differenceInDays } from "date-fns";
import { DistributionCountdown } from "./DistributionCountdown";

export function VotingPower({
minRequiredVotingPower,
Expand Down Expand Up @@ -89,8 +89,6 @@ function NotEnoughPower() {
}

function UserHasVoted({ cycleDates }: { cycleDates: CycleDatesSuccess }) {
const days = differenceInDays(cycleDates.end, Date.now());

return (
<div className={clsx(widgetBaseClasses, "border-status-success")}>
<div className="flex gap-4">
Expand All @@ -103,7 +101,9 @@ function UserHasVoted({ cycleDates }: { cycleDates: CycleDatesSuccess }) {
</div>
<div>
<span className="dark:text-breadgray-grey">Next round: </span>
<span>In {days} {days === 1 ? "day" : "days"}</span>
<span>
<DistributionCountdown end={cycleDates.end} />
</span>
</div>
</div>
);
Expand Down