Merge pull request #22 from lbryio/rewards-fix

fix: allow claiming rewards with multiple of the same type
This commit is contained in:
Sean Yesmunt 2019-01-18 11:26:40 -05:00 committed by GitHub
commit 83c275da7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

15
dist/bundle.js vendored
View file

@ -8009,6 +8009,10 @@ function doClaimRewardType(rewardType) {
return;
}
// Set `claim_code` so the api knows which reward to give if there are multiple of the same type
var params = options.params || {};
params.claim_code = reward.claim_code;
dispatch({
type: _lbryRedux.ACTIONS.CLAIM_REWARD_STARTED,
data: { reward: reward }
@ -8036,9 +8040,13 @@ 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);
_rewards3.default.claimReward(rewardType, params).then(success, failure);
};
}
@ -9075,6 +9083,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 +9116,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';
@ -51,6 +51,10 @@ export function doClaimRewardType(rewardType, options = {}) {
return;
}
// Set `claim_code` so the api knows which reward to give if there are multiple of the same type
const params = options.params || {};
params.claim_code = reward.claim_code;
dispatch({
type: ACTIONS.CLAIM_REWARD_STARTED,
data: { reward },
@ -81,9 +85,13 @@ 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);
rewards.claimReward(rewardType, 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;