From cb47ccb925f5586efd2cd5502be78ffb23f7b796 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 17 Jan 2019 01:22:39 -0500 Subject: [PATCH] fix: allow claiming rewards with multiple of the same type --- dist/bundle.js | 9 ++++++++- src/redux/actions/rewards.js | 6 +++++- src/redux/reducers/rewards.js | 5 ++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index c4cfb12..82e0e73 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -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); diff --git a/src/redux/actions/rewards.js b/src/redux/actions/rewards.js index db9eb45..a33b052 100644 --- a/src/redux/actions/rewards.js +++ b/src/redux/actions/rewards.js @@ -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); diff --git a/src/redux/reducers/rewards.js b/src/redux/reducers/rewards.js index 85a24cd..0d786b5 100644 --- a/src/redux/reducers/rewards.js +++ b/src/redux/reducers/rewards.js @@ -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;