Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonz-dfinity committed Jul 17, 2024
1 parent 37cde99 commit 23d7e24
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
5 changes: 4 additions & 1 deletion frontend/src/lib/constants/neurons.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const LAST_TOPICS = [Topic.ExchangeRate];

// Topics that neurons cannot yet set following for.
// TODO: Remove this list when the NNS Governance supports following on those topics.
export const TOPICS_WITH_FOLLOWING_DISABLED = [Topic.ProtocolCanisterManagement, Topic.ServiceNervousSystemManagement];
export const TOPICS_WITH_FOLLOWING_DISABLED = [
Topic.ProtocolCanisterManagement,
Topic.ServiceNervousSystemManagement,
];

// This list should include ALL topics ordered as we want.
// Filtering out topics is done in the utils.
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/i18n/en.governance.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,4 @@
"DeployHostosToSomeNodes": "Deploy a HostOS version to a given set of nodes. The proposal changes the HostOS version that is used on the specified nodes.",
"SubnetRentalRequest": "A proposal to rent a subnet on the Internet Computer.<br/><br/>The Subnet Rental Canister is called when this proposal is executed, and the rental request is stored there. The user specified in the proposal needs to make a sufficient upfront payment in ICP in order for the proposal to be valid, and the subnet must be available for rent. The available rental conditions can be checked by calling the Subnet Rental Canister."
}
}
}
2 changes: 1 addition & 1 deletion frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1032,4 +1032,4 @@
"show_all": "Show all",
"import_token": "Import Token"
}
}
}
36 changes: 20 additions & 16 deletions frontend/src/lib/utils/neuron.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,26 +208,26 @@ export const bonusMultiplier = ({
}): number =>
1 +
multiplier *
(Math.min(Number(amount), max) /
// to avoid NaN
(max === 0 ? 1 : max));
(Math.min(Number(amount), max) /
// to avoid NaN
(max === 0 ? 1 : max));

// TODO: Do we need this? What does it mean to have a valid stake?
// TODO: https://dfinity.atlassian.net/browse/L2-507
export const hasValidStake = (neuron: NeuronInfo): boolean =>
// Ignore if we can't validate the stake
nonNullish(neuron.fullNeuron)
? neuron.fullNeuron.cachedNeuronStake +
neuron.fullNeuron.maturityE8sEquivalent >
BigInt(DEFAULT_TRANSACTION_FEE_E8S)
neuron.fullNeuron.maturityE8sEquivalent >
BigInt(DEFAULT_TRANSACTION_FEE_E8S)
: false;

export const getDissolvingTimestampSeconds = (
neuron: NeuronInfo
): bigint | undefined =>
neuron.state === NeuronState.Dissolving &&
neuron.fullNeuron?.dissolveState !== undefined &&
"WhenDissolvedTimestampSeconds" in neuron.fullNeuron.dissolveState
neuron.fullNeuron?.dissolveState !== undefined &&
"WhenDissolvedTimestampSeconds" in neuron.fullNeuron.dissolveState
? neuron.fullNeuron.dissolveState.WhenDissolvedTimestampSeconds
: undefined;

Expand Down Expand Up @@ -283,7 +283,7 @@ export const formattedMaturity = ({ fullNeuron }: NeuronInfo): string =>
export const formattedTotalMaturity = ({ fullNeuron }: NeuronInfo): string =>
formatMaturity(
(fullNeuron?.maturityE8sEquivalent ?? 0n) +
(fullNeuron?.stakedMaturityE8sEquivalent ?? 0n)
(fullNeuron?.stakedMaturityE8sEquivalent ?? 0n)
);

/**
Expand Down Expand Up @@ -369,7 +369,7 @@ export const isNeuronControllable = ({
fullNeuron?.controller !== undefined &&
(fullNeuron.controller === identity?.getPrincipal().toText() ||
getAccountByPrincipal({ principal: fullNeuron.controller, accounts }) !==
undefined);
undefined);

export const isNeuronControlledByHardwareWallet = ({
neuron,
Expand Down Expand Up @@ -735,12 +735,12 @@ export const canBeMerged = (
}
return sameManageNeuronFollowees(neurons)
? {
isValid: true,
}
isValid: true,
}
: {
isValid: false,
messageKey: "error.merge_neurons_not_same_manage_neuron_followees",
};
isValid: false,
messageKey: "error.merge_neurons_not_same_manage_neuron_followees",
};
};

export const mapNeuronIds = ({
Expand Down Expand Up @@ -815,7 +815,11 @@ export const topicsToFollow = (neuron: NeuronInfo): Topic[] =>
(followeesByTopic({ neuron, topic: Topic.ManageNeuron }) === undefined
? TOPICS_TO_FOLLOW_NNS.filter((topic) => topic !== Topic.ManageNeuron)
: TOPICS_TO_FOLLOW_NNS
).filter((topic) => !DEPRECATED_TOPICS.includes(topic) && !TOPICS_WITH_FOLLOWING_DISABLED.includes(topic));
).filter(
(topic) =>
!DEPRECATED_TOPICS.includes(topic) &&
!TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
);

// NeuronInfo is public info.
// fullNeuron is only for users with access.
Expand Down Expand Up @@ -973,7 +977,7 @@ export const maturityLastDistribution = ({
return (
actual_timestamp_seconds -
(fromNullable(rounds_since_last_distribution) ?? 1n) *
BigInt(SECONDS_IN_DAY)
BigInt(SECONDS_IN_DAY)
);
};

Expand Down
16 changes: 12 additions & 4 deletions frontend/src/tests/lib/utils/neuron.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2171,26 +2171,34 @@ describe("neuron-utils", () => {
expect(topicsToFollow(neuronWithoutManageNeuron)).toEqual(
TOPICS_TO_FOLLOW_NNS.filter(
(topic) =>
topic !== Topic.ManageNeuron && !DEPRECATED_TOPICS.includes(topic) && !TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
topic !== Topic.ManageNeuron &&
!DEPRECATED_TOPICS.includes(topic) &&
!TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
)
);
expect(topicsToFollow(neuronWithoutFollowees)).toEqual(
TOPICS_TO_FOLLOW_NNS.filter(
(topic) =>
topic !== Topic.ManageNeuron && !DEPRECATED_TOPICS.includes(topic) && !TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
topic !== Topic.ManageNeuron &&
!DEPRECATED_TOPICS.includes(topic) &&
!TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
)
);
expect(topicsToFollow(neuronWithManageNeuron)).toEqual(
TOPICS_TO_FOLLOW_NNS.filter(
(topic) => !DEPRECATED_TOPICS.includes(topic) && !TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
(topic) =>
!DEPRECATED_TOPICS.includes(topic) &&
!TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
)
);
});

it("should return topics with ManageNeuron if neuron follows some neuron on the ManageNeuron topic", () => {
expect(topicsToFollow(neuronWithManageNeuron)).toEqual(
TOPICS_TO_FOLLOW_NNS.filter(
(topic) => !DEPRECATED_TOPICS.includes(topic) && !TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
(topic) =>
!DEPRECATED_TOPICS.includes(topic) &&
!TOPICS_WITH_FOLLOWING_DISABLED.includes(topic)
)
);
});
Expand Down

0 comments on commit 23d7e24

Please sign in to comment.