From 8f12477cc17a34cf6ed17e5297571c7461c55352 Mon Sep 17 00:00:00 2001 From: aeolian <94939382+aeolianeth@users.noreply.github.com> Date: Wed, 27 Nov 2024 20:58:05 +1000 Subject: [PATCH] feat: countdown to first cycle --- .../CyclesPayoutsTab/CountdownCallout.tsx | 24 +++++++++++++++++++ src/locales/messages.pot | 3 +++ .../CyclesPayoutsPanel/CyclesPayoutsPanel.tsx | 19 ++++++++------- .../components/CurrentUpcomingSubPanel.tsx | 10 ++++++-- .../hooks/useCurrentUpcomingSubPanel.ts | 4 ++++ 5 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 src/components/Project/ProjectTabs/CyclesPayoutsTab/CountdownCallout.tsx diff --git a/src/components/Project/ProjectTabs/CyclesPayoutsTab/CountdownCallout.tsx b/src/components/Project/ProjectTabs/CyclesPayoutsTab/CountdownCallout.tsx new file mode 100644 index 0000000000..86cd8186b7 --- /dev/null +++ b/src/components/Project/ProjectTabs/CyclesPayoutsTab/CountdownCallout.tsx @@ -0,0 +1,24 @@ +import { ClockIcon } from '@heroicons/react/24/outline' +import { Trans } from '@lingui/macro' +import { useCountdownClock } from 'components/Project/hooks/useCountdownClock' +import { twMerge } from 'tailwind-merge' + +export function CountdownCallout({ + cycleStart, +}: { + cycleStart: number | undefined +}) { + const { remainingTimeText } = useCountdownClock(cycleStart) + + return ( +
+ + Starts in {remainingTimeText} +
+ ) +} diff --git a/src/locales/messages.pot b/src/locales/messages.pot index 42b56b7b73..6c75493759 100644 --- a/src/locales/messages.pot +++ b/src/locales/messages.pot @@ -3989,6 +3989,9 @@ msgstr "" msgid "tokens per ETH paid" msgstr "" +msgid "Starts in {remainingTimeText}" +msgstr "" + msgid "Congratulations!" msgstr "" diff --git a/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/CyclesPayoutsPanel.tsx b/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/CyclesPayoutsPanel.tsx index 151bd44d91..cc61a2cf40 100644 --- a/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/CyclesPayoutsPanel.tsx +++ b/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/CyclesPayoutsPanel.tsx @@ -1,7 +1,7 @@ import { Tab } from '@headlessui/react' import { t } from '@lingui/macro' import { CyclesTab } from 'components/Project/ProjectTabs/CyclesPayoutsTab/CyclesTab' -import { useMemo } from 'react' +import { useProjectContext } from '../../hooks/useProjectContext' import { CurrentUpcomingSubPanel } from './components/CurrentUpcomingSubPanel' import { HistorySubPanel } from './components/HistorySubPanel' @@ -11,14 +11,15 @@ type CyclesSubPanel = { } export const CyclesPayoutsPanel = () => { - const tabs: CyclesSubPanel[] = useMemo( - () => [ - { id: 'current', name: t`Current` }, - { id: 'upcoming', name: t`Upcoming` }, - { id: 'history', name: t`History` }, - ], - [], - ) + const { fundingCycle } = useProjectContext() + + const tabs: CyclesSubPanel[] = [ + // Don't show the current tab if there is no current cycle + fundingCycle?.number.gt(0) && { id: 'current', name: t`Current` }, + { id: 'upcoming', name: t`Upcoming` }, + { id: 'history', name: t`History` }, + ].filter(Boolean) as CyclesSubPanel[] + return (
diff --git a/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/components/CurrentUpcomingSubPanel.tsx b/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/components/CurrentUpcomingSubPanel.tsx index 367f158bd4..67803def08 100644 --- a/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/components/CurrentUpcomingSubPanel.tsx +++ b/src/packages/v2v3/components/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/components/CurrentUpcomingSubPanel.tsx @@ -1,5 +1,6 @@ import { InformationCircleIcon } from '@heroicons/react/24/outline' import { Trans, t } from '@lingui/macro' +import { CountdownCallout } from 'components/Project/ProjectTabs/CyclesPayoutsTab/CountdownCallout' import { currentCycleRemainingLengthTooltip } from 'components/Project/ProjectTabs/CyclesPayoutsTab/CyclesPanelTooltips' import { UpcomingCycleChangesCallout } from 'components/Project/ProjectTabs/CyclesPayoutsTab/UpcomingCycleChangesCallout' import { TitleDescriptionDisplayCard } from 'components/Project/ProjectTabs/TitleDescriptionDisplayCard' @@ -104,8 +105,13 @@ export const CurrentUpcomingSubPanel = ({ return (
- {id === 'upcoming' && ( - + )} + {id === 'upcoming' && info.cycleNumber && info.cycleNumber > 1 && ( + { return upcomingFundingCycle?.duration?.isZero() ?? true }, [fundingCycle?.duration, type, upcomingFundingCycle?.duration]) + const start = + type === 'current' ? fundingCycle?.start : upcomingFundingCycle?.start + const upcomingCycleLength = useMemo(() => { if (!upcomingFundingCycle) return if (cycleUnlocked) return '-' @@ -82,6 +85,7 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => { cycleLength: upcomingCycleLength, cycleUnlocked, currentCycleUnlocked, + start, hasPendingConfiguration: /** * If a cycle is unlocked, it may have a pending change.