Skip to content

Draft: Don't display confirm following for not votable neurons #6348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
isNeuronMissingReward,
secondsUntilMissingReward,
isNeuronMissingRewardsSoon,
hasEnoughDissolveDelayToVote,
} from "$lib/utils/neuron.utils";
import {
IconCheckCircleFill,
Expand Down Expand Up @@ -96,7 +97,7 @@
};
</script>

{#if nonNullish($startReducingVotingPowerAfterSecondsStore) && nonNullish($clearFollowingAfterSecondsStore)}
{#if hasEnoughDissolveDelayToVote(neuron) && nonNullish($startReducingVotingPowerAfterSecondsStore) && nonNullish($clearFollowingAfterSecondsStore)}
<CommonItemAction
testId="nns-neuron-reward-status-action-component"
tooltipText={replacePlaceholders($i18n.missing_rewards.description, {
Expand Down
18 changes: 11 additions & 7 deletions frontend/src/lib/derived/neurons.derived.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { startReducingVotingPowerAfterSecondsStore } from "$lib/derived/network-economics.derived";
import { neuronsStore } from "$lib/stores/neurons.store";
import {
hasEnoughDissolveDelayToVote,
hasValidStake,
isNeuronMissingRewardsSoon,
sortNeuronsByStake,
Expand All @@ -24,13 +25,16 @@ export const soonLosingRewardNeuronsStore: Readable<NeuronInfo[]> = derived(
definedNeuronsStore,
($definedNeuronsStore) =>
sortNeuronsByVotingPowerRefreshedTimeout(
$definedNeuronsStore.filter((neuron) =>
isNeuronMissingRewardsSoon({
neuron,
startReducingVotingPowerAfterSeconds: get(
startReducingVotingPowerAfterSecondsStore
),
})
$definedNeuronsStore.filter(
(neuron) =>
// Neurons that are not able to vote cannot suddenly miss rewards.
hasEnoughDissolveDelayToVote(neuron) &&
isNeuronMissingRewardsSoon({
neuron,
startReducingVotingPowerAfterSeconds: get(
startReducingVotingPowerAfterSecondsStore
),
})
)
)
);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/pages/NnsNeuronDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
isSpawning,
neuronVoting,
isNeuronMissingRewardsSoon,
hasEnoughDissolveDelayToVote,
} from "$lib/utils/neuron.utils";
import { Island } from "@dfinity/gix-components";
import type { NeuronId, NeuronInfo } from "@dfinity/nns";
Expand Down Expand Up @@ -156,6 +157,7 @@
$: isConfirmFollowingVisible =
$ENABLE_PERIODIC_FOLLOWING_CONFIRMATION &&
nonNullish(neuron) &&
hasEnoughDissolveDelayToVote(neuron) &&
isNeuronMissingRewardsSoon({
neuron,
startReducingVotingPowerAfterSeconds:
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/tests/fakes/governance-api.fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ export const addNeuronWith = ({
neuronType,
controller,
stake,
dissolveDelaySeconds,
votingPowerRefreshedTimestampSeconds = nowInSeconds(),
}: {
identity?: Identity;
votingPowerRefreshedTimestampSeconds?: bigint | number;
dissolveDelaySeconds?: bigint | number;
} & Partial<FakeNeuronParams>): NeuronInfo => {
const neuron = { ...mockNeuron, fullNeuron: { ...mockNeuron.fullNeuron } };
if (neuronId) {
Expand All @@ -221,6 +223,9 @@ export const addNeuronWith = ({
if (controller) {
neuron.fullNeuron.controller = controller;
}
if (nonNullish(dissolveDelaySeconds)) {
neuron.dissolveDelaySeconds = BigInt(dissolveDelaySeconds);
}
if (nonNullish(votingPowerRefreshedTimestampSeconds)) {
neuron.fullNeuron.votingPowerRefreshedTimestampSeconds = BigInt(
votingPowerRefreshedTimestampSeconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ describe("NnsNeuronRewardStatusAction", () => {
});

it("should render active neuron state", async () => {
const testNeuron = {
const testNeuron: NeuronInfo = {
...mockNeuron,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowInSeconds()),
Expand All @@ -54,9 +55,24 @@ describe("NnsNeuronRewardStatusAction", () => {
expect(await po.getFollowNeuronsButtonPo().isPresent()).toBe(false);
});

it("should not render active neuron state when neuron dissolve delay is too low for voting", async () => {
const testNeuron: NeuronInfo = {
...mockNeuron,
dissolveDelaySeconds: 0n,
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowInSeconds()),
},
};
const po = renderComponent(testNeuron);

expect(await po.isPresent()).toBe(false);
});

it("should not render active neuron state w/o voting power economics params", async () => {
const testNeuron = {
const testNeuron: NeuronInfo = {
...mockNeuron,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowInSeconds()),
Expand All @@ -70,8 +86,9 @@ describe("NnsNeuronRewardStatusAction", () => {

it("should render losing soon neuron state", async () => {
const tenDays = 10;
const testNeuron = {
const testNeuron: NeuronInfo = {
...mockNeuron,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand All @@ -90,8 +107,9 @@ describe("NnsNeuronRewardStatusAction", () => {
});

it("should render inactive neuron reward state", async () => {
const testNeuron = {
const testNeuron: NeuronInfo = {
...mockNeuron,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand All @@ -110,8 +128,9 @@ describe("NnsNeuronRewardStatusAction", () => {
});

it("should render inactive/reset following neuron reward state", async () => {
const testNeuron = {
const testNeuron: NeuronInfo = {
...mockNeuron,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ describe("NnsStakeItemAction", () => {
});

it("should render item actions", async () => {
const po = renderComponent(mockNeuron);
const po = renderComponent({
...mockNeuron,
dissolveDelaySeconds: BigInt(NNS_MINIMUM_DISSOLVE_DELAY_TO_VOTE),
});

expect(await po.hasStakeItemAction()).toBe(true);
expect(await po.hasNeuronStateItemAction()).toBe(true);
Expand All @@ -156,7 +159,10 @@ describe("NnsStakeItemAction", () => {
parameters: mockNetworkEconomics,
certified: true,
});
const po = renderComponent(mockNeuron);
const po = renderComponent({
...mockNeuron,
dissolveDelaySeconds: BigInt(NNS_MINIMUM_DISSOLVE_DELAY_TO_VOTE),
});

expect(await po.getNnsNeuronRewardStatusActionPo().isPresent()).toBe(true);
});
Expand All @@ -166,7 +172,10 @@ describe("NnsStakeItemAction", () => {
"ENABLE_PERIODIC_FOLLOWING_CONFIRMATION",
false
);
const po = renderComponent(mockNeuron);
const po = renderComponent({
...mockNeuron,
dissolveDelaySeconds: BigInt(NNS_MINIMUM_DISSOLVE_DELAY_TO_VOTE),
});

expect(await po.getNnsNeuronRewardStatusActionPo().isPresent()).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("LosingRewardNeuronsModal", () => {
const activeNeuron = {
...mockNeuron,
neuronId: 0n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowSeconds),
Expand All @@ -34,6 +35,7 @@ describe("LosingRewardNeuronsModal", () => {
const in10DaysLosingRewardsNeuron = {
...mockNeuron,
neuronId: 1n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand All @@ -45,6 +47,7 @@ describe("LosingRewardNeuronsModal", () => {
const losingRewardsNeuron = {
...mockNeuron,
neuronId: 2n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("LosingRewardsBanner", () => {
const activeNeuron = {
...mockNeuron,
neuronId: 0n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowSeconds),
Expand All @@ -26,6 +27,7 @@ describe("LosingRewardsBanner", () => {
const in10DaysLosingRewardsNeuron = {
...mockNeuron,
neuronId: 1n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand All @@ -37,6 +39,7 @@ describe("LosingRewardsBanner", () => {
const losingRewardsNeuron = {
...mockNeuron,
neuronId: 2n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand All @@ -52,6 +55,7 @@ describe("LosingRewardsBanner", () => {
];
const refreshedNeurons = neurons.map((neuron) => ({
...neuron,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...neuron.fullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowSeconds),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ import { mockFullNeuron, mockNeuron } from "$tests/mocks/neurons.mock";
import { NnsNeuronsMissingRewardsBadgePo } from "$tests/page-objects/NnsNeuronsMissingRewardsBadge.page-object";
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object";
import { render } from "$tests/utils/svelte.test-utils";
import type { NeuronInfo } from "@dfinity/nns";

describe("NnsNeuronsMissingRewardsBadge", () => {
const nowSeconds = nowInSeconds();
const activeNeuron = {
const activeNeuron: NeuronInfo = {
...mockNeuron,
neuronId: 0n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowSeconds),
controller: mockIdentity.getPrincipal().toText(),
},
};
const losingRewardsNeuron = {
const losingRewardsNeuron: NeuronInfo = {
...mockNeuron,
neuronId: 2n,
dissolveDelaySeconds: BigInt(SECONDS_IN_HALF_YEAR),
fullNeuron: {
...mockFullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/tests/lib/derived/neurons.derived.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ describe("neurons-derived", () => {
});

describe("soonLosingRewardNeuronsStore", () => {
const enoughDissolveDelayToVote = BigInt(SECONDS_IN_HALF_YEAR);
const neuron1 = {
...mockNeuron,
dissolveDelaySeconds: enoughDissolveDelayToVote,
fullNeuron: {
...mockNeuron.fullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(
Expand All @@ -127,6 +129,7 @@ describe("neurons-derived", () => {
};
const neuron2 = {
...mockNeuron,
dissolveDelaySeconds: enoughDissolveDelayToVote,
fullNeuron: {
...mockNeuron.fullNeuron,
votingPowerRefreshedTimestampSeconds: 0n,
Expand All @@ -135,6 +138,7 @@ describe("neurons-derived", () => {
};
const neuron3 = {
...mockNeuron,
dissolveDelaySeconds: enoughDissolveDelayToVote,
fullNeuron: {
...mockNeuron.fullNeuron,
votingPowerRefreshedTimestampSeconds: 0n,
Expand All @@ -143,6 +147,7 @@ describe("neurons-derived", () => {
};
const freshNeuron = {
...mockNeuron,
dissolveDelaySeconds: enoughDissolveDelayToVote,
fullNeuron: {
...mockNeuron.fullNeuron,
votingPowerRefreshedTimestampSeconds: BigInt(nowInSeconds()),
Expand Down Expand Up @@ -196,5 +201,17 @@ describe("neurons-derived", () => {
});
expect(get(soonLosingRewardNeuronsStore)).toEqual([]);
});

it("should not include neurons that have not enough dissolve delay to vote", () => {
const notEnoughDissolveDelayToVoteNeuron = {
...neuron1,
dissolveDelaySeconds: enoughDissolveDelayToVote - 1n,
};
neuronsStore.setNeurons({
neurons: [notEnoughDissolveDelayToVoteNeuron, neuron1],
certified: true,
});
expect(get(soonLosingRewardNeuronsStore)).toEqual([neuron1]);
});
});
});
Loading