new referrals #79
10 changed files with 746 additions and 352 deletions
128
dist/bundle.es.js
vendored
128
dist/bundle.es.js
vendored
|
@ -49,7 +49,10 @@ const USER_INVITE_NEW_FAILURE = 'USER_INVITE_NEW_FAILURE';
|
||||||
const FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS';
|
const FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS';
|
||||||
const USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED';
|
const USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED';
|
||||||
const USER_YOUTUBE_IMPORT_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE';
|
const USER_YOUTUBE_IMPORT_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE';
|
||||||
const USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS'; // Claims
|
const USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS';
|
||||||
|
const USER_SET_REFERRER_STARTED = 'USER_SET_REFERRER_STARTED';
|
||||||
|
const USER_SET_REFERRER_SUCCESS = 'USER_SET_REFERRER_SUCCESS';
|
||||||
|
const USER_SET_REFERRER_FAILURE = 'USER_SET_REFERRER_FAILURE'; // Claims
|
||||||
|
|
||||||
const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
|
const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
|
||||||
const FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED';
|
const FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED';
|
||||||
|
@ -176,6 +179,9 @@ var action_types = /*#__PURE__*/Object.freeze({
|
||||||
USER_YOUTUBE_IMPORT_STARTED: USER_YOUTUBE_IMPORT_STARTED,
|
USER_YOUTUBE_IMPORT_STARTED: USER_YOUTUBE_IMPORT_STARTED,
|
||||||
USER_YOUTUBE_IMPORT_FAILURE: USER_YOUTUBE_IMPORT_FAILURE,
|
USER_YOUTUBE_IMPORT_FAILURE: USER_YOUTUBE_IMPORT_FAILURE,
|
||||||
USER_YOUTUBE_IMPORT_SUCCESS: USER_YOUTUBE_IMPORT_SUCCESS,
|
USER_YOUTUBE_IMPORT_SUCCESS: USER_YOUTUBE_IMPORT_SUCCESS,
|
||||||
|
USER_SET_REFERRER_STARTED: USER_SET_REFERRER_STARTED,
|
||||||
|
USER_SET_REFERRER_SUCCESS: USER_SET_REFERRER_SUCCESS,
|
||||||
|
USER_SET_REFERRER_FAILURE: USER_SET_REFERRER_FAILURE,
|
||||||
FETCH_FEATURED_CONTENT_STARTED: FETCH_FEATURED_CONTENT_STARTED,
|
FETCH_FEATURED_CONTENT_STARTED: FETCH_FEATURED_CONTENT_STARTED,
|
||||||
FETCH_FEATURED_CONTENT_COMPLETED: FETCH_FEATURED_CONTENT_COMPLETED,
|
FETCH_FEATURED_CONTENT_COMPLETED: FETCH_FEATURED_CONTENT_COMPLETED,
|
||||||
FETCH_TRENDING_CONTENT_STARTED: FETCH_TRENDING_CONTENT_STARTED,
|
FETCH_TRENDING_CONTENT_STARTED: FETCH_TRENDING_CONTENT_STARTED,
|
||||||
|
@ -263,6 +269,14 @@ var youtube = /*#__PURE__*/Object.freeze({
|
||||||
COMPLETED_TRANSFER: COMPLETED_TRANSFER
|
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 = {
|
const Lbryio = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
authenticationPromise: null,
|
authenticationPromise: null,
|
||||||
|
@ -485,6 +499,7 @@ rewards.TYPE_FIRST_STREAM = 'first_stream';
|
||||||
rewards.TYPE_MANY_DOWNLOADS = 'many_downloads';
|
rewards.TYPE_MANY_DOWNLOADS = 'many_downloads';
|
||||||
rewards.TYPE_FIRST_PUBLISH = 'first_publish';
|
rewards.TYPE_FIRST_PUBLISH = 'first_publish';
|
||||||
rewards.TYPE_REFERRAL = 'referral';
|
rewards.TYPE_REFERRAL = 'referral';
|
||||||
|
rewards.TYPE_REFEREE = 'referee';
|
||||||
rewards.TYPE_REWARD_CODE = 'reward_code';
|
rewards.TYPE_REWARD_CODE = 'reward_code';
|
||||||
rewards.TYPE_SUBSCRIPTION = 'subscription';
|
rewards.TYPE_SUBSCRIPTION = 'subscription';
|
||||||
rewards.YOUTUBE_CREATOR = 'youtube_creator';
|
rewards.YOUTUBE_CREATOR = 'youtube_creator';
|
||||||
|
@ -617,7 +632,11 @@ var subscriptions = handleActions({
|
||||||
[CHANNEL_SUBSCRIBE]: (state, action) => {
|
[CHANNEL_SUBSCRIBE]: (state, action) => {
|
||||||
const newSubscription = action.data;
|
const newSubscription = action.data;
|
||||||
const newSubscriptions = state.subscriptions.slice();
|
const newSubscriptions = state.subscriptions.slice();
|
||||||
newSubscriptions.unshift(newSubscription);
|
|
||||||
|
if (!newSubscriptions.some(sub => sub.uri === newSubscription.uri)) {
|
||||||
|
newSubscriptions.unshift(newSubscription);
|
||||||
|
}
|
||||||
|
|
||||||
return { ...state,
|
return { ...state,
|
||||||
subscriptions: newSubscriptions
|
subscriptions: newSubscriptions
|
||||||
};
|
};
|
||||||
|
@ -1214,8 +1233,11 @@ const selectUserInviteStatusFailed = reselect.createSelector(selectUserInvitesRe
|
||||||
const selectUserInviteNewIsPending = reselect.createSelector(selectState$2, state => state.inviteNewIsPending);
|
const selectUserInviteNewIsPending = reselect.createSelector(selectState$2, state => state.inviteNewIsPending);
|
||||||
const selectUserInviteNewErrorMessage = reselect.createSelector(selectState$2, state => state.inviteNewErrorMessage);
|
const selectUserInviteNewErrorMessage = reselect.createSelector(selectState$2, state => state.inviteNewErrorMessage);
|
||||||
const selectUserInviteReferralLink = reselect.createSelector(selectState$2, state => state.referralLink);
|
const selectUserInviteReferralLink = reselect.createSelector(selectState$2, state => state.referralLink);
|
||||||
|
const selectUserInviteReferralCode = reselect.createSelector(selectState$2, state => state.referralCode ? state.referralCode[0] : '');
|
||||||
const selectYouTubeImportPending = reselect.createSelector(selectState$2, state => state.youtubeChannelImportPending);
|
const selectYouTubeImportPending = reselect.createSelector(selectState$2, state => state.youtubeChannelImportPending);
|
||||||
const selectYouTubeImportError = reselect.createSelector(selectState$2, state => state.youtubeChannelImportErrorMessage);
|
const selectYouTubeImportError = reselect.createSelector(selectState$2, state => state.youtubeChannelImportErrorMessage);
|
||||||
|
const selectSetReferrerPending = reselect.createSelector(selectState$2, state => state.referrerSetIsPending);
|
||||||
|
const selectSetReferrerError = reselect.createSelector(selectState$2, state => state.referrerSetError);
|
||||||
const selectYouTubeImportVideosComplete = reselect.createSelector(selectState$2, state => {
|
const selectYouTubeImportVideosComplete = reselect.createSelector(selectState$2, state => {
|
||||||
const total = state.youtubeChannelImportTotal;
|
const total = state.youtubeChannelImportTotal;
|
||||||
const complete = state.youtubeChannelImportComplete || 0;
|
const complete = state.youtubeChannelImportComplete || 0;
|
||||||
|
@ -1237,7 +1259,8 @@ function doFetchInviteStatus() {
|
||||||
data: {
|
data: {
|
||||||
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
|
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
|
||||||
invitees: status.invitees,
|
invitees: status.invitees,
|
||||||
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`
|
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`,
|
||||||
|
referralCode: code
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
@ -1276,12 +1299,12 @@ function doAuthenticate(appVersion, os = null, firebaseToken = null) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: AUTHENTICATION_STARTED
|
type: AUTHENTICATION_STARTED
|
||||||
});
|
});
|
||||||
Lbryio.authenticate().then(user => {
|
Lbryio.authenticate().then(accessToken => {
|
||||||
// analytics.setUser(user);
|
// analytics.setUser(user);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: AUTHENTICATION_SUCCESS,
|
type: AUTHENTICATION_SUCCESS,
|
||||||
data: {
|
data: {
|
||||||
user
|
accessToken
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dispatch(doRewardList());
|
dispatch(doRewardList());
|
||||||
|
@ -1574,9 +1597,9 @@ function doUserInviteNew(email) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: USER_INVITE_NEW_STARTED
|
type: USER_INVITE_NEW_STARTED
|
||||||
});
|
});
|
||||||
Lbryio.call('user', 'invite', {
|
return Lbryio.call('user', 'invite', {
|
||||||
email
|
email
|
||||||
}, 'post').then(() => {
|
}, 'post').then(success => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: USER_INVITE_NEW_SUCCESS,
|
type: USER_INVITE_NEW_SUCCESS,
|
||||||
data: {
|
data: {
|
||||||
|
@ -1587,6 +1610,7 @@ function doUserInviteNew(email) {
|
||||||
message: __(`Invite sent to ${email}`)
|
message: __(`Invite sent to ${email}`)
|
||||||
}));
|
}));
|
||||||
dispatch(doFetchInviteStatus());
|
dispatch(doFetchInviteStatus());
|
||||||
|
return success;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: USER_INVITE_NEW_FAILURE,
|
type: USER_INVITE_NEW_FAILURE,
|
||||||
|
@ -1597,6 +1621,62 @@ function doUserInviteNew(email) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
function doUserSetReferrer(referrer, shouldClaim) {
|
||||||
|
return async (dispatch, getState) => {
|
||||||
|
dispatch({
|
||||||
|
type: USER_SET_REFERRER_STARTED
|
||||||
|
});
|
||||||
|
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
|
||||||
|
});
|
||||||
|
|
||||||
|
if (shouldClaim) {
|
||||||
|
dispatch(doClaimRewardType(rewards.TYPE_REFEREE));
|
||||||
|
dispatch(doUserFetch());
|
||||||
|
} else {
|
||||||
|
dispatch(doUserFetch());
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
dispatch({
|
||||||
|
type: USER_SET_REFERRER_FAILURE,
|
||||||
|
data: {
|
||||||
|
error
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
function doClaimYoutubeChannels() {
|
function doClaimYoutubeChannels() {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -2879,21 +2959,26 @@ const defaultState$3 = {
|
||||||
inviteStatusIsPending: false,
|
inviteStatusIsPending: false,
|
||||||
invitesRemaining: undefined,
|
invitesRemaining: undefined,
|
||||||
invitees: undefined,
|
invitees: undefined,
|
||||||
|
referralLink: undefined,
|
||||||
|
referralCode: undefined,
|
||||||
user: undefined,
|
user: undefined,
|
||||||
|
accessToken: undefined,
|
||||||
youtubeChannelImportPending: false,
|
youtubeChannelImportPending: false,
|
||||||
youtubeChannelImportErrorMessage: ''
|
youtubeChannelImportErrorMessage: '',
|
||||||
|
referrerSetIsPending: false,
|
||||||
|
referrerSetError: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers$2[AUTHENTICATION_STARTED] = state => Object.assign({}, state, {
|
reducers$2[AUTHENTICATION_STARTED] = state => Object.assign({}, state, {
|
||||||
authenticationIsPending: true,
|
authenticationIsPending: true,
|
||||||
userIsPending: true,
|
userIsPending: true,
|
||||||
user: defaultState$3.user
|
accessToken: defaultState$3.accessToken
|
||||||
});
|
});
|
||||||
|
|
||||||
reducers$2[AUTHENTICATION_SUCCESS] = (state, action) => Object.assign({}, state, {
|
reducers$2[AUTHENTICATION_SUCCESS] = (state, action) => Object.assign({}, state, {
|
||||||
authenticationIsPending: false,
|
authenticationIsPending: false,
|
||||||
userIsPending: false,
|
userIsPending: false,
|
||||||
user: action.data.user
|
accessToken: action.data.accessToken
|
||||||
});
|
});
|
||||||
|
|
||||||
reducers$2[AUTHENTICATION_FAILURE] = state => Object.assign({}, state, {
|
reducers$2[AUTHENTICATION_FAILURE] = state => Object.assign({}, state, {
|
||||||
|
@ -3039,7 +3124,8 @@ reducers$2[USER_INVITE_STATUS_FETCH_SUCCESS] = (state, action) => Object.assign(
|
||||||
inviteStatusIsPending: false,
|
inviteStatusIsPending: false,
|
||||||
invitesRemaining: action.data.invitesRemaining,
|
invitesRemaining: action.data.invitesRemaining,
|
||||||
invitees: action.data.invitees,
|
invitees: action.data.invitees,
|
||||||
referralLink: action.data.referralLink
|
referralLink: action.data.referralLink,
|
||||||
|
referralCode: action.data.referralCode
|
||||||
});
|
});
|
||||||
|
|
||||||
reducers$2[USER_INVITE_NEW_STARTED] = state => Object.assign({}, state, {
|
reducers$2[USER_INVITE_NEW_STARTED] = state => Object.assign({}, state, {
|
||||||
|
@ -3096,6 +3182,21 @@ reducers$2[USER_EMAIL_VERIFY_RETRY_FAILURE] = state => Object.assign({}, state,
|
||||||
resendingVerificationEmail: false
|
resendingVerificationEmail: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
reducers$2[USER_SET_REFERRER_STARTED] = state => Object.assign({}, state, {
|
||||||
|
referrerSetIsPending: true,
|
||||||
|
referrerSetError: defaultState$3.referrerSetError
|
||||||
|
});
|
||||||
|
|
||||||
|
reducers$2[USER_SET_REFERRER_SUCCESS] = state => Object.assign({}, state, {
|
||||||
|
referrerSetIsPending: false,
|
||||||
|
referrerSetError: defaultState$3.referrerSetError
|
||||||
|
});
|
||||||
|
|
||||||
|
reducers$2[USER_SET_REFERRER_FAILURE] = (state, action) => Object.assign({}, state, {
|
||||||
|
referrerSetIsPending: false,
|
||||||
|
referrerSetError: action.data.error.message
|
||||||
|
});
|
||||||
|
|
||||||
function userReducer(state = defaultState$3, action) {
|
function userReducer(state = defaultState$3, action) {
|
||||||
const handler = reducers$2[action.type];
|
const handler = reducers$2[action.type];
|
||||||
if (handler) return handler(state, action);
|
if (handler) return handler(state, action);
|
||||||
|
@ -3466,6 +3567,7 @@ const selectState$a = state => state.lbrytv || {};
|
||||||
const selectCurrentUploads = reselect.createSelector(selectState$a, state => state.currentUploads);
|
const selectCurrentUploads = reselect.createSelector(selectState$a, state => state.currentUploads);
|
||||||
const selectUploadCount = reselect.createSelector(selectCurrentUploads, currentUploads => currentUploads && Object.keys(currentUploads).length);
|
const selectUploadCount = reselect.createSelector(selectCurrentUploads, currentUploads => currentUploads && Object.keys(currentUploads).length);
|
||||||
|
|
||||||
|
exports.ERRORS = errors;
|
||||||
exports.LBRYINC_ACTIONS = action_types;
|
exports.LBRYINC_ACTIONS = action_types;
|
||||||
exports.Lbryio = Lbryio;
|
exports.Lbryio = Lbryio;
|
||||||
exports.YOUTUBE_STATUSES = youtube;
|
exports.YOUTUBE_STATUSES = youtube;
|
||||||
|
@ -3528,6 +3630,7 @@ exports.doUserPhoneReset = doUserPhoneReset;
|
||||||
exports.doUserPhoneVerify = doUserPhoneVerify;
|
exports.doUserPhoneVerify = doUserPhoneVerify;
|
||||||
exports.doUserPhoneVerifyFailure = doUserPhoneVerifyFailure;
|
exports.doUserPhoneVerifyFailure = doUserPhoneVerifyFailure;
|
||||||
exports.doUserResendVerificationEmail = doUserResendVerificationEmail;
|
exports.doUserResendVerificationEmail = doUserResendVerificationEmail;
|
||||||
|
exports.doUserSetReferrer = doUserSetReferrer;
|
||||||
exports.filteredReducer = filteredReducer;
|
exports.filteredReducer = filteredReducer;
|
||||||
exports.homepageReducer = homepageReducer;
|
exports.homepageReducer = homepageReducer;
|
||||||
exports.lbrytvReducer = lbrytvReducer;
|
exports.lbrytvReducer = lbrytvReducer;
|
||||||
|
@ -3586,6 +3689,8 @@ exports.selectPhoneVerifyIsPending = selectPhoneVerifyIsPending;
|
||||||
exports.selectReferralReward = selectReferralReward;
|
exports.selectReferralReward = selectReferralReward;
|
||||||
exports.selectResendingVerificationEmail = selectResendingVerificationEmail;
|
exports.selectResendingVerificationEmail = selectResendingVerificationEmail;
|
||||||
exports.selectRewardContentClaimIds = selectRewardContentClaimIds;
|
exports.selectRewardContentClaimIds = selectRewardContentClaimIds;
|
||||||
|
exports.selectSetReferrerError = selectSetReferrerError;
|
||||||
|
exports.selectSetReferrerPending = selectSetReferrerPending;
|
||||||
exports.selectSetSyncErrorMessage = selectSetSyncErrorMessage;
|
exports.selectSetSyncErrorMessage = selectSetSyncErrorMessage;
|
||||||
exports.selectSetSyncIsPending = selectSetSyncIsPending;
|
exports.selectSetSyncIsPending = selectSetSyncIsPending;
|
||||||
exports.selectShowSuggestedSubs = selectShowSuggestedSubs;
|
exports.selectShowSuggestedSubs = selectShowSuggestedSubs;
|
||||||
|
@ -3612,6 +3717,7 @@ exports.selectUserCountryCode = selectUserCountryCode;
|
||||||
exports.selectUserEmail = selectUserEmail;
|
exports.selectUserEmail = selectUserEmail;
|
||||||
exports.selectUserInviteNewErrorMessage = selectUserInviteNewErrorMessage;
|
exports.selectUserInviteNewErrorMessage = selectUserInviteNewErrorMessage;
|
||||||
exports.selectUserInviteNewIsPending = selectUserInviteNewIsPending;
|
exports.selectUserInviteNewIsPending = selectUserInviteNewIsPending;
|
||||||
|
exports.selectUserInviteReferralCode = selectUserInviteReferralCode;
|
||||||
exports.selectUserInviteReferralLink = selectUserInviteReferralLink;
|
exports.selectUserInviteReferralLink = selectUserInviteReferralLink;
|
||||||
exports.selectUserInviteStatusFailed = selectUserInviteStatusFailed;
|
exports.selectUserInviteStatusFailed = selectUserInviteStatusFailed;
|
||||||
exports.selectUserInviteStatusIsPending = selectUserInviteStatusIsPending;
|
exports.selectUserInviteStatusIsPending = selectUserInviteStatusIsPending;
|
||||||
|
|
847
dist/bundle.js
vendored
847
dist/bundle.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -40,6 +40,9 @@ export const FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS';
|
||||||
export const USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED';
|
export const USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED';
|
||||||
export const USER_YOUTUBE_IMPORT_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE';
|
export const USER_YOUTUBE_IMPORT_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE';
|
||||||
export const USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS';
|
export const USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS';
|
||||||
|
export const USER_SET_REFERRER_STARTED = 'USER_SET_REFERRER_STARTED';
|
||||||
|
export const USER_SET_REFERRER_SUCCESS = 'USER_SET_REFERRER_SUCCESS';
|
||||||
|
export const USER_SET_REFERRER_FAILURE = 'USER_SET_REFERRER_FAILURE';
|
||||||
|
|
||||||
// Claims
|
// Claims
|
||||||
export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
|
export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
|
||||||
|
|
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 LBRYINC_ACTIONS from 'constants/action_types';
|
||||||
import * as YOUTUBE_STATUSES from 'constants/youtube';
|
import * as YOUTUBE_STATUSES from 'constants/youtube';
|
||||||
|
import * as ERRORS from 'constants/errors';
|
||||||
import Lbryio from 'lbryio';
|
import Lbryio from 'lbryio';
|
||||||
import rewards from 'rewards';
|
import rewards from 'rewards';
|
||||||
import subscriptionsReducer from 'redux/reducers/subscriptions';
|
import subscriptionsReducer from 'redux/reducers/subscriptions';
|
||||||
|
@ -8,7 +9,7 @@ import subscriptionsReducer from 'redux/reducers/subscriptions';
|
||||||
export { userStateSyncMiddleware } from 'redux/middleware/sync';
|
export { userStateSyncMiddleware } from 'redux/middleware/sync';
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
export { LBRYINC_ACTIONS, YOUTUBE_STATUSES };
|
export { LBRYINC_ACTIONS, YOUTUBE_STATUSES, ERRORS };
|
||||||
|
|
||||||
// Lbryio and rewards
|
// Lbryio and rewards
|
||||||
export { Lbryio, rewards };
|
export { Lbryio, rewards };
|
||||||
|
@ -63,6 +64,7 @@ export {
|
||||||
doUserInviteNew,
|
doUserInviteNew,
|
||||||
doClaimYoutubeChannels,
|
doClaimYoutubeChannels,
|
||||||
doCheckYoutubeTransfer,
|
doCheckYoutubeTransfer,
|
||||||
|
doUserSetReferrer,
|
||||||
} from 'redux/actions/user';
|
} from 'redux/actions/user';
|
||||||
export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
|
export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
|
||||||
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
|
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
|
||||||
|
@ -162,11 +164,14 @@ export {
|
||||||
selectUserInviteNewIsPending,
|
selectUserInviteNewIsPending,
|
||||||
selectUserInviteNewErrorMessage,
|
selectUserInviteNewErrorMessage,
|
||||||
selectUserInviteReferralLink,
|
selectUserInviteReferralLink,
|
||||||
|
selectUserInviteReferralCode,
|
||||||
selectUserVerifiedEmail,
|
selectUserVerifiedEmail,
|
||||||
selectYoutubeChannels,
|
selectYoutubeChannels,
|
||||||
selectYouTubeImportPending,
|
selectYouTubeImportPending,
|
||||||
selectYouTubeImportError,
|
selectYouTubeImportError,
|
||||||
selectYouTubeImportVideosComplete,
|
selectYouTubeImportVideosComplete,
|
||||||
|
selectSetReferrerPending,
|
||||||
|
selectSetReferrerError,
|
||||||
} from 'redux/selectors/user';
|
} from 'redux/selectors/user';
|
||||||
export {
|
export {
|
||||||
makeSelectFetchingCostInfoForUri,
|
makeSelectFetchingCostInfoForUri,
|
||||||
|
|
|
@ -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 * as ACTIONS from 'constants/action_types';
|
||||||
import { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
|
import { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
|
||||||
import {
|
import {
|
||||||
|
@ -25,6 +32,7 @@ export function doFetchInviteStatus() {
|
||||||
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
|
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
|
||||||
invitees: status.invitees,
|
invitees: status.invitees,
|
||||||
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`,
|
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`,
|
||||||
|
referralCode: code,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -63,11 +71,11 @@ export function doAuthenticate(appVersion, os = null, firebaseToken = null) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Lbryio.authenticate()
|
Lbryio.authenticate()
|
||||||
.then(user => {
|
.then(accessToken => {
|
||||||
// analytics.setUser(user);
|
// analytics.setUser(user);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.AUTHENTICATION_SUCCESS,
|
type: ACTIONS.AUTHENTICATION_SUCCESS,
|
||||||
data: { user },
|
data: { accessToken },
|
||||||
});
|
});
|
||||||
dispatch(doRewardList());
|
dispatch(doRewardList());
|
||||||
dispatch(doFetchInviteStatus());
|
dispatch(doFetchInviteStatus());
|
||||||
|
@ -363,8 +371,8 @@ export function doUserInviteNew(email) {
|
||||||
type: ACTIONS.USER_INVITE_NEW_STARTED,
|
type: ACTIONS.USER_INVITE_NEW_STARTED,
|
||||||
});
|
});
|
||||||
|
|
||||||
Lbryio.call('user', 'invite', { email }, 'post')
|
return Lbryio.call('user', 'invite', { email }, 'post')
|
||||||
.then(() => {
|
.then(success => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.USER_INVITE_NEW_SUCCESS,
|
type: ACTIONS.USER_INVITE_NEW_SUCCESS,
|
||||||
data: { email },
|
data: { email },
|
||||||
|
@ -377,6 +385,7 @@ export function doUserInviteNew(email) {
|
||||||
);
|
);
|
||||||
|
|
||||||
dispatch(doFetchInviteStatus());
|
dispatch(doFetchInviteStatus());
|
||||||
|
return success;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -387,6 +396,51 @@ export function doUserInviteNew(email) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doUserSetReferrer(referrer, shouldClaim) {
|
||||||
|
return async (dispatch, getState) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.USER_SET_REFERRER_STARTED,
|
||||||
|
});
|
||||||
|
let claim;
|
||||||
|
let referrerCode = referrer;
|
||||||
|
|
||||||
|
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 },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
referrerCode = claim && claim.permanent_url.replace('lbry://', '');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await Lbryio.call('user', 'referral', { referrer: referrerCode }, 'post');
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.USER_SET_REFERRER_SUCCESS,
|
||||||
|
});
|
||||||
|
if (shouldClaim) {
|
||||||
|
dispatch(doClaimRewardType(rewards.TYPE_REFEREE));
|
||||||
|
dispatch(doUserFetch());
|
||||||
|
} else {
|
||||||
|
dispatch(doUserFetch());
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.USER_SET_REFERRER_FAILURE,
|
||||||
|
data: { error },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function doClaimYoutubeChannels() {
|
export function doClaimYoutubeChannels() {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|
|
@ -25,7 +25,9 @@ export default handleActions(
|
||||||
): SubscriptionState => {
|
): SubscriptionState => {
|
||||||
const newSubscription: Subscription = action.data;
|
const newSubscription: Subscription = action.data;
|
||||||
const newSubscriptions: Array<Subscription> = state.subscriptions.slice();
|
const newSubscriptions: Array<Subscription> = state.subscriptions.slice();
|
||||||
newSubscriptions.unshift(newSubscription);
|
if (!newSubscriptions.some(sub => sub.uri === newSubscription.uri)) {
|
||||||
|
newSubscriptions.unshift(newSubscription);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -15,23 +15,28 @@ const defaultState = {
|
||||||
inviteStatusIsPending: false,
|
inviteStatusIsPending: false,
|
||||||
invitesRemaining: undefined,
|
invitesRemaining: undefined,
|
||||||
invitees: undefined,
|
invitees: undefined,
|
||||||
|
referralLink: undefined,
|
||||||
|
referralCode: undefined,
|
||||||
user: undefined,
|
user: undefined,
|
||||||
|
accessToken: undefined,
|
||||||
youtubeChannelImportPending: false,
|
youtubeChannelImportPending: false,
|
||||||
youtubeChannelImportErrorMessage: '',
|
youtubeChannelImportErrorMessage: '',
|
||||||
|
referrerSetIsPending: false,
|
||||||
|
referrerSetError: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
|
reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
|
||||||
Object.assign({}, state, {
|
Object.assign({}, state, {
|
||||||
authenticationIsPending: true,
|
authenticationIsPending: true,
|
||||||
userIsPending: true,
|
userIsPending: true,
|
||||||
user: defaultState.user,
|
accessToken: defaultState.accessToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
reducers[ACTIONS.AUTHENTICATION_SUCCESS] = (state, action) =>
|
reducers[ACTIONS.AUTHENTICATION_SUCCESS] = (state, action) =>
|
||||||
Object.assign({}, state, {
|
Object.assign({}, state, {
|
||||||
authenticationIsPending: false,
|
authenticationIsPending: false,
|
||||||
userIsPending: false,
|
userIsPending: false,
|
||||||
user: action.data.user,
|
accessToken: action.data.accessToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
reducers[ACTIONS.AUTHENTICATION_FAILURE] = state =>
|
reducers[ACTIONS.AUTHENTICATION_FAILURE] = state =>
|
||||||
|
@ -198,6 +203,7 @@ reducers[ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS] = (state, action) =>
|
||||||
invitesRemaining: action.data.invitesRemaining,
|
invitesRemaining: action.data.invitesRemaining,
|
||||||
invitees: action.data.invitees,
|
invitees: action.data.invitees,
|
||||||
referralLink: action.data.referralLink,
|
referralLink: action.data.referralLink,
|
||||||
|
referralCode: action.data.referralCode,
|
||||||
});
|
});
|
||||||
|
|
||||||
reducers[ACTIONS.USER_INVITE_NEW_STARTED] = state =>
|
reducers[ACTIONS.USER_INVITE_NEW_STARTED] = state =>
|
||||||
|
@ -265,6 +271,24 @@ reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_FAILURE] = state =>
|
||||||
resendingVerificationEmail: false,
|
resendingVerificationEmail: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
reducers[ACTIONS.USER_SET_REFERRER_STARTED] = state =>
|
||||||
|
Object.assign({}, state, {
|
||||||
|
referrerSetIsPending: true,
|
||||||
|
referrerSetError: defaultState.referrerSetError,
|
||||||
|
});
|
||||||
|
|
||||||
|
reducers[ACTIONS.USER_SET_REFERRER_SUCCESS] = state =>
|
||||||
|
Object.assign({}, state, {
|
||||||
|
referrerSetIsPending: false,
|
||||||
|
referrerSetError: defaultState.referrerSetError,
|
||||||
|
});
|
||||||
|
|
||||||
|
reducers[ACTIONS.USER_SET_REFERRER_FAILURE] = (state, action) =>
|
||||||
|
Object.assign({}, state, {
|
||||||
|
referrerSetIsPending: false,
|
||||||
|
referrerSetError: action.data.error.message,
|
||||||
|
});
|
||||||
|
|
||||||
export function userReducer(state = defaultState, action) {
|
export function userReducer(state = defaultState, action) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
if (handler) return handler(state, action);
|
if (handler) return handler(state, action);
|
||||||
|
|
|
@ -152,6 +152,11 @@ export const selectUserInviteReferralLink = createSelector(
|
||||||
state => state.referralLink
|
state => state.referralLink
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectUserInviteReferralCode = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => (state.referralCode ? state.referralCode[0] : '')
|
||||||
|
);
|
||||||
|
|
||||||
export const selectYouTubeImportPending = createSelector(
|
export const selectYouTubeImportPending = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.youtubeChannelImportPending
|
state => state.youtubeChannelImportPending
|
||||||
|
@ -162,6 +167,13 @@ export const selectYouTubeImportError = createSelector(
|
||||||
state => state.youtubeChannelImportErrorMessage
|
state => state.youtubeChannelImportErrorMessage
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectSetReferrerPending = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.referrerSetIsPending
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectSetReferrerError = createSelector(selectState, state => state.referrerSetError);
|
||||||
|
|
||||||
export const selectYouTubeImportVideosComplete = createSelector(selectState, state => {
|
export const selectYouTubeImportVideosComplete = createSelector(selectState, state => {
|
||||||
const total = state.youtubeChannelImportTotal;
|
const total = state.youtubeChannelImportTotal;
|
||||||
const complete = state.youtubeChannelImportComplete || 0;
|
const complete = state.youtubeChannelImportComplete || 0;
|
||||||
|
|
|
@ -11,6 +11,7 @@ rewards.TYPE_FIRST_STREAM = 'first_stream';
|
||||||
rewards.TYPE_MANY_DOWNLOADS = 'many_downloads';
|
rewards.TYPE_MANY_DOWNLOADS = 'many_downloads';
|
||||||
rewards.TYPE_FIRST_PUBLISH = 'first_publish';
|
rewards.TYPE_FIRST_PUBLISH = 'first_publish';
|
||||||
rewards.TYPE_REFERRAL = 'referral';
|
rewards.TYPE_REFERRAL = 'referral';
|
||||||
|
rewards.TYPE_REFEREE = 'referee';
|
||||||
rewards.TYPE_REWARD_CODE = 'reward_code';
|
rewards.TYPE_REWARD_CODE = 'reward_code';
|
||||||
rewards.TYPE_SUBSCRIPTION = 'subscription';
|
rewards.TYPE_SUBSCRIPTION = 'subscription';
|
||||||
rewards.YOUTUBE_CREATOR = 'youtube_creator';
|
rewards.YOUTUBE_CREATOR = 'youtube_creator';
|
||||||
|
|
Loading…
Reference in a new issue