Skip to content

Commit 0ca8771

Browse files
committed
[14/04 16:05 - feature/mission-70]: WIP - Work in progress!
1 parent d35e955 commit 0ca8771

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

src/governance-app-frontend/src/features/stakes/components/neuronDetail/NeuronDetailIncreaseDelayView.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { Alert, AlertDescription } from '@components/Alert';
77
import { Button } from '@components/button';
88
import { MaxRewardsBadge } from '@components/MaxRewardsBadge';
99
import { SECONDS_IN_MONTH } from '@constants/extra';
10-
import { ICP_MAX_DISSOLVE_DELAY_MONTHS } from '@constants/neuron';
1110
import { mapCanisterError } from '@utils/errors';
12-
import { getNeuronDissolveDelaySeconds } from '@utils/neuron';
11+
import { getNeuronDissolveDelaySeconds, getNeuronIsMaxDissolveDelay } from '@utils/neuron';
1312
import { errorNotification, successNotification } from '@utils/notification';
1413

1514
import { useIncreaseDelay } from '../../hooks/useIncreaseDelay';
@@ -34,11 +33,8 @@ export function NeuronDetailIncreaseDelayView({
3433

3534
const { mutateAsync, isPending } = useIncreaseDelay();
3635

37-
// Get current dissolve delay in months
3836
const currentDelaySeconds = Number(getNeuronDissolveDelaySeconds(neuron));
39-
const currentDelayMonths = Math.round(currentDelaySeconds / SECONDS_IN_MONTH);
40-
41-
const isMaxDelay = currentDelayMonths >= ICP_MAX_DISSOLVE_DELAY_MONTHS;
37+
const isMaxDelay = getNeuronIsMaxDissolveDelay(neuron);
4238

4339
const handleConfirm = async () => {
4440
if (!selectedMonths) return;
@@ -49,6 +45,7 @@ export function NeuronDetailIncreaseDelayView({
4945
await mutateAsync({
5046
neuronId: neuron.neuronId,
5147
dissolveDelayMonths: selectedMonths,
48+
currentDissolveDelaySeconds: currentDelaySeconds,
5249
});
5350

5451
successNotification({
@@ -101,7 +98,7 @@ export function NeuronDetailIncreaseDelayView({
10198
<div className="mb-2 grid grid-cols-1 gap-2 sm:grid-cols-2">
10299
{regularOptions.map((option) => {
103100
const isSelected = selectedMonths === option.value;
104-
const isDisabled = option.value <= currentDelayMonths;
101+
const isDisabled = option.value * SECONDS_IN_MONTH <= currentDelaySeconds;
105102

106103
return (
107104
<button
@@ -128,7 +125,7 @@ export function NeuronDetailIncreaseDelayView({
128125
{/* Max rewards option */}
129126
{(() => {
130127
const isSelected = selectedMonths === maxRewardsOption.value;
131-
const isDisabled = maxRewardsOption.value === currentDelayMonths;
128+
const isDisabled = maxRewardsOption.value * SECONDS_IN_MONTH <= currentDelaySeconds;
132129

133130
return (
134131
<button

src/governance-app-frontend/src/features/stakes/hooks/useCreateNeuron.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getConsistentTopicFollowees,
1010
} from '@features/voting/utils/topicFollowing';
1111

12-
import { E8Sn, ICP_TRANSACTION_FEE_E8Sn, SECONDS_IN_MONTH } from '@constants/extra';
12+
import { E8Sn, ICP_TRANSACTION_FEE_E8Sn, SECONDS_IN_DAY, SECONDS_IN_MONTH } from '@constants/extra';
1313
import { useNnsGovernance } from '@hooks/governance';
1414
import { useIcpLedger } from '@hooks/icpLedger';
1515
import { bigIntMul } from '@utils/bigInt';
@@ -88,12 +88,13 @@ export function useCreateNeuron(params: Props) {
8888
}
8989

9090
// Step 2: Set dissolve delay
91+
// New neurons start with a default 7-day dissolve delay, so subtract it
9192
if (step === StakingWizardCreateNeuronStep.SetDissolveDelay) {
92-
const newDissolveTimestamp =
93-
Math.floor(Date.now() / 1000) + params.dissolveDelayMonths * SECONDS_IN_MONTH;
94-
await governanceCanister.setDissolveDelay({
93+
const defaultDelay = SECONDS_IN_DAY * 7;
94+
const targetDelay = params.dissolveDelayMonths * SECONDS_IN_MONTH;
95+
await governanceCanister.increaseDissolveDelay({
9596
neuronId,
96-
dissolveDelaySeconds: newDissolveTimestamp,
97+
additionalDissolveDelaySeconds: Math.max(targetDelay - defaultDelay, 0),
9798
});
9899
step = StakingWizardCreateNeuronStep.SetAutoStakeMaturity;
99100
setCurrentStep(step);

src/governance-app-frontend/src/features/stakes/hooks/useIncreaseDelay.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { failedRefresh, QUERY_KEYS } from '@utils/query';
99
type IncreaseDelayParams = {
1010
neuronId: bigint;
1111
dissolveDelayMonths: number;
12+
currentDissolveDelaySeconds: number;
1213
};
1314

1415
/**
@@ -27,14 +28,11 @@ export function useIncreaseDelay() {
2728
throw new Error(t(($) => $.neuronDetailModal.increaseDelay.errors.failed));
2829
}
2930

30-
// Calculate the new dissolve delay timestamp
31-
// This is the current time + the delay in seconds
32-
const newDissolveTimestamp =
33-
Math.floor(Date.now() / 1000) + params.dissolveDelayMonths * SECONDS_IN_MONTH;
34-
35-
await governanceCanister.setDissolveDelay({
31+
const targetDelay = params.dissolveDelayMonths * SECONDS_IN_MONTH;
32+
const additional = Math.max(targetDelay - params.currentDissolveDelaySeconds, 0);
33+
await governanceCanister.increaseDissolveDelay({
3634
neuronId: params.neuronId,
37-
dissolveDelaySeconds: newDissolveTimestamp,
35+
additionalDissolveDelaySeconds: additional,
3836
});
3937

4038
await queryClient

0 commit comments

Comments
 (0)