lbry-desktop/src/renderer/redux/selectors/rewards.js

65 lines
2 KiB
JavaScript
Raw Normal View History

import { createSelector } from 'reselect';
const selectState = state => state.rewards || {};
2017-05-26 10:53:32 +02:00
export const selectUnclaimedRewardsByType = createSelector(
selectState,
state => state.unclaimedRewardsByType
2017-06-08 02:56:52 +02:00
);
2017-05-26 10:53:32 +02:00
export const selectClaimedRewardsById = createSelector(
selectState,
state => state.claimedRewardsById
);
export const selectClaimedRewards = createSelector(
selectClaimedRewardsById,
byId => Object.values(byId) || []
);
export const selectClaimedRewardsByTransactionId = createSelector(selectClaimedRewards, rewards =>
rewards.reduce((mapParam, reward) => {
const map = mapParam;
map[reward.transaction_id] = reward;
return map;
}, {})
);
export const selectUnclaimedRewards = createSelector(selectState, state => state.unclaimedRewards);
2017-05-26 10:53:32 +02:00
export const selectFetchingRewards = createSelector(selectState, state => !!state.fetching);
2017-05-26 10:53:32 +02:00
export const selectUnclaimedRewardValue = createSelector(selectUnclaimedRewards, rewards =>
rewards.reduce((sum, reward) => sum + reward.reward_amount, 0)
2017-07-28 03:13:12 +02:00
);
export const selectClaimsPendingByType = createSelector(
selectState,
2017-06-08 02:56:52 +02:00
state => state.claimPendingByType
);
2017-12-13 22:36:30 +01:00
const selectIsClaimRewardPending = (state, props) =>
selectClaimsPendingByType(state, props)[props.reward_type];
2017-12-13 22:36:30 +01:00
export const makeSelectIsRewardClaimPending = () =>
createSelector(selectIsClaimRewardPending, isClaiming => isClaiming);
export const selectClaimErrorsByType = createSelector(
selectState,
2017-06-08 02:56:52 +02:00
state => state.claimErrorsByType
);
2017-12-13 22:36:30 +01:00
const selectClaimRewardError = (state, props) =>
selectClaimErrorsByType(state, props)[props.reward_type];
2017-12-13 22:36:30 +01:00
export const makeSelectClaimRewardError = () =>
createSelector(selectClaimRewardError, errorMessage => errorMessage);
const selectRewardByType = (state, rewardType) =>
selectUnclaimedRewards(state).find(reward => reward.reward_type === rewardType);
2017-05-26 10:53:32 +02:00
export const makeSelectRewardByType = () => createSelector(selectRewardByType, reward => reward);
2017-08-26 05:21:26 +02:00
2017-12-13 22:36:30 +01:00
export const makeSelectRewardAmountByType = () =>
createSelector(selectRewardByType, reward => (reward ? reward.reward_amount : 0));