@@ -4,7 +4,6 @@ import { useProjectContext } from 'components/v2v3/V2V3Project/ProjectDashboard/
44import { useProjectMetadata } from 'components/v2v3/V2V3Project/ProjectDashboard/hooks/useProjectMetadata'
55import { timeSecondsToDateString } from 'components/v2v3/V2V3Project/ProjectDashboard/utils/timeSecondsToDateString'
66import { useProjectUpcomingFundingCycle } from 'hooks/v2v3/contractReader/useProjectUpcomingFundingCycle'
7- import { BallotState } from 'models/v2v3/fundingCycle'
87import { useMemo } from 'react'
98
109export const useCurrentUpcomingSubPanel = ( type : 'current' | 'upcoming' ) => {
@@ -16,14 +15,8 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
1615 const {
1716 data : upcomingFundingCycleData ,
1817 loading : upcomingFundingCycleLoading ,
19- } = useProjectUpcomingFundingCycle ( {
20- projectId,
21- /**
22- * if the current cycle is unlocked, force the use of latestConfiguredFundingCycleOf.
23- */
24- useLatestConfigured : fundingCycle ?. duration ?. isZero ( ) ?? false ,
25- } )
26- const [ upcomingFundingCycle , , ballotState ] = upcomingFundingCycleData ?? [ ]
18+ } = useProjectUpcomingFundingCycle ( { projectId } )
19+ const [ upcomingFundingCycle ] = upcomingFundingCycleData ?? [ ]
2720 const { timeRemainingText } = useFundingCycleCountdown ( )
2821
2922 const cycleNumber = useMemo ( ( ) => {
@@ -40,6 +33,12 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
4033 return upcomingFundingCycle ?. duration ?. isZero ( ) ?? true
4134 } , [ fundingCycle ?. duration , type , upcomingFundingCycle ?. duration ] )
4235
36+ /** Determines if the CURRENT cycle is unlocked.
37+ * This is used to check if the upcoming cycle can start at any time. */
38+ const currentCycleUnlocked = useMemo ( ( ) => {
39+ return fundingCycle ?. duration ?. isZero ( ) ?? true
40+ } , [ fundingCycle ?. duration ] )
41+
4342 const upcomingCycleLength = useMemo ( ( ) => {
4443 if ( ! upcomingFundingCycle ) return
4544 if ( cycleUnlocked ) return '-'
@@ -49,12 +48,15 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
4948 )
5049 } , [ cycleUnlocked , upcomingFundingCycle ] )
5150
52- /** Determines if the CURRENT cycle is unlocked.
53- * This is used to check if the upcoming cycle can start at any time. */
54- const currentCycleUnlocked = fundingCycle ?. duration ?. isZero ( ) ?? true
51+ const status = useMemo ( ( ) => {
52+ if ( cycleUnlocked ) return t `Unlocked`
53+ return t `Locked`
54+ } , [ cycleUnlocked ] )
5555
56- const status = cycleUnlocked ? t `Unlocked` : t `Locked`
57- const remainingTime = cycleUnlocked ? '-' : timeRemainingText
56+ const remainingTime = useMemo ( ( ) => {
57+ if ( cycleUnlocked ) return '-'
58+ return timeRemainingText
59+ } , [ cycleUnlocked , timeRemainingText ] )
5860
5961 // Short circuit current for faster loading
6062 if ( type === 'current' ) {
@@ -82,14 +84,5 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
8284 cycleLength : upcomingCycleLength ,
8385 cycleUnlocked,
8486 currentCycleUnlocked,
85- hasPendingConfiguration :
86- /**
87- * If a cycle is unlocked, it may have a pending change.
88- * The only way it would, is if the ballot state of the latestConfiguredFC is `approved`.
89- */
90- cycleUnlocked &&
91- typeof ballotState !== 'undefined' &&
92- ballotState !== null &&
93- ballotState === BallotState . approved ,
9487 }
9588}
0 commit comments