Skip to content

Commit

Permalink
Rename isNeuronMissingRewardSoon (#6352)
Browse files Browse the repository at this point in the history
# Motivation

Because of upcoming changes, `shouldDisplayMissingRewardNotification` is
no longer enough to decide whether missing rewards-related notifications
need to be shown. So, it makes sense to give the function a more generic
name.

# Changes

- Rename `shouldDisplayMissingRewardNotification` to
`isNeuronMissingRewardSoon`.

# Tests

- No logic changes. 

# Todos

- [ ] Add entry to changelog (if necessary).
Not necessary.
  • Loading branch information
mstrasinskis authored Feb 5, 2025
1 parent c6cfbb9 commit 0090dd0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
isNeuronFollowingReset,
isNeuronMissingReward,
secondsUntilMissingReward,
shouldDisplayMissingRewardNotification,
isNeuronMissingRewardsSoon,
} from "$lib/utils/neuron.utils";
import {
IconCheckCircleFill,
Expand Down Expand Up @@ -43,7 +43,7 @@
let isLosingRewardsSoon = false;
$: isLosingRewardsSoon =
!isLosingRewards &&
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
neuron,
startReducingVotingPowerAfterSeconds:
$startReducingVotingPowerAfterSecondsStore,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/derived/neurons.derived.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { startReducingVotingPowerAfterSecondsStore } from "$lib/derived/network-
import { neuronsStore } from "$lib/stores/neurons.store";
import {
hasValidStake,
shouldDisplayMissingRewardNotification,
isNeuronMissingRewardsSoon,
sortNeuronsByStake,
sortNeuronsByVotingPowerRefreshedTimeout,
} from "$lib/utils/neuron.utils";
Expand All @@ -25,7 +25,7 @@ export const soonLosingRewardNeuronsStore: Readable<NeuronInfo[]> = derived(
($definedNeuronsStore) =>
sortNeuronsByVotingPowerRefreshedTimeout(
$definedNeuronsStore.filter((neuron) =>
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
neuron,
startReducingVotingPowerAfterSeconds: get(
startReducingVotingPowerAfterSecondsStore
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/pages/NnsNeuronDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
getNeuronById,
isSpawning,
neuronVoting,
shouldDisplayMissingRewardNotification,
isNeuronMissingRewardsSoon,
} from "$lib/utils/neuron.utils";
import { Island } from "@dfinity/gix-components";
import type { NeuronId, NeuronInfo } from "@dfinity/nns";
Expand Down Expand Up @@ -156,7 +156,7 @@
$: isConfirmFollowingVisible =
$ENABLE_PERIODIC_FOLLOWING_CONFIRMATION &&
nonNullish(neuron) &&
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
neuron,
startReducingVotingPowerAfterSeconds:
$startReducingVotingPowerAfterSecondsStore,
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/lib/utils/neuron.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ const getNeuronTagsUnrelatedToController = ({
status: "danger",
});
} else if (
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
neuron,
startReducingVotingPowerAfterSeconds,
})
Expand Down Expand Up @@ -1326,6 +1326,7 @@ export const isNeuronFollowingReset = ({
return nowInSeconds() >= neuronFollowingResetTimestampSeconds;
};

// TODO(mstr): Rename to use the plural form of "rewards" in related functions.
/** If the voting power economics are not available,
* we assume that the neuron is not missing rewards. */
export const isNeuronMissingReward = ({
Expand All @@ -1346,7 +1347,7 @@ export const isNeuronMissingReward = ({
* e.g. "Neuron will start missing rewards in 30 days"
* If the voting power economics are not available,
* we assume that the neuron is not missing rewards. */
export const shouldDisplayMissingRewardNotification = ({
export const isNeuronMissingRewardsSoon = ({
neuron,
startReducingVotingPowerAfterSeconds,
}: {
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/tests/lib/utils/neuron.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
isNeuronControlledByHardwareWallet,
isNeuronFollowingReset,
isNeuronMissingReward,
isNeuronMissingRewardsSoon,
isPublicNeuron,
isSpawning,
isValidInputAmount,
Expand All @@ -70,7 +71,6 @@ import {
neuronStakedMaturity,
neuronsVotingPower,
secondsUntilMissingReward,
shouldDisplayMissingRewardNotification,
sortNeuronsByStake,
sortNeuronsByVotingPowerRefreshedTimeout,
topicsToFollow,
Expand Down Expand Up @@ -3751,10 +3751,10 @@ describe("neuron-utils", () => {
});
});

describe("shouldDisplayMissingRewardNotification", () => {
describe("isNeuronMissingRewardsSoon", () => {
it("should return false by default", () => {
expect(
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
startReducingVotingPowerAfterSeconds: BigInt(SECONDS_IN_HALF_YEAR),
neuron: {
...mockNeuron,
Expand All @@ -3766,7 +3766,7 @@ describe("neuron-utils", () => {

it("should return true after notification period starts", () => {
expect(
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
startReducingVotingPowerAfterSeconds: BigInt(SECONDS_IN_HALF_YEAR),
neuron: neuronWithRefreshedTimestamp({
votingPowerRefreshedTimestampAgeSecs:
Expand All @@ -3775,7 +3775,7 @@ describe("neuron-utils", () => {
})
).toBe(true);
expect(
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
startReducingVotingPowerAfterSeconds: BigInt(SECONDS_IN_HALF_YEAR),
neuron: neuronWithRefreshedTimestamp({
votingPowerRefreshedTimestampAgeSecs:
Expand All @@ -3787,7 +3787,7 @@ describe("neuron-utils", () => {

it("should return false w/o voting economics", () => {
expect(
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
startReducingVotingPowerAfterSeconds: undefined,
neuron: neuronWithRefreshedTimestamp({
votingPowerRefreshedTimestampAgeSecs:
Expand All @@ -3799,7 +3799,7 @@ describe("neuron-utils", () => {

it("should return false before notification period", () => {
expect(
shouldDisplayMissingRewardNotification({
isNeuronMissingRewardsSoon({
startReducingVotingPowerAfterSeconds: BigInt(SECONDS_IN_HALF_YEAR),
neuron: neuronWithRefreshedTimestamp({
votingPowerRefreshedTimestampAgeSecs:
Expand Down

0 comments on commit 0090dd0

Please sign in to comment.