Skip to content

Commit

Permalink
NNS1-3485: reporting page to show Busy component while processing req…
Browse files Browse the repository at this point in the history
…uest (#5984)

# Motivation

While downloading the report we want to avoid users from interacting
with it.
It can be tested in
[here](https://qsgjb-riaaa-aaaaa-aaaga-cai.yhabib-ingress.devenv.dfinity.network/)

# Changes

- Adds busy layover for ReportingNeurons and ReportingTransactions

# Tests

- Unit test to check that the busy functions are called

# Todos

- [ ] Add entry to changelog (if necessary).
Not necessary
  • Loading branch information
yhabib authored Dec 11, 2024
1 parent 80445c6 commit 96920de
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { queryNeurons } from "$lib/api/governance.api";
import { sortNeuronsByStake } from "$lib/utils/neuron.utils";
import { getAuthenticatedIdentity } from "$lib/services/auth.services";
import { startBusy, stopBusy } from "$lib/stores/busy.store";
let loading = false;
Expand All @@ -32,6 +33,7 @@
const exportNeurons = async () => {
try {
loading = true;
startBusy({ initiator: "reporting-neurons" });
// we are logged in to be able to interact with the button
const signIdentity = await getAuthenticatedIdentity();
Expand Down Expand Up @@ -115,6 +117,7 @@
}
} finally {
loading = false;
stopBusy("reporting-neurons");
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { queryNeurons } from "$lib/api/governance.api";
import { sortNeuronsByStake } from "$lib/utils/neuron.utils";
import { nnsAccountsListStore } from "$lib/derived/accounts-list.derived";
import { startBusy, stopBusy } from "$lib/stores/busy.store";
let identity: Identity | null | undefined;
let swapCanisterAccounts: Set<string>;
Expand Down Expand Up @@ -52,6 +53,7 @@
const exportIcpTransactions = async () => {
try {
loading = true;
startBusy({ initiator: "reporting-transactions" });
// we are logged in to be able to interact with the button
const signIdentity = identity as SignIdentity;
Expand Down Expand Up @@ -137,6 +139,7 @@
}
} finally {
loading = false;
stopBusy("reporting-transactions");
}
};
</script>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/stores/busy.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export type BusyStateInitiatorType =
| "import-token-importing"
| "import-token-removing"
| "import-token-updating"
| "change-neuron-visibility";
| "change-neuron-visibility"
| "reporting-neurons"
| "reporting-transactions";

export interface BusyState {
initiator: BusyStateInitiatorType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { mockNeuron } from "$tests/mocks/neurons.mock";
import { ReportingNeuronsButtonPo } from "$tests/page-objects/ReportingNeuronsButon.page-object";
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object";
import { runResolvedPromises } from "$tests/utils/timers.test-utils";
import { busyStore } from "@dfinity/gix-components";
import type { NeuronInfo } from "@dfinity/nns";
import { render } from "@testing-library/svelte";
import { get } from "svelte/store";

vi.mock("$lib/api/governance.api");

Expand Down Expand Up @@ -222,4 +224,22 @@ describe("ReportingNeuronsButton", () => {

expect(await po.isDisabled()).toBe(false);
});

it("should show busy page exporting", async () => {
const po = renderComponent();
expect(get(busyStore)).toEqual([]);

await po.click();

expect(get(busyStore)).toEqual([
{
initiator: "reporting-neurons",
text: undefined,
},
]);

await runResolvedPromises();

expect(get(busyStore)).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import {
setAccountsForTesting,
} from "$tests/utils/accounts.test-utils";
import { runResolvedPromises } from "$tests/utils/timers.test-utils";
import { busyStore } from "@dfinity/gix-components";
import type { NeuronInfo } from "@dfinity/nns";
import { render } from "@testing-library/svelte";
import { get } from "svelte/store";

vi.mock("$lib/api/icp-ledger.api");
vi.mock("$lib/api/governance.api");
Expand Down Expand Up @@ -293,4 +295,22 @@ describe("ReportingTransactionsButton", () => {

expect(await po.isDisabled()).toBe(false);
});

it("should show busy page while exporting", async () => {
const po = renderComponent();
expect(get(busyStore)).toEqual([]);

await po.click();

expect(get(busyStore)).toEqual([
{
initiator: "reporting-transactions",
text: undefined,
},
]);

await runResolvedPromises();

expect(get(busyStore)).toEqual([]);
});
});

0 comments on commit 96920de

Please sign in to comment.