Merge pull request #79 from lbryio/new_referrals

new referrals
This commit is contained in:
jessopb 2020-01-14 14:47:42 -05:00 committed by GitHub
commit e3520f5216
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 746 additions and 352 deletions

126
dist/bundle.es.js vendored
View file

@ -49,7 +49,10 @@ const USER_INVITE_NEW_FAILURE = 'USER_INVITE_NEW_FAILURE';
const FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS';
const USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED';
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_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_FAILURE: USER_YOUTUBE_IMPORT_FAILURE,
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_COMPLETED: FETCH_FEATURED_CONTENT_COMPLETED,
FETCH_TRENDING_CONTENT_STARTED: FETCH_TRENDING_CONTENT_STARTED,
@ -263,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,
@ -485,6 +499,7 @@ rewards.TYPE_FIRST_STREAM = 'first_stream';
rewards.TYPE_MANY_DOWNLOADS = 'many_downloads';
rewards.TYPE_FIRST_PUBLISH = 'first_publish';
rewards.TYPE_REFERRAL = 'referral';
rewards.TYPE_REFEREE = 'referee';
rewards.TYPE_REWARD_CODE = 'reward_code';
rewards.TYPE_SUBSCRIPTION = 'subscription';
rewards.YOUTUBE_CREATOR = 'youtube_creator';
@ -617,7 +632,11 @@ var subscriptions = handleActions({
[CHANNEL_SUBSCRIBE]: (state, action) => {
const newSubscription = action.data;
const newSubscriptions = state.subscriptions.slice();
if (!newSubscriptions.some(sub => sub.uri === newSubscription.uri)) {
newSubscriptions.unshift(newSubscription);
}
return { ...state,
subscriptions: newSubscriptions
};
@ -1214,8 +1233,11 @@ 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 ? 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.referrerSetIsPending);
const selectSetReferrerError = reselect.createSelector(selectState$2, state => state.referrerSetError);
const selectYouTubeImportVideosComplete = reselect.createSelector(selectState$2, state => {
const total = state.youtubeChannelImportTotal;
const complete = state.youtubeChannelImportComplete || 0;
@ -1237,7 +1259,8 @@ function doFetchInviteStatus() {
data: {
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
invitees: status.invitees,
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`,
referralCode: code
}
});
}).catch(error => {
@ -1276,12 +1299,12 @@ function doAuthenticate(appVersion, os = null, firebaseToken = null) {
dispatch({
type: AUTHENTICATION_STARTED
});
Lbryio.authenticate().then(user => {
Lbryio.authenticate().then(accessToken => {
// analytics.setUser(user);
dispatch({
type: AUTHENTICATION_SUCCESS,
data: {
user
accessToken
}
});
dispatch(doRewardList());
@ -1574,9 +1597,9 @@ function doUserInviteNew(email) {
dispatch({
type: USER_INVITE_NEW_STARTED
});
Lbryio.call('user', 'invite', {
return Lbryio.call('user', 'invite', {
email
}, 'post').then(() => {
}, 'post').then(success => {
dispatch({
type: USER_INVITE_NEW_SUCCESS,
data: {
@ -1587,6 +1610,7 @@ function doUserInviteNew(email) {
message: __(`Invite sent to ${email}`)
}));
dispatch(doFetchInviteStatus());
return success;
}).catch(error => {
dispatch({
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() {
return dispatch => {
dispatch({
@ -2879,21 +2959,26 @@ const defaultState$3 = {
inviteStatusIsPending: false,
invitesRemaining: undefined,
invitees: undefined,
referralLink: undefined,
referralCode: undefined,
user: undefined,
accessToken: undefined,
youtubeChannelImportPending: false,
youtubeChannelImportErrorMessage: ''
youtubeChannelImportErrorMessage: '',
referrerSetIsPending: false,
referrerSetError: ''
};
reducers$2[AUTHENTICATION_STARTED] = state => Object.assign({}, state, {
authenticationIsPending: true,
userIsPending: true,
user: defaultState$3.user
accessToken: defaultState$3.accessToken
});
reducers$2[AUTHENTICATION_SUCCESS] = (state, action) => Object.assign({}, state, {
authenticationIsPending: false,
userIsPending: false,
user: action.data.user
accessToken: action.data.accessToken
});
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,
invitesRemaining: action.data.invitesRemaining,
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, {
@ -3096,6 +3182,21 @@ reducers$2[USER_EMAIL_VERIFY_RETRY_FAILURE] = state => Object.assign({}, state,
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) {
const handler = reducers$2[action.type];
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 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;
@ -3528,6 +3630,7 @@ exports.doUserPhoneReset = doUserPhoneReset;
exports.doUserPhoneVerify = doUserPhoneVerify;
exports.doUserPhoneVerifyFailure = doUserPhoneVerifyFailure;
exports.doUserResendVerificationEmail = doUserResendVerificationEmail;
exports.doUserSetReferrer = doUserSetReferrer;
exports.filteredReducer = filteredReducer;
exports.homepageReducer = homepageReducer;
exports.lbrytvReducer = lbrytvReducer;
@ -3586,6 +3689,8 @@ exports.selectPhoneVerifyIsPending = selectPhoneVerifyIsPending;
exports.selectReferralReward = selectReferralReward;
exports.selectResendingVerificationEmail = selectResendingVerificationEmail;
exports.selectRewardContentClaimIds = selectRewardContentClaimIds;
exports.selectSetReferrerError = selectSetReferrerError;
exports.selectSetReferrerPending = selectSetReferrerPending;
exports.selectSetSyncErrorMessage = selectSetSyncErrorMessage;
exports.selectSetSyncIsPending = selectSetSyncIsPending;
exports.selectShowSuggestedSubs = selectShowSuggestedSubs;
@ -3612,6 +3717,7 @@ exports.selectUserCountryCode = selectUserCountryCode;
exports.selectUserEmail = selectUserEmail;
exports.selectUserInviteNewErrorMessage = selectUserInviteNewErrorMessage;
exports.selectUserInviteNewIsPending = selectUserInviteNewIsPending;
exports.selectUserInviteReferralCode = selectUserInviteReferralCode;
exports.selectUserInviteReferralLink = selectUserInviteReferralLink;
exports.selectUserInviteStatusFailed = selectUserInviteStatusFailed;
exports.selectUserInviteStatusIsPending = selectUserInviteStatusIsPending;

845
dist/bundle.js vendored

File diff suppressed because it is too large Load diff

View file

@ -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_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE';
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
export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';

4
src/constants/errors.js Normal file
View 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.';

View file

@ -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 };
@ -63,6 +64,7 @@ export {
doUserInviteNew,
doClaimYoutubeChannels,
doCheckYoutubeTransfer,
doUserSetReferrer,
} from 'redux/actions/user';
export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
@ -162,11 +164,14 @@ export {
selectUserInviteNewIsPending,
selectUserInviteNewErrorMessage,
selectUserInviteReferralLink,
selectUserInviteReferralCode,
selectUserVerifiedEmail,
selectYoutubeChannels,
selectYouTubeImportPending,
selectYouTubeImportError,
selectYouTubeImportVideosComplete,
selectSetReferrerPending,
selectSetReferrerError,
} from 'redux/selectors/user';
export {
makeSelectFetchingCostInfoForUri,

View file

@ -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 {
@ -25,6 +32,7 @@ export function doFetchInviteStatus() {
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
invitees: status.invitees,
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`,
referralCode: code,
},
});
})
@ -63,11 +71,11 @@ export function doAuthenticate(appVersion, os = null, firebaseToken = null) {
});
Lbryio.authenticate()
.then(user => {
.then(accessToken => {
// analytics.setUser(user);
dispatch({
type: ACTIONS.AUTHENTICATION_SUCCESS,
data: { user },
data: { accessToken },
});
dispatch(doRewardList());
dispatch(doFetchInviteStatus());
@ -363,8 +371,8 @@ export function doUserInviteNew(email) {
type: ACTIONS.USER_INVITE_NEW_STARTED,
});
Lbryio.call('user', 'invite', { email }, 'post')
.then(() => {
return Lbryio.call('user', 'invite', { email }, 'post')
.then(success => {
dispatch({
type: ACTIONS.USER_INVITE_NEW_SUCCESS,
data: { email },
@ -377,6 +385,7 @@ export function doUserInviteNew(email) {
);
dispatch(doFetchInviteStatus());
return success;
})
.catch(error => {
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() {
return dispatch => {
dispatch({

View file

@ -25,7 +25,9 @@ export default handleActions(
): SubscriptionState => {
const newSubscription: Subscription = action.data;
const newSubscriptions: Array<Subscription> = state.subscriptions.slice();
if (!newSubscriptions.some(sub => sub.uri === newSubscription.uri)) {
newSubscriptions.unshift(newSubscription);
}
return {
...state,

View file

@ -15,23 +15,28 @@ const defaultState = {
inviteStatusIsPending: false,
invitesRemaining: undefined,
invitees: undefined,
referralLink: undefined,
referralCode: undefined,
user: undefined,
accessToken: undefined,
youtubeChannelImportPending: false,
youtubeChannelImportErrorMessage: '',
referrerSetIsPending: false,
referrerSetError: '',
};
reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
Object.assign({}, state, {
authenticationIsPending: true,
userIsPending: true,
user: defaultState.user,
accessToken: defaultState.accessToken,
});
reducers[ACTIONS.AUTHENTICATION_SUCCESS] = (state, action) =>
Object.assign({}, state, {
authenticationIsPending: false,
userIsPending: false,
user: action.data.user,
accessToken: action.data.accessToken,
});
reducers[ACTIONS.AUTHENTICATION_FAILURE] = state =>
@ -198,6 +203,7 @@ reducers[ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS] = (state, action) =>
invitesRemaining: action.data.invitesRemaining,
invitees: action.data.invitees,
referralLink: action.data.referralLink,
referralCode: action.data.referralCode,
});
reducers[ACTIONS.USER_INVITE_NEW_STARTED] = state =>
@ -265,6 +271,24 @@ reducers[ACTIONS.USER_EMAIL_VERIFY_RETRY_FAILURE] = state =>
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) {
const handler = reducers[action.type];
if (handler) return handler(state, action);

View file

@ -152,6 +152,11 @@ export const selectUserInviteReferralLink = createSelector(
state => state.referralLink
);
export const selectUserInviteReferralCode = createSelector(
selectState,
state => (state.referralCode ? state.referralCode[0] : '')
);
export const selectYouTubeImportPending = createSelector(
selectState,
state => state.youtubeChannelImportPending
@ -162,6 +167,13 @@ export const selectYouTubeImportError = createSelector(
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 => {
const total = state.youtubeChannelImportTotal;
const complete = state.youtubeChannelImportComplete || 0;

View file

@ -11,6 +11,7 @@ rewards.TYPE_FIRST_STREAM = 'first_stream';
rewards.TYPE_MANY_DOWNLOADS = 'many_downloads';
rewards.TYPE_FIRST_PUBLISH = 'first_publish';
rewards.TYPE_REFERRAL = 'referral';
rewards.TYPE_REFEREE = 'referee';
rewards.TYPE_REWARD_CODE = 'reward_code';
rewards.TYPE_SUBSCRIPTION = 'subscription';
rewards.YOUTUBE_CREATOR = 'youtube_creator';