fix merge conflicts

This commit is contained in:
Akinwale Ariwodola 2019-02-15 09:55:24 +01:00
commit 7f690b89ac
7 changed files with 623 additions and 510 deletions

1061
dist/bundle.js vendored

File diff suppressed because it is too large Load diff

View file

@ -42,6 +42,7 @@ export {
doAuthenticate, doAuthenticate,
doUserFetch, doUserFetch,
doUserEmailNew, doUserEmailNew,
doUserCheckEmailVerified,
doUserEmailToVerify, doUserEmailToVerify,
doUserEmailVerifyFailure, doUserEmailVerifyFailure,
doUserEmailVerify, doUserEmailVerify,
@ -81,6 +82,7 @@ export {
selectClaimRewardError, selectClaimRewardError,
selectRewardByType, selectRewardByType,
selectRewardContentClaimIds, selectRewardContentClaimIds,
selectReferralReward,
} from 'redux/selectors/rewards'; } from 'redux/selectors/rewards';
export { export {
makeSelectIsNew, makeSelectIsNew,

View file

@ -115,12 +115,12 @@ Lbryio.authenticate = () => {
// check that token works // check that token works
return Lbryio.getCurrentUser() return Lbryio.getCurrentUser()
.then(() => true) .then(user => user)
.catch(() => false); .catch(() => false);
}) })
.then(isTokenValid => { .then(user => {
if (isTokenValid) { if (user) {
return reject; return user;
} }
return Lbry.status().then(status => { return Lbry.status().then(status => {
@ -137,7 +137,12 @@ Lbryio.authenticate = () => {
return reject(); return reject();
}); });
}) })
.then(Lbryio.getCurrentUser) .then(user => {
if (!user) {
return Lbryio.getCurrentUser();
}
return user;
})
.then(resolve, reject); .then(resolve, reject);
}); });
} }

View file

@ -1,7 +1,8 @@
import Lbryio from 'lbryio'; import Lbryio from 'lbryio';
import { ACTIONS } from 'lbry-redux'; import { ACTIONS, doToast } from 'lbry-redux';
import { selectUnclaimedRewards } from 'redux/selectors/rewards'; import { selectUnclaimedRewards } from 'redux/selectors/rewards';
import { selectUserIsRewardApproved } from 'redux/selectors/user'; import { selectUserIsRewardApproved } from 'redux/selectors/user';
import { doFetchInviteStatus } from 'redux/actions/user';
import rewards from 'rewards'; import rewards from 'rewards';
export function doRewardList() { export function doRewardList() {
@ -51,6 +52,10 @@ export function doClaimRewardType(rewardType, options = {}) {
return; 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({ dispatch({
type: ACTIONS.CLAIM_REWARD_STARTED, type: ACTIONS.CLAIM_REWARD_STARTED,
data: { reward }, data: { reward },
@ -68,6 +73,8 @@ export function doClaimRewardType(rewardType, options = {}) {
rewards.callbacks.claimFirstRewardSuccess rewards.callbacks.claimFirstRewardSuccess
) { ) {
rewards.callbacks.claimFirstRewardSuccess(); rewards.callbacks.claimFirstRewardSuccess();
} else if (successReward.reward_type === rewards.TYPE_REFERRAL) {
dispatch(doFetchInviteStatus());
} }
dispatch(doRewardList()); dispatch(doRewardList());
@ -81,9 +88,13 @@ export function doClaimRewardType(rewardType, options = {}) {
error: !options || !options.failSilently ? error : undefined, error: !options || !options.failSilently ? error : undefined,
}, },
}); });
if (options.notifyError) {
dispatch(doToast({ message: error.message, isError: true }));
}
}; };
rewards.claimReward(rewardType, options.params).then(success, failure); rewards.claimReward(rewardType, params).then(success, failure);
}; };
} }

View file

@ -16,6 +16,8 @@ export function doFetchInviteStatus() {
Lbryio.call('user', 'invite_status') Lbryio.call('user', 'invite_status')
.then(status => { .then(status => {
dispatch(doRewardList());
dispatch({ dispatch({
type: ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS, type: ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS,
data: { data: {
@ -98,6 +100,22 @@ export function doUserFetch() {
}; };
} }
export function doUserCheckEmailVerified() {
// This will happen in the background so we don't need loading booleans
return dispatch => {
Lbryio.getCurrentUser().then(user => {
if (user.has_verified_email) {
dispatch(doRewardList());
dispatch({
type: ACTIONS.USER_FETCH_SUCCESS,
data: { user },
});
}
});
};
}
export function doUserPhoneReset() { export function doUserPhoneReset() {
return { return {
type: ACTIONS.USER_PHONE_RESET, type: ACTIONS.USER_PHONE_RESET,

View file

@ -38,6 +38,9 @@ reducers[ACTIONS.FETCH_REWARDS_COMPLETED] = (state, action) => {
function setClaimRewardState(state, reward, isClaiming, errorMessage = '') { function setClaimRewardState(state, reward, isClaiming, errorMessage = '') {
const newClaimPendingByType = Object.assign({}, state.claimPendingByType); const newClaimPendingByType = Object.assign({}, state.claimPendingByType);
const newClaimErrorsByType = Object.assign({}, state.claimErrorsByType); 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) { if (isClaiming) {
newClaimPendingByType[reward.reward_type] = isClaiming; newClaimPendingByType[reward.reward_type] = isClaiming;
} else { } else {
@ -65,7 +68,7 @@ reducers[ACTIONS.CLAIM_REWARD_SUCCESS] = (state, action) => {
const { reward } = action.data; const { reward } = action.data;
const { unclaimedRewards } = state; 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); unclaimedRewards.splice(index, 1);
const { claimedRewardsById } = state; const { claimedRewardsById } = state;

View file

@ -1,4 +1,5 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import REWARDS from 'rewards';
const selectState = state => state.rewards || {}; const selectState = state => state.rewards || {};
@ -67,3 +68,9 @@ export const selectRewardContentClaimIds = createSelector(
selectState, selectState,
state => state.rewardedContentClaimIds state => state.rewardedContentClaimIds
); );
export const selectReferralReward = createSelector(
selectUnclaimedRewards,
unclaimedRewards =>
unclaimedRewards.filter(reward => reward.reward_type === REWARDS.TYPE_REFERRAL)[0]
);