diff --git a/frontend/src/lib/components/common/PageHeading.svelte b/frontend/src/lib/components/common/PageHeading.svelte new file mode 100644 index 00000000000..8b43f0bbe6e --- /dev/null +++ b/frontend/src/lib/components/common/PageHeading.svelte @@ -0,0 +1,27 @@ + + +
+ +

+ +

+
+ + diff --git a/frontend/src/lib/components/neuron-detail/NnsNeuronPageHeading.svelte b/frontend/src/lib/components/neuron-detail/NnsNeuronPageHeading.svelte index 12159b1f3a2..edc11166ef8 100644 --- a/frontend/src/lib/components/neuron-detail/NnsNeuronPageHeading.svelte +++ b/frontend/src/lib/components/neuron-detail/NnsNeuronPageHeading.svelte @@ -5,6 +5,7 @@ import { formatVotingPower, neuronStake } from "$lib/utils/neuron.utils"; import { replacePlaceholders } from "$lib/utils/i18n.utils"; import { i18n } from "$lib/stores/i18n"; + import PageHeading from "../common/PageHeading.svelte"; export let neuron: NeuronInfo; @@ -15,28 +16,11 @@ }); -
- -

+ + + {replacePlaceholders($i18n.neuron_detail.voting_power_subtitle, { $votingPower: formatVotingPower(neuron.votingPower), })} -

-
- - + + diff --git a/frontend/src/lib/components/sns-neuron-detail/SnsNeuronPageHeading.svelte b/frontend/src/lib/components/sns-neuron-detail/SnsNeuronPageHeading.svelte new file mode 100644 index 00000000000..91d0eb22850 --- /dev/null +++ b/frontend/src/lib/components/sns-neuron-detail/SnsNeuronPageHeading.svelte @@ -0,0 +1,57 @@ + + + + + {#if nonNullish(amount)} + + {/if} + + + {#if nonNullish(neuron)} + {replacePlaceholders($i18n.neuron_detail.voting_power_subtitle, { + $votingPower: formatNumber( + snsNeuronVotingPower({ neuron, snsParameters: parameters }) + ), + })} + {/if} + + diff --git a/frontend/src/lib/pages/SnsNeuronDetail.svelte b/frontend/src/lib/pages/SnsNeuronDetail.svelte index fb9175003bc..01eabf19c38 100644 --- a/frontend/src/lib/pages/SnsNeuronDetail.svelte +++ b/frontend/src/lib/pages/SnsNeuronDetail.svelte @@ -42,6 +42,8 @@ import SnsNeuronVotingPowerSection from "$lib/components/sns-neuron-detail/SnsNeuronVotingPowerSection.svelte"; import SnsNeuronMaturitySection from "$lib/components/sns-neuron-detail/SnsNeuronMaturitySection.svelte"; import SnsNeuronAdvancedSection from "$lib/components/sns-neuron-detail/SnsNeuronAdvancedSection.svelte"; + import Separator from "$lib/components/ui/Separator.svelte"; + import SnsNeuronPageHeading from "$lib/components/sns-neuron-detail/SnsNeuronPageHeading.svelte"; export let neuronId: string | null | undefined; @@ -149,11 +151,15 @@ {:else} - {#if $ENABLE_NEURON_SETTINGS} - - - - + {#if $ENABLE_NEURON_SETTINGS && nonNullish(parameters)} +
+ + + + + + +
{/if} @@ -179,3 +185,11 @@ + + diff --git a/frontend/src/tests/lib/components/sns-neuron-detail/SnsNeuronPageHeading.spec.ts b/frontend/src/tests/lib/components/sns-neuron-detail/SnsNeuronPageHeading.spec.ts new file mode 100644 index 00000000000..8321c532020 --- /dev/null +++ b/frontend/src/tests/lib/components/sns-neuron-detail/SnsNeuronPageHeading.spec.ts @@ -0,0 +1,38 @@ +/** + * @jest-environment jsdom + */ + +import SnsNeuronPageHeading from "$lib/components/sns-neuron-detail/SnsNeuronPageHeading.svelte"; +import { renderSelectedSnsNeuronContext } from "$tests/mocks/context-wrapper.mock"; +import { + mockSnsNeuron, + snsNervousSystemParametersMock, +} from "$tests/mocks/sns-neurons.mock"; +import { SnsNeuronPageHeadingPo } from "$tests/page-objects/SnsNeuronPageHeading.page-object"; +import { JestPageObjectElement } from "$tests/page-objects/jest.page-object"; +import type { SnsNeuron } from "@dfinity/sns"; + +describe("SnsNeuronPageHeading", () => { + const renderSnsNeuronCmp = (neuron: SnsNeuron) => { + const { container } = renderSelectedSnsNeuronContext({ + Component: SnsNeuronPageHeading, + neuron, + reload: jest.fn(), + props: { + parameters: snsNervousSystemParametersMock, + }, + }); + + return SnsNeuronPageHeadingPo.under(new JestPageObjectElement(container)); + }; + + it("should render the neuron's stake", async () => { + const stake = 314_000_000n; + const po = renderSnsNeuronCmp({ + ...mockSnsNeuron, + cached_neuron_stake_e8s: stake, + }); + + expect(await po.getStake()).toEqual("3.14"); + }); +}); diff --git a/frontend/src/tests/page-objects/SnsNeuronPageHeading.page-object.ts b/frontend/src/tests/page-objects/SnsNeuronPageHeading.page-object.ts new file mode 100644 index 00000000000..001edb6f368 --- /dev/null +++ b/frontend/src/tests/page-objects/SnsNeuronPageHeading.page-object.ts @@ -0,0 +1,21 @@ +import { AmountDisplayPo } from "$tests/page-objects/AmountDisplay.page-object"; +import { BasePageObject } from "$tests/page-objects/base.page-object"; +import type { PageObjectElement } from "$tests/types/page-object.types"; + +export class SnsNeuronPageHeadingPo extends BasePageObject { + private static readonly TID = "sns-neuron-page-heading-component"; + + static under(element: PageObjectElement): SnsNeuronPageHeadingPo { + return new SnsNeuronPageHeadingPo( + element.byTestId(SnsNeuronPageHeadingPo.TID) + ); + } + + getAmountDisplayPo(): AmountDisplayPo { + return AmountDisplayPo.under(this.root); + } + + getStake(): Promise { + return this.getAmountDisplayPo().getAmount(); + } +}