From 418edfc5e60f479d32c65b72cb950d3145d637f7 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 17 Jul 2024 22:30:35 +0000 Subject: [PATCH] Do not display unrecognized topics when showing followees --- frontend/src/lib/utils/neuron.utils.ts | 33 ++++++++++--------- .../src/tests/lib/utils/neuron.utils.spec.ts | 4 +++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/frontend/src/lib/utils/neuron.utils.ts b/frontend/src/lib/utils/neuron.utils.ts index 02e2da1803b..c87a7d5c28f 100644 --- a/frontend/src/lib/utils/neuron.utils.ts +++ b/frontend/src/lib/utils/neuron.utils.ts @@ -207,9 +207,9 @@ 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 @@ -217,16 +217,16 @@ 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; @@ -282,7 +282,7 @@ export const formattedMaturity = ({ fullNeuron }: NeuronInfo): string => export const formattedTotalMaturity = ({ fullNeuron }: NeuronInfo): string => formatMaturity( (fullNeuron?.maturityE8sEquivalent ?? 0n) + - (fullNeuron?.stakedMaturityE8sEquivalent ?? 0n) + (fullNeuron?.stakedMaturityE8sEquivalent ?? 0n) ); /** @@ -368,7 +368,7 @@ export const isNeuronControllable = ({ fullNeuron?.controller !== undefined && (fullNeuron.controller === identity?.getPrincipal().toText() || getAccountByPrincipal({ principal: fullNeuron.controller, accounts }) !== - undefined); + undefined); export const isNeuronControlledByHardwareWallet = ({ neuron, @@ -486,6 +486,9 @@ export const followeesNeurons = (neuron: NeuronInfo): FolloweesNeuron[] => { result.find(({ neuronId: id }) => id === neuronId); for (const { followees, topic } of neuron.fullNeuron.followees) { + if (!(topic in Topic)) { + continue; + } for (const neuronId of followees) { const followeesNeuron = resultNeuron(neuronId); if (followeesNeuron === undefined) { @@ -734,12 +737,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 = ({ @@ -972,7 +975,7 @@ export const maturityLastDistribution = ({ return ( actual_timestamp_seconds - (fromNullable(rounds_since_last_distribution) ?? 1n) * - BigInt(SECONDS_IN_DAY) + BigInt(SECONDS_IN_DAY) ); }; diff --git a/frontend/src/tests/lib/utils/neuron.utils.spec.ts b/frontend/src/tests/lib/utils/neuron.utils.spec.ts index 8054d0c6f99..92c6a02eafa 100644 --- a/frontend/src/tests/lib/utils/neuron.utils.spec.ts +++ b/frontend/src/tests/lib/utils/neuron.utils.spec.ts @@ -1056,6 +1056,10 @@ describe("neuron-utils", () => { topic: Topic.Governance, followees: [0n, 1n, 2n], }, + { + topic: 100 as Topic, + followees: [3n, 4n], + } ], }, };