@@ -4,6 +4,7 @@ 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'
78import { useMemo } from 'react'
89
910export const useCurrentUpcomingSubPanel = ( type : 'current' | 'upcoming' ) => {
@@ -15,8 +16,14 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
1516 const {
1617 data : upcomingFundingCycleData ,
1718 loading : upcomingFundingCycleLoading ,
18- } = useProjectUpcomingFundingCycle ( { projectId } )
19- const [ upcomingFundingCycle ] = upcomingFundingCycleData ?? [ ]
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 ?? [ ]
2027 const { timeRemainingText } = useFundingCycleCountdown ( )
2128
2229 const cycleNumber = useMemo ( ( ) => {
@@ -33,12 +40,6 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
3340 return upcomingFundingCycle ?. duration ?. isZero ( ) ?? true
3441 } , [ fundingCycle ?. duration , type , upcomingFundingCycle ?. duration ] )
3542
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-
4243 const upcomingCycleLength = useMemo ( ( ) => {
4344 if ( ! upcomingFundingCycle ) return
4445 if ( cycleUnlocked ) return '-'
@@ -48,15 +49,12 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
4849 )
4950 } , [ cycleUnlocked , upcomingFundingCycle ] )
5051
51- const status = useMemo ( ( ) => {
52- if ( cycleUnlocked ) return t `Unlocked`
53- return t `Locked`
54- } , [ cycleUnlocked ] )
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
5555
56- const remainingTime = useMemo ( ( ) => {
57- if ( cycleUnlocked ) return '-'
58- return timeRemainingText
59- } , [ cycleUnlocked , timeRemainingText ] )
56+ const status = cycleUnlocked ? t `Unlocked` : t `Locked`
57+ const remainingTime = cycleUnlocked ? '-' : timeRemainingText
6058
6159 // Short circuit current for faster loading
6260 if ( type === 'current' ) {
@@ -84,5 +82,14 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
8482 cycleLength : upcomingCycleLength ,
8583 cycleUnlocked,
8684 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 ,
8794 }
8895}
0 commit comments