Skip to content
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

NNS1-3348 display public neuron badge #5500

Merged
merged 28 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cbdde0c
Update en.json
Sep 20, 2024
5c26369
Update neurons-table and utils
Sep 20, 2024
e046911
Update neuron utils and add tests
Sep 20, 2024
1738eab
Add IconPublicBadge, update po and add test
Sep 20, 2024
b98048e
Use --elements-badge color
Sep 20, 2024
de887e1
Set visibility undefined for SNS neurons
Sep 23, 2024
c9b1e8f
Add visibility to mockTableNeuron
Sep 23, 2024
69dcf1b
Update gix-components
Sep 23, 2024
4c155f0
bot: Bump gix-components (#5503)
sa-github-api Sep 23, 2024
380d87f
fix tags display
coskucinkilic Sep 23, 2024
6f2ca0e
Update e2e screenshots
coskucinkilic Sep 23, 2024
8623224
bot: Bump ic-js (#5509)
sa-github-api Sep 23, 2024
57d0028
bot: Update IC Cargo Dependencies to release-2024-09-19_01-31-base (#…
sa-github-api Sep 24, 2024
aa3c9a6
bot: Update proposals candid bindings (#5502)
sa-github-api Sep 24, 2024
03010b6
remove gap from neuronIdCell container and add margin-right to public…
coskucinkilic Sep 24, 2024
71145c4
remove visibility and add isPublic to tableNeuron
coskucinkilic Sep 24, 2024
3f44189
Update tableNeuronsFromSnsNeurons
coskucinkilic Sep 24, 2024
97145a4
dynamically get ENABLE_NEURON_VISIBILITY with $
coskucinkilic Sep 24, 2024
c3df540
Remove import of get
coskucinkilic Sep 24, 2024
36dd7de
Update e2e screenshots
coskucinkilic Sep 24, 2024
d505255
Merge branch 'main' of https://github.com/dfinity/nns-dapp into NNS1-…
coskucinkilic Sep 24, 2024
ddddafa
Merge branch 'main' of https://github.com/dfinity/nns-dapp into NNS1-…
coskucinkilic Sep 24, 2024
780952e
fix tests
coskucinkilic Sep 24, 2024
8d47465
Rename utility function to isPublicNeuron
coskucinkilic Sep 24, 2024
869b230
rename getVisibilityTooltipPo to getPublicNeuronTooltipPo
coskucinkilic Sep 24, 2024
eb110ba
Merge branch 'main' into NNS1-3348-display-public-neuron-badge
coskucinkilic Sep 25, 2024
5a3829b
Merge branch 'main' into NNS1-3348-display-public-neuron-badge
coskucinkilic Sep 25, 2024
64cb2b8
Merge branch 'main' into NNS1-3348-display-public-neuron-badge
coskucinkilic Sep 25, 2024
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
@@ -1,7 +1,9 @@
<script lang="ts">
import Hash from "$lib/components/ui/Hash.svelte";
import { i18n } from "$lib/stores/i18n";
import type { TableNeuron } from "$lib/types/neurons-table";
import { Tag } from "@dfinity/gix-components";
import { Tag, IconPublicBadge, Tooltip } from "@dfinity/gix-components";
import { ENABLE_NEURON_VISIBILITY } from "$lib/stores/feature-flags.store";

export let rowData: TableNeuron;
</script>
Expand All @@ -14,6 +16,13 @@
idPrefix="neuron-id-cell"
showCopy
/>
{#if $ENABLE_NEURON_VISIBILITY && rowData.isPublic}
<span class="public-icon-container" data-tid="public-icon-container">
<Tooltip top id="neuron-id-cell-public-icon" text={$i18n.neurons.public}>
<IconPublicBadge />
</Tooltip>
</span>
{/if}
{#if rowData.tags.length > 0}
<span class="tags" data-tid="neuron-tags">
{#each rowData.tags as tag}
Expand All @@ -26,10 +35,20 @@
<style lang="scss">
.container {
line-height: 1.5;
display: flex;
align-items: center;
flex-wrap: wrap;

.public-icon-container {
color: var(--elements-badge);
line-height: 0;
margin-right: var(--padding);
mstrasinskis marked this conversation as resolved.
Show resolved Hide resolved
}
}

.tags {
display: inline-flex;
flex-wrap: wrap;
mstrasinskis marked this conversation as resolved.
Show resolved Hide resolved
gap: var(--padding);
}
</style>
3 changes: 2 additions & 1 deletion frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@
"merge_neurons_source_neuron_disappear": "The neuron <strong>$neuronId</strong> will disappear.",
"merge_neurons_more_info": "Learn more about merging neurons <a href=\"https://medium.com/dfinity/internet-computer-nns-neurons-can-now-be-merged-8b4e44584dc2\" rel=\"noopener noreferrer\" aria-label=\"more info about merging neurons\" target=\"_blank\">here</a>.",
"stake_amount": "Stake Amount",
"state": "State"
"state": "State",
"public": "Neuron is public"
},
"new_followee": {
"title": "Enter New Followee",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/types/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ interface I18nNeurons {
merge_neurons_more_info: string;
stake_amount: string;
state: string;
public: string;
}

interface I18nNew_followee {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/types/neurons-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type TableNeuron = {
dissolveDelaySeconds: bigint;
state: NeuronState;
tags: string[];
isPublic: boolean;
};

// Should define a partial ordering on TableNeuron by return -1 if a < b, +1 if
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/utils/neuron.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import {
NeuronState,
NeuronType,
NeuronVisibility,
Topic,
Vote,
ineligibleNeurons,
Expand Down Expand Up @@ -1064,3 +1065,7 @@ export const getTopicSubtitle = ({
};
return mapper[topic];
};

export const isPublicNeuron = (neuronInfo: NeuronInfo): boolean => {
return neuronInfo.visibility === NeuronVisibility.Public;
};
3 changes: 3 additions & 0 deletions frontend/src/lib/utils/neurons-table.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { UniverseCanisterIdText } from "$lib/types/universe";
import { buildNeuronUrl } from "$lib/utils/navigation.utils";
import {
getNeuronTags,
isPublicNeuron,
isSpawning,
neuronAvailableMaturity,
neuronStake,
Expand Down Expand Up @@ -69,6 +70,7 @@ export const tableNeuronsFromNeuronInfos = ({
accounts,
i18n,
}).map(({ text }) => text),
isPublic: isPublicNeuron(neuronInfo),
};
});
};
Expand Down Expand Up @@ -110,6 +112,7 @@ export const tableNeuronsFromSnsNeurons = ({
identity,
i18n,
}).map(({ text }) => text),
isPublic: false,
};
});
};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,27 @@ describe("NeuronsTable", () => {
expect(await cell2.getTags()).toEqual(tags);
expect(await cell2.hasTagsElement()).toBe(true);
});

it("should render visibility icon and tooltip for public neuron", async () => {
const po = renderComponent({
neurons: [
{
...neuron1,
isPublic: true,
},
{
...neuron2,
},
],
});

const visibilityTooltipPo = (
await po.getNeuronsTableRowPo(neuron1.neuronId)
)
.getNeuronIdCellPo()
.getPublicNeuronTooltipPo();

expect(await visibilityTooltipPo.isPresent()).toBe(true);
expect(await visibilityTooltipPo.getTooltipText()).toBe("Neuron is public");
});
});
30 changes: 30 additions & 0 deletions frontend/src/tests/lib/utils/neuron.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
isNeuronControllable,
isNeuronControllableByUser,
isNeuronControlledByHardwareWallet,
isPublicNeuron,
isSpawning,
isValidInputAmount,
mapMergeableNeurons,
Expand Down Expand Up @@ -90,6 +91,7 @@ import type { WizardStep } from "@dfinity/gix-components";
import {
NeuronState,
NeuronType,
NeuronVisibility,
Topic,
Vote,
type BallotInfo,
Expand Down Expand Up @@ -2943,4 +2945,32 @@ describe("neuron-utils", () => {
);
});
});

