Skip to content

Commit

Permalink
remove createIsActionableProposalStore
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrasinskis committed Mar 26, 2024
1 parent 5865a30 commit dff58ed
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 112 deletions.
34 changes: 0 additions & 34 deletions frontend/src/lib/derived/actionable-proposals.derived.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import { OWN_CANISTER_ID_TEXT } from "$lib/constants/canister-ids.constants";
import { AppPath } from "$lib/constants/routes.constants";
import { authSignedInStore } from "$lib/derived/auth.derived";
import { pageStore } from "$lib/derived/page.derived";
import { selectedUniverseIdStore } from "$lib/derived/selected-universe.derived";
import { actionableNnsProposalsStore } from "$lib/stores/actionable-nns-proposals.store";
import { actionableSnsProposalsStore } from "$lib/stores/actionable-sns-proposals.store";
import { isSelectedPath } from "$lib/utils/navigation.utils";
import { snsProposalId } from "$lib/utils/sns-proposals.utils";
import { isUniverseNns } from "$lib/utils/universe.utils";
import { mapEntries } from "$lib/utils/utils";
import { isNullish } from "@dfinity/utils";
import { derived, type Readable } from "svelte/store";

export interface ActionableProposalCountData {
Expand Down Expand Up @@ -62,33 +58,3 @@ export const actionableProposalSupportedStore: Readable<ActionableProposalSuppor
],
}),
}));

/**
* Returns a derived store based on the proposal id and currently selected universe.
* It contains `true` if the proposal is actionable,
* `false` - not actionable,
* and `undefined` when this information is not available.
*
* @param proposalId The proposal id to check. Can be undefined for more flexible usage.
*/
export const createIsActionableProposalStore = (
proposalId: bigint | undefined
) =>
derived(
[
selectedUniverseIdStore,
actionableNnsProposalsStore,
actionableSnsProposalsStore,
],
([selectedUniverseId, actionableNnsProposals, actionableSnsProposals]) =>
isNullish(proposalId)
? // undefined proposalId
undefined
: isUniverseNns(selectedUniverseId)
? // nns proposalId
actionableNnsProposals.proposals?.some(({ id }) => id === proposalId)
: // sns proposalId
actionableSnsProposals[selectedUniverseId.toText()]?.proposals?.some(
(proposal) => snsProposalId(proposal) === proposalId
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ import {
actionableProposalCountStore,
actionableProposalIndicationEnabledStore,
actionableProposalSupportedStore,
createIsActionableProposalStore,
} from "$lib/derived/actionable-proposals.derived";
import { actionableNnsProposalsStore } from "$lib/stores/actionable-nns-proposals.store";
import { actionableSnsProposalsStore } from "$lib/stores/actionable-sns-proposals.store";
import { page } from "$mocks/$app/stores";
import { resetIdentity, setNoIdentity } from "$tests/mocks/auth.store.mock";
import { mockProposalInfo } from "$tests/mocks/proposal.mock";
import { principal } from "$tests/mocks/sns-projects.mock";
import {
createSnsProposal,
mockSnsProposal,
} from "$tests/mocks/sns-proposals.mock";
import { mockSnsCanisterIdText } from "$tests/mocks/sns.api.mock";
import { mockSnsProposal } from "$tests/mocks/sns-proposals.mock";
import type { ProposalInfo } from "@dfinity/nns";
import { Principal } from "@dfinity/principal";
import { SnsProposalDecisionStatus } from "@dfinity/sns";
import { get } from "svelte/store";

describe("actionable proposals derived stores", () => {
Expand Down Expand Up @@ -155,74 +148,4 @@ describe("actionable proposals derived stores", () => {
});
});
});

describe("createIsActionableProposalStore", () => {
const nnsProposal0: ProposalInfo = {
...mockProposalInfo,
id: 0n,
};
const nnsProposal1: ProposalInfo = {
...mockProposalInfo,
id: 1n,
};
const snsProposal0 = createSnsProposal({
proposalId: 0n,
status: SnsProposalDecisionStatus.PROPOSAL_DECISION_STATUS_OPEN,
});
const snsProposal1 = createSnsProposal({
proposalId: 1n,
status: SnsProposalDecisionStatus.PROPOSAL_DECISION_STATUS_OPEN,
});

beforeEach(() => {
page.reset();
actionableNnsProposalsStore.reset();
actionableSnsProposalsStore.resetForTesting();
});

it("returns actionable state for nns proposal", async () => {
const isActionableProposalStore = createIsActionableProposalStore(1n);
// no nns proposals
expect(get(isActionableProposalStore)).toBe(undefined);

actionableNnsProposalsStore.setProposals([nnsProposal0]);
expect(get(isActionableProposalStore)).toBe(false);

actionableNnsProposalsStore.setProposals([nnsProposal0, nnsProposal1]);
expect(get(isActionableProposalStore)).toBe(true);

// selected project contains no data
page.mock({ data: { universe: mockSnsCanisterIdText } });
expect(get(isActionableProposalStore)).toBe(undefined);
});

it("returns actionable state for sns proposal", async () => {
const isActionableProposalStore = createIsActionableProposalStore(1n);
expect(get(isActionableProposalStore)).toBe(undefined);

actionableSnsProposalsStore.set({
rootCanisterId: Principal.fromText(mockSnsCanisterIdText),
proposals: [snsProposal0, snsProposal1],
includeBallotsByCaller: true,
});
// selected project contains no data
expect(get(isActionableProposalStore)).toBe(undefined);

page.mock({ data: { universe: mockSnsCanisterIdText } });
expect(get(isActionableProposalStore)).toBe(true);

actionableSnsProposalsStore.set({
rootCanisterId: Principal.fromText(mockSnsCanisterIdText),
proposals: [snsProposal0],
includeBallotsByCaller: true,
});
expect(get(isActionableProposalStore)).toBe(false);
});

it("returns undefined when proposal id equals undefined", async () => {
const isActionableProposalStore =
createIsActionableProposalStore(undefined);
expect(get(isActionableProposalStore)).toBe(undefined);
});
});
});

0 comments on commit dff58ed

Please sign in to comment.