2017-06-06 23:19:12 +02:00
|
|
|
import { createSelector } from "reselect";
|
2017-06-02 02:51:52 +02:00
|
|
|
import { selectUser } from "selectors/user";
|
2017-04-24 09:25:27 +02:00
|
|
|
|
2017-05-26 10:53:32 +02:00
|
|
|
const _selectState = state => state.rewards || {};
|
|
|
|
|
|
|
|
export const selectRewardsByType = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 23:15:34 +02:00
|
|
|
state => state.rewardsByType || {}
|
2017-06-08 02:56:52 +02:00
|
|
|
);
|
2017-05-26 10:53:32 +02:00
|
|
|
|
|
|
|
export const selectRewards = createSelector(
|
|
|
|
selectRewardsByType,
|
2017-06-08 02:56:52 +02:00
|
|
|
byType => Object.values(byType) || []
|
|
|
|
);
|
2017-05-26 10:53:32 +02:00
|
|
|
|
2017-06-02 02:51:52 +02:00
|
|
|
export const selectIsRewardEligible = createSelector(
|
|
|
|
selectUser,
|
2017-06-08 02:56:52 +02:00
|
|
|
user => user.can_claim_rewards
|
|
|
|
);
|
2017-06-02 02:51:52 +02:00
|
|
|
|
2017-05-26 10:53:32 +02:00
|
|
|
export const selectFetchingRewards = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => !!state.fetching
|
|
|
|
);
|
2017-05-26 10:53:32 +02:00
|
|
|
|
|
|
|
export const selectHasClaimedReward = (state, props) => {
|
2017-06-08 23:15:34 +02:00
|
|
|
const reward = selectRewardsByType(state)[props.reward_type];
|
|
|
|
return reward && reward.transaction_id !== "";
|
2017-06-08 02:56:52 +02:00
|
|
|
};
|
2017-05-26 10:53:32 +02:00
|
|
|
|
|
|
|
export const makeSelectHasClaimedReward = () => {
|
2017-06-08 02:56:52 +02:00
|
|
|
return createSelector(selectHasClaimedReward, claimed => claimed);
|
|
|
|
};
|
2017-05-26 10:53:32 +02:00
|
|
|
|
2017-06-02 02:51:52 +02:00
|
|
|
export const selectClaimsPendingByType = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.claimPendingByType
|
|
|
|
);
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
const selectIsClaimRewardPending = (state, props) => {
|
2017-06-08 02:56:52 +02:00
|
|
|
return selectClaimsPendingByType(state, props)[props.reward_type];
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
export const makeSelectIsRewardClaimPending = () => {
|
2017-06-08 02:56:52 +02:00
|
|
|
return createSelector(selectIsClaimRewardPending, isClaiming => isClaiming);
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
export const selectClaimErrorsByType = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.claimErrorsByType
|
|
|
|
);
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
const selectClaimRewardError = (state, props) => {
|
2017-06-08 02:56:52 +02:00
|
|
|
return selectClaimErrorsByType(state, props)[props.reward_type];
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
export const makeSelectClaimRewardError = () => {
|
2017-06-08 02:56:52 +02:00
|
|
|
return createSelector(selectClaimRewardError, errorMessage => errorMessage);
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
2017-05-26 10:53:32 +02:00
|
|
|
const selectRewardByType = (state, props) => {
|
2017-06-08 02:56:52 +02:00
|
|
|
return selectRewardsByType(state)[props.reward_type];
|
|
|
|
};
|
2017-05-26 10:53:32 +02:00
|
|
|
|
|
|
|
export const makeSelectRewardByType = () => {
|
2017-06-08 02:56:52 +02:00
|
|
|
return createSelector(selectRewardByType, reward => reward);
|
|
|
|
};
|