-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ledger neuron hotkey warning (#6061)
# Motivation To prevent missing rewards for ledger neurons, we display a warning on the HW wallet page. # Changes - Add `LedgerNeuronHotkeyWarning` component. - Display `LedgerNeuronHotkeyWarning` . # Tests - Added. - Tested locally that the banner is closable. <img width="744" alt="image" src="https://github.com/user-attachments/assets/51b6fec2-3c57-4040-88d4-a07e4d190fbf" /> # Todos - [ ] Add entry to changelog (if necessary). Not necessary.
- Loading branch information
1 parent
37cc835
commit 8e54925
Showing
8 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
frontend/src/lib/components/accounts/LedgerNeuronHotkeyWarning.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts"> | ||
import { browser } from "$app/environment"; | ||
import { i18n } from "$lib/stores/i18n"; | ||
import { IconInfo } from "@dfinity/gix-components"; | ||
import Banner from "../ui/Banner.svelte"; | ||
import BannerIcon from "../ui/BannerIcon.svelte"; | ||
import TestIdWrapper from "../common/TestIdWrapper.svelte"; | ||
const LOCAL_STORAGE_KEY = "isLedgerNeuronHotkeyWarningDisabled"; | ||
let isDismissed = browser | ||
? Boolean(JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY) ?? "false")) | ||
: false; | ||
let isVisible = false; | ||
$: isVisible = !isDismissed; | ||
function dismissBanner() { | ||
isDismissed = true; | ||
localStorage.setItem(LOCAL_STORAGE_KEY, "true"); | ||
} | ||
</script> | ||
|
||
<TestIdWrapper testId="ledger-neuron-hotkey-warning-component"> | ||
{#if isVisible} | ||
<Banner | ||
isClosable | ||
on:nnsClose={dismissBanner} | ||
htmlText={$i18n.losing_rewards.hw_hotkey_warning} | ||
> | ||
<BannerIcon slot="icon"> | ||
<IconInfo /> | ||
</BannerIcon> | ||
</Banner> | ||
{/if} | ||
</TestIdWrapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
frontend/src/tests/lib/components/accounts/LedgerNeuronHotkeyWarning.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import LedgerNeuronHotkeyWarning from "$lib/components/accounts/LedgerNeuronHotkeyWarning.svelte"; | ||
import { LedgerNeuronHotkeyWarningPo } from "$tests/page-objects/LedgerNeuronHotkeyWarning.page-object"; | ||
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object"; | ||
import { render } from "@testing-library/svelte"; | ||
|
||
describe("LedgerNeuronHotkeyWarning", () => { | ||
const localStorageKey = "isLedgerNeuronHotkeyWarningDisabled"; | ||
const renderComponent = () => { | ||
const { container } = render(LedgerNeuronHotkeyWarning); | ||
return LedgerNeuronHotkeyWarningPo.under( | ||
new JestPageObjectElement(container) | ||
); | ||
}; | ||
|
||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
it("should be shown when localStorageKey not set", async () => { | ||
const po = await renderComponent(); | ||
expect(localStorage.getItem(localStorageKey)).toBeNull(); | ||
|
||
expect(await po.isBannerVisible()).toBe(true); | ||
}); | ||
|
||
it("should not render when localStorageKey is set to true", async () => { | ||
localStorage.setItem(localStorageKey, "true"); | ||
const po = await renderComponent(); | ||
|
||
expect(await po.isBannerVisible()).toBe(false); | ||
}); | ||
|
||
it("should be closable", async () => { | ||
const po = await renderComponent(); | ||
|
||
expect(await po.isBannerVisible()).toBe(true); | ||
expect(localStorage.getItem(localStorageKey)).toBeNull(); | ||
|
||
await po.getBannerPo().clickClose(); | ||
|
||
expect(await po.isBannerVisible()).toBe(false); | ||
expect(localStorage.getItem(localStorageKey)).toEqual("true"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
frontend/src/tests/page-objects/LedgerNeuronHotkeyWarning.page-object.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { BasePageObject } from "$tests/page-objects/base.page-object"; | ||
import type { PageObjectElement } from "$tests/types/page-object.types"; | ||
import { BannerPo } from "./Banner.page-object"; | ||
|
||
export class LedgerNeuronHotkeyWarningPo extends BasePageObject { | ||
private static readonly TID = "ledger-neuron-hotkey-warning-component"; | ||
|
||
static under(element: PageObjectElement): LedgerNeuronHotkeyWarningPo { | ||
return new LedgerNeuronHotkeyWarningPo( | ||
element.byTestId(LedgerNeuronHotkeyWarningPo.TID) | ||
); | ||
} | ||
|
||
getBannerPo(): BannerPo { | ||
return BannerPo.under(this.root); | ||
} | ||
|
||
async isBannerVisible(): Promise<boolean> { | ||
return this.getBannerPo().isPresent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters