referral improvements:
resolve canonical urls before claiming some error handling bugfixes
This commit is contained in:
parent
81dd94572d
commit
54ca3fa8a7
7 changed files with 561 additions and 394 deletions
62
dist/bundle.es.js
vendored
62
dist/bundle.es.js
vendored
|
@ -269,6 +269,14 @@ var youtube = /*#__PURE__*/Object.freeze({
|
|||
COMPLETED_TRANSFER: COMPLETED_TRANSFER
|
||||
});
|
||||
|
||||
const ALREADY_CLAIMED = 'once the invite reward has been claimed the referrer cannot be changed';
|
||||
const REFERRER_NOT_FOUND = 'A lbry.tv account could not be found for the referrer you provided.';
|
||||
|
||||
var errors = /*#__PURE__*/Object.freeze({
|
||||
ALREADY_CLAIMED: ALREADY_CLAIMED,
|
||||
REFERRER_NOT_FOUND: REFERRER_NOT_FOUND
|
||||
});
|
||||
|
||||
const Lbryio = {
|
||||
enabled: true,
|
||||
authenticationPromise: null,
|
||||
|
@ -624,7 +632,11 @@ var subscriptions = handleActions({
|
|||
[CHANNEL_SUBSCRIBE]: (state, action) => {
|
||||
const newSubscription = action.data;
|
||||
const newSubscriptions = state.subscriptions.slice();
|
||||
newSubscriptions.unshift(newSubscription);
|
||||
|
||||
if (!newSubscriptions.some(sub => sub.uri === newSubscription.uri)) {
|
||||
newSubscriptions.unshift(newSubscription);
|
||||
}
|
||||
|
||||
return { ...state,
|
||||
subscriptions: newSubscriptions
|
||||
};
|
||||
|
@ -1221,7 +1233,7 @@ const selectUserInviteStatusFailed = reselect.createSelector(selectUserInvitesRe
|
|||
const selectUserInviteNewIsPending = reselect.createSelector(selectState$2, state => state.inviteNewIsPending);
|
||||
const selectUserInviteNewErrorMessage = reselect.createSelector(selectState$2, state => state.inviteNewErrorMessage);
|
||||
const selectUserInviteReferralLink = reselect.createSelector(selectState$2, state => state.referralLink);
|
||||
const selectUserInviteReferralCode = reselect.createSelector(selectState$2, state => state.referralCode);
|
||||
const selectUserInviteReferralCode = reselect.createSelector(selectState$2, state => state.referralCode ? state.referralCode[0] : '');
|
||||
const selectYouTubeImportPending = reselect.createSelector(selectState$2, state => state.youtubeChannelImportPending);
|
||||
const selectYouTubeImportError = reselect.createSelector(selectState$2, state => state.youtubeChannelImportErrorMessage);
|
||||
const selectSetReferrerPending = reselect.createSelector(selectState$2, state => state.setReferrerIsPending);
|
||||
|
@ -1610,20 +1622,47 @@ function doUserInviteNew(email) {
|
|||
};
|
||||
}
|
||||
function doUserSetReferrer(referrer, shouldClaim) {
|
||||
return dispatch => {
|
||||
return async (dispatch, getState) => {
|
||||
dispatch({
|
||||
type: USER_SET_REFERRER_STARTED
|
||||
});
|
||||
return Lbryio.call('user', 'referral', {
|
||||
referrer
|
||||
}, 'post').then(() => {
|
||||
let claim;
|
||||
let referrerCode = referrer;
|
||||
const isClaim = lbryRedux.parseURI(referrer).claimId;
|
||||
|
||||
if (isClaim) {
|
||||
const uri = `lbry://${referrer}`;
|
||||
claim = lbryRedux.makeSelectClaimForUri(uri)(getState());
|
||||
|
||||
if (!claim) {
|
||||
try {
|
||||
const response = await lbryRedux.Lbry.resolve({
|
||||
urls: [uri]
|
||||
});
|
||||
claim = response && response[uri];
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: USER_SET_REFERRER_FAILURE,
|
||||
data: {
|
||||
error
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
referrerCode = claim && claim.permanent_url.replace('lbry://', '');
|
||||
}
|
||||
|
||||
try {
|
||||
await Lbryio.call('user', 'referral', {
|
||||
referrer: referrerCode
|
||||
}, 'post');
|
||||
dispatch({
|
||||
type: USER_SET_REFERRER_SUCCESS
|
||||
}); // for testing
|
||||
|
||||
});
|
||||
dispatch(lbryRedux.doToast({
|
||||
message: __(`Set Referrer to ${referrer}`)
|
||||
})); // we need to userFetch because once you claim this,
|
||||
}));
|
||||
|
||||
if (shouldClaim) {
|
||||
dispatch(doClaimRewardType(rewards.TYPE_REFEREE));
|
||||
|
@ -1631,14 +1670,14 @@ function doUserSetReferrer(referrer, shouldClaim) {
|
|||
} else {
|
||||
dispatch(doUserFetch());
|
||||
}
|
||||
}).catch(error => {
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: USER_SET_REFERRER_FAILURE,
|
||||
data: {
|
||||
error
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
function doClaimYoutubeChannels() {
|
||||
|
@ -3531,6 +3570,7 @@ const selectState$a = state => state.lbrytv || {};
|
|||
const selectCurrentUploads = reselect.createSelector(selectState$a, state => state.currentUploads);
|
||||
const selectUploadCount = reselect.createSelector(selectCurrentUploads, currentUploads => currentUploads && Object.keys(currentUploads).length);
|
||||
|
||||
exports.ERRORS = errors;
|
||||
exports.LBRYINC_ACTIONS = action_types;
|
||||
exports.Lbryio = Lbryio;
|
||||
exports.YOUTUBE_STATUSES = youtube;
|
||||
|
|
807
dist/bundle.js
vendored
807
dist/bundle.js
vendored
File diff suppressed because it is too large
Load diff
4
src/constants/errors.js
Normal file
4
src/constants/errors.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const ALREADY_CLAIMED =
|
||||
'once the invite reward has been claimed the referrer cannot be changed';
|
||||
export const REFERRER_NOT_FOUND =
|
||||
'A lbry.tv account could not be found for the referrer you provided.';
|
|
@ -1,5 +1,6 @@
|
|||
import * as LBRYINC_ACTIONS from 'constants/action_types';
|
||||
import * as YOUTUBE_STATUSES from 'constants/youtube';
|
||||
import * as ERRORS from 'constants/errors';
|
||||
import Lbryio from 'lbryio';
|
||||
import rewards from 'rewards';
|
||||
import subscriptionsReducer from 'redux/reducers/subscriptions';
|
||||
|
@ -8,7 +9,7 @@ import subscriptionsReducer from 'redux/reducers/subscriptions';
|
|||
export { userStateSyncMiddleware } from 'redux/middleware/sync';
|
||||
|
||||
// constants
|
||||
export { LBRYINC_ACTIONS, YOUTUBE_STATUSES };
|
||||
export { LBRYINC_ACTIONS, YOUTUBE_STATUSES, ERRORS };
|
||||
|
||||
// Lbryio and rewards
|
||||
export { Lbryio, rewards };
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
import { Lbry, doToast, doFetchChannelListMine, batchActions } from 'lbry-redux';
|
||||
import {
|
||||
Lbry,
|
||||
doToast,
|
||||
doFetchChannelListMine,
|
||||
batchActions,
|
||||
makeSelectClaimForUri,
|
||||
parseURI,
|
||||
} from 'lbry-redux';
|
||||
import * as ACTIONS from 'constants/action_types';
|
||||
import { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
|
||||
import {
|
||||
|
@ -390,36 +397,52 @@ export function doUserInviteNew(email) {
|
|||
}
|
||||
|
||||
export function doUserSetReferrer(referrer, shouldClaim) {
|
||||
return dispatch => {
|
||||
return async (dispatch, getState) => {
|
||||
dispatch({
|
||||
type: ACTIONS.USER_SET_REFERRER_STARTED,
|
||||
});
|
||||
let claim;
|
||||
let referrerCode = referrer;
|
||||
|
||||
return Lbryio.call('user', 'referral', { referrer }, 'post')
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: ACTIONS.USER_SET_REFERRER_SUCCESS,
|
||||
});
|
||||
// for testing
|
||||
dispatch(
|
||||
doToast({
|
||||
message: __(`Set Referrer to ${referrer}`),
|
||||
})
|
||||
);
|
||||
// we need to userFetch because once you claim this,
|
||||
if (shouldClaim) {
|
||||
dispatch(doClaimRewardType(rewards.TYPE_REFEREE));
|
||||
dispatch(doUserFetch());
|
||||
} else {
|
||||
dispatch(doUserFetch());
|
||||
const isClaim = parseURI(referrer).claimId;
|
||||
if (isClaim) {
|
||||
const uri = `lbry://${referrer}`;
|
||||
claim = makeSelectClaimForUri(uri)(getState());
|
||||
if (!claim) {
|
||||
try {
|
||||
const response = await Lbry.resolve({ urls: [uri] });
|
||||
claim = response && response[uri];
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: ACTIONS.USER_SET_REFERRER_FAILURE,
|
||||
data: { error },
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch({
|
||||
type: ACTIONS.USER_SET_REFERRER_FAILURE,
|
||||
data: { error },
|
||||
});
|
||||
}
|
||||
referrerCode = claim && claim.permanent_url.replace('lbry://', '');
|
||||
}
|
||||
try {
|
||||
await Lbryio.call('user', 'referral', { referrer: referrerCode }, 'post');
|
||||
dispatch({
|
||||
type: ACTIONS.USER_SET_REFERRER_SUCCESS,
|
||||
});
|
||||
dispatch(
|
||||
doToast({
|
||||
message: __(`Set Referrer to ${referrer}`),
|
||||
}),
|
||||
);
|
||||
if (shouldClaim) {
|
||||
dispatch(doClaimRewardType(rewards.TYPE_REFEREE));
|
||||
dispatch(doUserFetch());
|
||||
} else {
|
||||
dispatch(doUserFetch());
|
||||
}
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: ACTIONS.USER_SET_REFERRER_FAILURE,
|
||||
data: { error },
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,9 @@ export default handleActions(
|
|||
): SubscriptionState => {
|
||||
const newSubscription: Subscription = action.data;
|
||||
const newSubscriptions: Array<Subscription> = state.subscriptions.slice();
|
||||
newSubscriptions.unshift(newSubscription);
|
||||
if (!newSubscriptions.some(sub => sub.uri === newSubscription.uri)) {
|
||||
newSubscriptions.unshift(newSubscription);
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
|
|
|
@ -154,7 +154,7 @@ export const selectUserInviteReferralLink = createSelector(
|
|||
|
||||
export const selectUserInviteReferralCode = createSelector(
|
||||
selectState,
|
||||
state => state.referralCode
|
||||
state => (state.referralCode ? state.referralCode[0] : '')
|
||||
);
|
||||
|
||||
export const selectYouTubeImportPending = createSelector(
|
||||
|
|
Loading…
Add table
Reference in a new issue