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