fix: allow claiming rewards with multiple of the same type #22

Merged
neb-b merged 2 commits from rewards-fix into master 2019-01-18 17:26:41 +01:00
3 changed files with 17 additions and 3 deletions
Showing only changes of commit cb47ccb925 - Show all commits

9
dist/bundle.js vendored
View file

@ -8036,6 +8036,10 @@ function doClaimRewardType(rewardType) {
error: !options || !options.failSilently ? error : undefined
}
});
if (options.notifyError) {
dispatch((0, _lbryRedux.doError)(error.message));
}
};
_rewards3.default.claimReward(rewardType, options.params).then(success, failure);
@ -9075,6 +9079,9 @@ function setClaimRewardState(state, reward, isClaiming) {
var newClaimPendingByType = Object.assign({}, state.claimPendingByType);
var newClaimErrorsByType = Object.assign({}, state.claimErrorsByType);
// Currently, for multiple rewards of the same type, they will both show "claiming" when one is beacuse we track this by `reward_type`
// To fix this we will need to use `claim_code` instead, and change all selectors to match
if (isClaiming) {
newClaimPendingByType[reward.reward_type] = isClaiming;
} else {
@ -9105,7 +9112,7 @@ reducers[_lbryRedux.ACTIONS.CLAIM_REWARD_SUCCESS] = function (state, action) {
var index = unclaimedRewards.findIndex(function (ur) {
return ur.reward_type === reward.reward_type;
return ur.claim_code === reward.claim_code;
});
unclaimedRewards.splice(index, 1);

View file

@ -1,5 +1,5 @@
import Lbryio from 'lbryio';
import { ACTIONS } from 'lbry-redux';
import { ACTIONS, doError } from 'lbry-redux';
import { selectUnclaimedRewards } from 'redux/selectors/rewards';
import { selectUserIsRewardApproved } from 'redux/selectors/user';
import rewards from 'rewards';
@ -81,6 +81,10 @@ export function doClaimRewardType(rewardType, options = {}) {
error: !options || !options.failSilently ? error : undefined,
},
});
if (options.notifyError) {
dispatch(doError(error.message));
}
};
rewards.claimReward(rewardType, options.params).then(success, failure);

View file

@ -38,6 +38,9 @@ reducers[ACTIONS.FETCH_REWARDS_COMPLETED] = (state, action) => {
function setClaimRewardState(state, reward, isClaiming, errorMessage = '') {
const newClaimPendingByType = Object.assign({}, state.claimPendingByType);
const newClaimErrorsByType = Object.assign({}, state.claimErrorsByType);
// Currently, for multiple rewards of the same type, they will both show "claiming" when one is beacuse we track this by `reward_type`
// To fix this we will need to use `claim_code` instead, and change all selectors to match
if (isClaiming) {
newClaimPendingByType[reward.reward_type] = isClaiming;
} else {
@ -65,7 +68,7 @@ reducers[ACTIONS.CLAIM_REWARD_SUCCESS] = (state, action) => {
const { reward } = action.data;
const { unclaimedRewards } = state;
const index = unclaimedRewards.findIndex(ur => ur.reward_type === reward.reward_type);
const index = unclaimedRewards.findIndex(ur => ur.claim_code === reward.claim_code);
unclaimedRewards.splice(index, 1);
const { claimedRewardsById } = state;