Skip to content

Commit

Permalink
chore: remove unused selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 committed Dec 19, 2024
1 parent 71e3d6e commit 0be4ebe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
10 changes: 6 additions & 4 deletions ts/features/wallet/components/WalletCardsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { itwCredentialsEidStatusSelector } from "../../itwallet/credentials/stor
import { itwLifecycleIsValidSelector } from "../../itwallet/lifecycle/store/selectors";
import {
isWalletEmptySelector,
selectIsWalletCardsLoading,
selectIsWalletLoading,
selectWalletCardsByCategory,
selectWalletCategories,
selectWalletItwCards,
selectWalletOtherCards,
shouldRenderWalletEmptyStateSelector
} from "../store/selectors";
Expand All @@ -41,7 +41,7 @@ const EID_INFO_BOTTOM_PADDING = 128;
* and the empty state
*/
const WalletCardsContainer = () => {
const isLoading = useIOSelector(selectIsWalletCardsLoading);
const isLoading = useIOSelector(selectIsWalletLoading);
const isWalletEmpty = useIOSelector(isWalletEmptySelector);
const shouldRenderEmptyState = useIOSelector(
shouldRenderWalletEmptyStateSelector
Expand Down Expand Up @@ -94,7 +94,9 @@ const WalletCardsContainerSkeleton = () => (
*/
const ItwWalletCardsContainer = withWalletCategoryFilter("itw", () => {
const navigation = useIONavigation();
const cards = useIOSelector(selectWalletItwCards);
const cards = useIOSelector(state =>
selectWalletCardsByCategory(state, "itw")
);
const isItwValid = useIOSelector(itwLifecycleIsValidSelector);
const isItwEnabled = useIOSelector(isItwEnabledSelector);
const eidStatus = useIOSelector(itwCredentialsEidStatusSelector);
Expand Down
4 changes: 2 additions & 2 deletions ts/features/wallet/saga/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { walletUpdate } from "../store/actions";
import { walletAddCards } from "../store/actions/cards";
import { walletToggleLoadingState } from "../store/actions/placeholders";
import { selectWalletPlaceholders } from "../store/selectors";
import { selectWalletPlaceholderCards } from "../store/selectors";
import { handleWalletAnalyticsSaga } from "./handleWalletAnalyticsSaga";
import { handleWalletPlaceholdersTimeout } from "./handleWalletLoadingPlaceholdersTimeout";
import { handleWalletLoadingStateSaga } from "./handleWalletLoadingStateSaga";
Expand All @@ -21,7 +21,7 @@ const LOADING_STATE_TIMEOUT = 2000 as Millisecond;
export function* watchWalletSaga(): SagaIterator {
// Adds persisted placeholders as cards in the wallet
// to be displayed while waiting for the actual cards
const placeholders = yield* select(selectWalletPlaceholders);
const placeholders = yield* select(selectWalletPlaceholderCards);
yield* put(walletAddCards(placeholders));

yield* takeLatest(
Expand Down
40 changes: 16 additions & 24 deletions ts/features/wallet/store/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import {
} from "../../types";
import { WalletCardCategoryFilter } from "../../types/index";

const selectWalletFeature = (state: GlobalState) => state.features.wallet;

/**
* Returns the list of cards excluding hidden cards
*/
export const selectWalletCards = createSelector(
selectWalletFeature,
(state: GlobalState) => state.features.wallet,
({ cards }) => Object.values(cards).filter(({ hidden }) => !hidden)
);

Expand Down Expand Up @@ -63,22 +61,6 @@ export const selectSortedWalletCards = createSelector(
)
);

/**
* Only gets cards which are part of the IT Wallet
*/
export const selectWalletItwCards = createSelector(
selectSortedWalletCards,
cards => cards.filter(({ category }) => category === "itw")
);

/**
* Only gets cards which are not part of the IT Wallet
*/
export const selectWalletOtherCards = createSelector(
selectSortedWalletCards,
cards => cards.filter(({ category }) => category !== "itw")
);

/**
* Selects the cards by their category
* @param category - The category of the cards to select
Expand All @@ -100,17 +82,26 @@ export const selectWalletCardsByType = createSelector(
(cards, type) => cards.filter(({ type: cardType }) => cardType === type)
);

/**
* Currently, if a card is not part of the IT Wallet, it is considered as "other"
* This selector returns the cards which are not part of the IT Wallet which must be displayed in the "other" section
*/
export const selectWalletOtherCards = createSelector(
selectSortedWalletCards,
cards => cards.filter(({ category }) => category !== "itw")
);

/**
* Selects the loading state of the wallet cards
*/
export const selectIsWalletCardsLoading = (state: GlobalState) =>
export const selectIsWalletLoading = (state: GlobalState) =>
state.features.wallet.placeholders.isLoading;

/**
* Selects the placeholders from the wallet
*/
export const selectWalletPlaceholders = createSelector(
selectWalletFeature,
export const selectWalletPlaceholderCards = createSelector(
(state: GlobalState) => state.features.wallet,
wallet =>
Object.entries(wallet.placeholders.items).map(
([key, category]) =>
Expand All @@ -120,8 +111,9 @@ export const selectWalletPlaceholders = createSelector(

/**
* Gets if the wallet can be considered empty.
* The wallet is empty if there are no categories to display
* @see selectWalletCategories
* The wallet is empty if there are no categories to display (@see selectWalletCategories)
*
* Note: we check categories because if ITW is valid, it is considered as one category even if there are no cards
*/
export const isWalletEmptySelector = (state: GlobalState) =>
selectWalletCategories(state).size === 0;
Expand Down

0 comments on commit 0be4ebe

Please sign in to comment.