1 import type { Maybe } from '@proton/pass/types';
3 import type { OptimisticFailedHistoryItem, WrappedOptimisticState } from '../types';
4 import { isOptimisticHistoryItemWithId } from '../utils/assertions';
6 const selectFailedAction: (
8 ) => <T extends WrappedOptimisticState = WrappedOptimisticState>(state: T) => Maybe<OptimisticFailedHistoryItem> =
9 (optimisticId) => (state) => {
10 const { optimistic } = state;
11 const { history } = optimistic;
13 const failedHistoryItemIndex = history.findIndex(isOptimisticHistoryItemWithId(optimisticId, { failed: true }));
15 return failedHistoryItemIndex !== -1
16 ? (history[failedHistoryItemIndex] as OptimisticFailedHistoryItem)
20 export default selectFailedAction;