describe("isPublicNeuron", () => {
it("should correctly identify public neurons", () => {
const publicNeuron = {
...mockNeuron,
visibility: NeuronVisibility.Public,
};
expect(isPublicNeuron(publicNeuron)).toBe(true);
});

it("should correctly identify non-public neurons", () => {
const privateNeuron = {
...mockNeuron,
visibility: NeuronVisibility.Private,
};
const unspecifiedNeuron = {
...mockNeuron,
visibility: NeuronVisibility.Unspecified,
};
const undefinedVisibilityNeuron = {
...mockNeuron,
visibility: undefined,
};
expect(isPublicNeuron(privateNeuron)).toBe(false);
expect(isPublicNeuron(unspecifiedNeuron)).toBe(false);
expect(isPublicNeuron(undefinedVisibilityNeuron)).toBe(false);
});
});
});
2 changes: 2 additions & 0 deletions frontend/src/tests/lib/utils/neurons-table.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe("neurons-table.utils", () => {
dissolveDelaySeconds: defaultDissolveDelaySeconds,
state: NeuronState.Locked,
tags: [],
isPublic: false,
};

const convert = (neuronInfos: NeuronInfo[]) =>
Expand Down Expand Up @@ -270,6 +271,7 @@ describe("neurons-table.utils", () => {
dissolveDelaySeconds,
state: NeuronState.Locked,
tags: [],
isPublic: false,
};

const convert = (snsNeurons: SnsNeuron[]) =>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/tests/mocks/neurons.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ export const mockTableNeuron: TableNeuron = {
dissolveDelaySeconds: 1n,
state: NeuronState.Locked,
tags: [],
isPublic: undefined,
};
5 changes: 5 additions & 0 deletions frontend/src/tests/page-objects/NeuronIdCell.page-object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BasePageObject } from "$tests/page-objects/base.page-object";
import { HashPo } from "$tests/page-objects/Hash.page-object";
import type { PageObjectElement } from "$tests/types/page-object.types";
import { TooltipPo } from "./Tooltip.page-object";

export class NeuronIdCellPo extends BasePageObject {
private static readonly TID = "neuron-id-cell-component";
Expand All @@ -25,4 +26,8 @@ export class NeuronIdCellPo extends BasePageObject {
const tagElements = await this.root.allByTestId("neuron-tag");
return Promise.all(tagElements.map((el) => el.getText()));
}

getPublicNeuronTooltipPo(): TooltipPo {
return TooltipPo.under(this.root.byTestId("public-icon-container"));
}
}