@@ -4,6 +4,7 @@ import { useProjectContext } from 'components/v2v3/V2V3Project/ProjectDashboard/
4
4
import { useProjectMetadata } from 'components/v2v3/V2V3Project/ProjectDashboard/hooks/useProjectMetadata'
5
5
import { timeSecondsToDateString } from 'components/v2v3/V2V3Project/ProjectDashboard/utils/timeSecondsToDateString'
6
6
import { useProjectUpcomingFundingCycle } from 'hooks/v2v3/contractReader/useProjectUpcomingFundingCycle'
7
+ import { BallotState } from 'models/v2v3/fundingCycle'
7
8
import { useMemo } from 'react'
8
9
9
10
export const useCurrentUpcomingSubPanel = ( type : 'current' | 'upcoming' ) => {
@@ -15,8 +16,14 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
15
16
const {
16
17
data : upcomingFundingCycleData ,
17
18
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 ?? [ ]
20
27
const { timeRemainingText } = useFundingCycleCountdown ( )
21
28
22
29
const cycleNumber = useMemo ( ( ) => {
@@ -33,12 +40,6 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
33
40
return upcomingFundingCycle ?. duration ?. isZero ( ) ?? true
34
41
} , [ fundingCycle ?. duration , type , upcomingFundingCycle ?. duration ] )
35
42
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
-
42
43
const upcomingCycleLength = useMemo ( ( ) => {
43
44
if ( ! upcomingFundingCycle ) return
44
45
if ( cycleUnlocked ) return '-'
@@ -48,15 +49,12 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
48
49
)
49
50
} , [ cycleUnlocked , upcomingFundingCycle ] )
50
51
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
55
55
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
60
58
61
59
// Short circuit current for faster loading
62
60
if ( type === 'current' ) {
@@ -84,5 +82,14 @@ export const useCurrentUpcomingSubPanel = (type: 'current' | 'upcoming') => {
84
82
cycleLength : upcomingCycleLength ,
85
83
cycleUnlocked,
86
84
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 ,
87
94
}
88
95
}
0 commit comments