-
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.
NNS1-3504: Split actionable-proposals.derived.ts (#6127)
# Motivation We want to sort the selectable universes based on their number of actionable proposals. For this `selectable-universes.derived.ts` needs to depend on `actionableProposalCountStore` from `actionable-proposals.derived.ts`. But this causes a circular dependency because of other derived stores in `actionable-proposals.derived.ts` which already depend on `selectable-universes.derived.ts`. # Changes 1. Move the derived stores in `actionable-proposals.derived.ts` that depend on `selectable-universes.derived.ts` to a new file named `actionable-universes.derived.ts`. 2. Update imports. # Tests 1. Move tests for the moved stores to a corresponding test file. # Todos - [ ] Add entry to changelog (if necessary). not necessary
- Loading branch information
Showing
7 changed files
with
201 additions
and
186 deletions.
There are no files selected for viewing
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
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,58 @@ | ||
import { OWN_CANISTER_ID_TEXT } from "$lib/constants/canister-ids.constants"; | ||
import { actionableNnsProposalsStore } from "$lib/stores/actionable-nns-proposals.store"; | ||
import { actionableSnsProposalsStore } from "$lib/stores/actionable-sns-proposals.store"; | ||
import type { ProposalsNavigationId } from "$lib/types/proposals"; | ||
import type { Universe } from "$lib/types/universe"; | ||
import type { SnsProposalData } from "@dfinity/sns"; | ||
import { fromDefinedNullable, nonNullish } from "@dfinity/utils"; | ||
import { derived, type Readable } from "svelte/store"; | ||
|
||
import { selectableUniversesStore } from "$lib/derived/selectable-universes.derived"; | ||
|
||
export interface ActionableSnsProposalsByUniverseData { | ||
universe: Universe; | ||
proposals: SnsProposalData[]; | ||
} | ||
|
||
/** A store that contains sns universes with actionable support and their actionable proposals | ||
* in the same order as they are displayed in the UI. */ | ||
export const actionableSnsProposalsByUniverseStore: Readable< | ||
Array<ActionableSnsProposalsByUniverseData> | ||
> = derived( | ||
[selectableUniversesStore, actionableSnsProposalsStore], | ||
([universes, actionableSnsProposals]) => | ||
universes | ||
.filter(({ canisterId }) => | ||
nonNullish(actionableSnsProposals[canisterId]) | ||
) | ||
.map((universe) => ({ | ||
universe, | ||
proposals: actionableSnsProposals[universe.canisterId].proposals, | ||
})) | ||
); | ||
|
||
// Generate list of ProposalsNavigationId using universes to provide correct order | ||
// of proposals in the UI. | ||
export const actionableProposalsNavigationIdsStore: Readable< | ||
Array<ProposalsNavigationId> | ||
> = derived( | ||
[ | ||
selectableUniversesStore, | ||
actionableNnsProposalsStore, | ||
actionableSnsProposalsStore, | ||
], | ||
([universes, nnsProposals, actionableSnsProposals]) => | ||
universes | ||
.map(({ canisterId }) => | ||
canisterId === OWN_CANISTER_ID_TEXT | ||
? (nnsProposals.proposals ?? []).map(({ id }) => ({ | ||
universe: OWN_CANISTER_ID_TEXT, | ||
proposalId: id as bigint, | ||
})) | ||
: (actionableSnsProposals[canisterId]?.proposals ?? []).map((aa) => ({ | ||
universe: canisterId, | ||
proposalId: fromDefinedNullable(aa.id).id, | ||
})) | ||
) | ||
.flatMap((ids) => (nonNullish(ids) ? ids : [])) | ||
); |
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
Oops, something went wrong.