Skip to content

Commit 829f597

Browse files
authored
fix: unlocked cycle upcoming state (#4193)
1 parent 506e6f3 commit 829f597

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

src/components/v2v3/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/components/CurrentUpcomingSubPanel.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ export const CurrentUpcomingSubPanel = ({
6363
</Trans>
6464
)
6565

66-
if (
66+
const hasNoUpcomingCycle =
6767
info.type === 'upcoming' &&
6868
info.currentCycleUnlocked &&
6969
/**
7070
* Always show 'upcoming' tab if it's FC 1
7171
* (which happens when Scheduled Launch is used,
7272
* mustStartAtOrAfter is in the future)
7373
*/
74-
info.cycleNumber !== 1
75-
) {
74+
info.cycleNumber !== 1 &&
75+
!info.hasPendingConfiguration
76+
77+
if (hasNoUpcomingCycle) {
7678
return (
7779
<div>
7880
<div

src/components/v2v3/V2V3Project/ProjectDashboard/components/CyclesPayoutsPanel/hooks/useCurrentUpcomingSubPanel.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useProjectContext } from 'components/v2v3/V2V3Project/ProjectDashboard/
44
import { useProjectMetadata } from 'components/v2v3/V2V3Project/ProjectDashboard/hooks/useProjectMetadata'
55
import { timeSecondsToDateString } from 'components/v2v3/V2V3Project/ProjectDashboard/utils/timeSecondsToDateString'
66
import { useProjectUpcomingFundingCycle } from 'hooks/v2v3/contractReader/useProjectUpcomingFundingCycle'
7+
import { BallotState } from 'models/v2v3/fundingCycle'
78
import { useMemo } from 'react'
89

910
export 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
}

src/hooks/v2v3/contractReader/useProjectUpcomingFundingCycle.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ type UpcomingFundingCycleDataType = [
1919
*/
2020
export function useProjectUpcomingFundingCycle({
2121
projectId,
22+
useLatestConfigured, // force latestConfiguredFundingCycleOf to be returned.
2223
}: {
2324
projectId: number | undefined
25+
useLatestConfigured?: boolean
2426
}): ContractReadResult<UpcomingFundingCycleDataType> {
2527
/**
2628
* Get Latest Configured Funding Cycle.
@@ -38,8 +40,9 @@ export function useProjectUpcomingFundingCycle({
3840
latestConfiguredFundingCycleBallotState,
3941
] = latestConfiguredFundingCycleResponse ?? []
4042
const isLatestConfiguredActive =
41-
latestConfiguredFundingCycle &&
42-
latestConfiguredFundingCycleBallotState === BallotState.active
43+
(latestConfiguredFundingCycle &&
44+
latestConfiguredFundingCycleBallotState === BallotState.active) ||
45+
useLatestConfigured
4346

4447
/**
4548
* Get Queued Configured Funding Cycle, *only if* latestConfiguredFundingCycle isn't active.

0 commit comments

Comments
 (0)