diff --git a/dist/bundle.es.js b/dist/bundle.es.js index ad80dc2..57a67a4 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -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, @@ -485,6 +491,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'; @@ -1214,8 +1221,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); 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); +const selectSetReferrerError = reselect.createSelector(selectState$2, state => state.setReferrerError); const selectYouTubeImportVideosComplete = reselect.createSelector(selectState$2, state => { const total = state.youtubeChannelImportTotal; const complete = state.youtubeChannelImportComplete || 0; @@ -1237,7 +1247,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 +1287,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 +1585,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 +1598,7 @@ function doUserInviteNew(email) { message: __(`Invite sent to ${email}`) })); dispatch(doFetchInviteStatus()); + return success; }).catch(error => { dispatch({ type: USER_INVITE_NEW_FAILURE, @@ -1597,6 +1609,38 @@ function doUserInviteNew(email) { }); }; } +function doUserSetReferrer(referrer, shouldClaim) { + return dispatch => { + dispatch({ + type: USER_SET_REFERRER_STARTED + }); + return Lbryio.call('user', 'referral', { + referrer + }, 'post').then(() => { + 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)); + dispatch(doUserFetch()); + } else { + dispatch(doUserFetch()); + } + }).catch(error => { + dispatch({ + type: USER_SET_REFERRER_FAILURE, + data: { + error + } + }); + }); + }; +} function doClaimYoutubeChannels() { return dispatch => { dispatch({ @@ -2879,21 +2923,26 @@ const defaultState$3 = { inviteStatusIsPending: false, invitesRemaining: undefined, invitees: undefined, + referralLink: undefined, + referralCode: undefined, user: undefined, + accessToken: undefined, youtubeChannelImportPending: false, - youtubeChannelImportErrorMessage: '' + youtubeChannelImportErrorMessage: '', + setReferrerIsPending: false, + setReferrerError: '' }; 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 +3088,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 +3146,21 @@ reducers$2[USER_EMAIL_VERIFY_RETRY_FAILURE] = state => Object.assign({}, state, resendingVerificationEmail: false }); +reducers$2[USER_SET_REFERRER_STARTED] = state => Object.assign({}, state, { + setReferrerIsPending: true, + setReferrerError: defaultState$3.setReferrerError +}); + +reducers$2[USER_SET_REFERRER_SUCCESS] = state => Object.assign({}, state, { + setReferrerIsPending: false, + setReferrerError: defaultState$3.setReferrerError +}); + +reducers$2[USER_SET_REFERRER_FAILURE] = (state, action) => Object.assign({}, state, { + setReferrerIsPending: false, + setReferrerError: action.data.error.message +}); + function userReducer(state = defaultState$3, action) { const handler = reducers$2[action.type]; if (handler) return handler(state, action); @@ -3528,6 +3593,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 +3652,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 +3680,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; diff --git a/dist/bundle.js b/dist/bundle.js index e49c150..66a0050 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -205,6 +205,8 @@ __webpack_require__.r(__webpack_exports__); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doCheckYoutubeTransfer", function() { return redux_actions_user__WEBPACK_IMPORTED_MODULE_10__["doCheckYoutubeTransfer"]; }); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doUserSetReferrer", function() { return redux_actions_user__WEBPACK_IMPORTED_MODULE_10__["doUserSetReferrer"]; }); + /* harmony import */ var redux_actions_cost_info__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(29); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchCostInfoForUri", function() { return redux_actions_cost_info__WEBPACK_IMPORTED_MODULE_11__["doFetchCostInfoForUri"]; }); @@ -404,6 +406,8 @@ __webpack_require__.r(__webpack_exports__); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectUserInviteReferralLink", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_31__["selectUserInviteReferralLink"]; }); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectUserInviteReferralCode", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_31__["selectUserInviteReferralCode"]; }); + /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectUserVerifiedEmail", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_31__["selectUserVerifiedEmail"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYoutubeChannels", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_31__["selectYoutubeChannels"]; }); @@ -414,6 +418,10 @@ __webpack_require__.r(__webpack_exports__); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYouTubeImportVideosComplete", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_31__["selectYouTubeImportVideosComplete"]; }); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSetReferrerPending", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_31__["selectSetReferrerPending"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSetReferrerError", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_31__["selectSetReferrerError"]; }); + /* harmony import */ var redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(47); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectFetchingCostInfoForUri", function() { return redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_32__["makeSelectFetchingCostInfoForUri"]; }); @@ -568,6 +576,9 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "USER_YOUTUBE_IMPORT_STARTED", function() { return USER_YOUTUBE_IMPORT_STARTED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "USER_YOUTUBE_IMPORT_FAILURE", function() { return USER_YOUTUBE_IMPORT_FAILURE; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "USER_YOUTUBE_IMPORT_SUCCESS", function() { return USER_YOUTUBE_IMPORT_SUCCESS; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "USER_SET_REFERRER_STARTED", function() { return USER_SET_REFERRER_STARTED; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "USER_SET_REFERRER_SUCCESS", function() { return USER_SET_REFERRER_SUCCESS; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "USER_SET_REFERRER_FAILURE", function() { return USER_SET_REFERRER_FAILURE; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_FEATURED_CONTENT_STARTED", function() { return FETCH_FEATURED_CONTENT_STARTED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_FEATURED_CONTENT_COMPLETED", function() { return FETCH_FEATURED_CONTENT_COMPLETED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_TRENDING_CONTENT_STARTED", function() { return FETCH_TRENDING_CONTENT_STARTED; }); @@ -684,7 +695,10 @@ var USER_INVITE_NEW_FAILURE = 'USER_INVITE_NEW_FAILURE'; var FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS'; var USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED'; var USER_YOUTUBE_IMPORT_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE'; -var USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS'; // Claims +var USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS'; +var USER_SET_REFERRER_STARTED = 'USER_SET_REFERRER_STARTED'; +var USER_SET_REFERRER_SUCCESS = 'USER_SET_REFERRER_SUCCESS'; +var USER_SET_REFERRER_FAILURE = 'USER_SET_REFERRER_FAILURE'; // Claims var FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED'; var FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED'; @@ -1255,6 +1269,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'; @@ -4648,8 +4663,11 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectUserInviteNewIsPending", function() { return selectUserInviteNewIsPending; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectUserInviteNewErrorMessage", function() { return selectUserInviteNewErrorMessage; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectUserInviteReferralLink", function() { return selectUserInviteReferralLink; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectUserInviteReferralCode", function() { return selectUserInviteReferralCode; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectYouTubeImportPending", function() { return selectYouTubeImportPending; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectYouTubeImportError", function() { return selectYouTubeImportError; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSetReferrerPending", function() { return selectSetReferrerPending; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSetReferrerError", function() { return selectSetReferrerError; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectYouTubeImportVideosComplete", function() { return selectYouTubeImportVideosComplete; }); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(14); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__); @@ -4753,12 +4771,21 @@ var selectUserInviteNewErrorMessage = Object(reselect__WEBPACK_IMPORTED_MODULE_0 var selectUserInviteReferralLink = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { return state.referralLink; }); +var selectUserInviteReferralCode = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { + return state.referralCode; +}); var selectYouTubeImportPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { return state.youtubeChannelImportPending; }); var selectYouTubeImportError = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { return state.youtubeChannelImportErrorMessage; }); +var selectSetReferrerPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { + return state.setReferrerIsPending; +}); +var selectSetReferrerError = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { + return state.setReferrerError; +}); var selectYouTubeImportVideosComplete = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { var total = state.youtubeChannelImportTotal; var complete = state.youtubeChannelImportComplete || 0; @@ -4791,6 +4818,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doFetchAccessToken", function() { return doFetchAccessToken; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doUserIdentityVerify", function() { return doUserIdentityVerify; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doUserInviteNew", function() { return doUserInviteNew; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doUserSetReferrer", function() { return doUserSetReferrer; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doClaimYoutubeChannels", function() { return doClaimYoutubeChannels; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doCheckYoutubeTransfer", function() { return doCheckYoutubeTransfer; }); /* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4); @@ -4830,7 +4858,8 @@ function doFetchInviteStatus() { data: { invitesRemaining: status.invites_remaining ? status.invites_remaining : 0, invitees: status.invitees, - referralLink: "".concat(lbryio__WEBPACK_IMPORTED_MODULE_5__["default"].CONNECTION_STRING, "user/refer?r=").concat(code) + referralLink: "".concat(lbryio__WEBPACK_IMPORTED_MODULE_5__["default"].CONNECTION_STRING, "user/refer?r=").concat(code), + referralCode: code } }); })["catch"](function (error) { @@ -4873,12 +4902,12 @@ function doAuthenticate(appVersion) { dispatch({ type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["AUTHENTICATION_STARTED"] }); - lbryio__WEBPACK_IMPORTED_MODULE_5__["default"].authenticate().then(function (user) { + lbryio__WEBPACK_IMPORTED_MODULE_5__["default"].authenticate().then(function (accessToken) { // analytics.setUser(user); dispatch({ type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["AUTHENTICATION_SUCCESS"], data: { - user: user + accessToken: accessToken } }); dispatch(Object(redux_actions_rewards__WEBPACK_IMPORTED_MODULE_2__["doRewardList"])()); @@ -5177,9 +5206,9 @@ function doUserInviteNew(email) { dispatch({ type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["USER_INVITE_NEW_STARTED"] }); - lbryio__WEBPACK_IMPORTED_MODULE_5__["default"].call('user', 'invite', { + return lbryio__WEBPACK_IMPORTED_MODULE_5__["default"].call('user', 'invite', { email: email - }, 'post').then(function () { + }, 'post').then(function (success) { dispatch({ type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["USER_INVITE_NEW_SUCCESS"], data: { @@ -5190,6 +5219,7 @@ function doUserInviteNew(email) { message: __("Invite sent to ".concat(email)) })); dispatch(doFetchInviteStatus()); + return success; })["catch"](function (error) { dispatch({ type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["USER_INVITE_NEW_FAILURE"], @@ -5200,6 +5230,38 @@ function doUserInviteNew(email) { }); }; } +function doUserSetReferrer(referrer, shouldClaim) { + return function (dispatch) { + dispatch({ + type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["USER_SET_REFERRER_STARTED"] + }); + return lbryio__WEBPACK_IMPORTED_MODULE_5__["default"].call('user', 'referral', { + referrer: referrer + }, 'post').then(function () { + dispatch({ + type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["USER_SET_REFERRER_SUCCESS"] + }); // for testing + + dispatch(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_0__["doToast"])({ + message: __("Set Referrer to ".concat(referrer)) + })); // we need to userFetch because once you claim this, + + if (shouldClaim) { + dispatch(Object(redux_actions_rewards__WEBPACK_IMPORTED_MODULE_2__["doClaimRewardType"])(rewards__WEBPACK_IMPORTED_MODULE_4__["default"].TYPE_REFEREE)); + dispatch(doUserFetch()); + } else { + dispatch(doUserFetch()); + } + })["catch"](function (error) { + dispatch({ + type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["USER_SET_REFERRER_FAILURE"], + data: { + error: error + } + }); + }); + }; +} function doClaimYoutubeChannels() { return function (dispatch) { dispatch({ @@ -6629,16 +6691,21 @@ var defaultState = { inviteStatusIsPending: false, invitesRemaining: undefined, invitees: undefined, + referralLink: undefined, + referralCode: undefined, user: undefined, + accessToken: undefined, youtubeChannelImportPending: false, - youtubeChannelImportErrorMessage: '' + youtubeChannelImportErrorMessage: '', + setReferrerIsPending: false, + setReferrerError: '' }; reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["AUTHENTICATION_STARTED"]] = function (state) { return Object.assign({}, state, { authenticationIsPending: true, userIsPending: true, - user: defaultState.user + accessToken: defaultState.accessToken }); }; @@ -6646,7 +6713,7 @@ reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["AUTHENTICATION_SUC return Object.assign({}, state, { authenticationIsPending: false, userIsPending: false, - user: action.data.user + accessToken: action.data.accessToken }); }; @@ -6832,7 +6899,8 @@ reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["USER_INVITE_STATUS inviteStatusIsPending: false, invitesRemaining: action.data.invitesRemaining, invitees: action.data.invitees, - referralLink: action.data.referralLink + referralLink: action.data.referralLink, + referralCode: action.data.referralCode }); }; @@ -6912,6 +6980,27 @@ reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["USER_EMAIL_VERIFY_ }); }; +reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["USER_SET_REFERRER_STARTED"]] = function (state) { + return Object.assign({}, state, { + setReferrerIsPending: true, + setReferrerError: defaultState.setReferrerError + }); +}; + +reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["USER_SET_REFERRER_SUCCESS"]] = function (state) { + return Object.assign({}, state, { + setReferrerIsPending: false, + setReferrerError: defaultState.setReferrerError + }); +}; + +reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["USER_SET_REFERRER_FAILURE"]] = function (state, action) { + return Object.assign({}, state, { + setReferrerIsPending: false, + setReferrerError: action.data.error.message + }); +}; + function userReducer() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; var action = arguments.length > 1 ? arguments[1] : undefined; diff --git a/src/constants/action_types.js b/src/constants/action_types.js index 45b759f..d2615ed 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -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'; diff --git a/src/index.js b/src/index.js index 7c5509b..b4109bc 100644 --- a/src/index.js +++ b/src/index.js @@ -63,6 +63,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 +163,14 @@ export { selectUserInviteNewIsPending, selectUserInviteNewErrorMessage, selectUserInviteReferralLink, + selectUserInviteReferralCode, selectUserVerifiedEmail, selectYoutubeChannels, selectYouTubeImportPending, selectYouTubeImportError, selectYouTubeImportVideosComplete, + selectSetReferrerPending, + selectSetReferrerError, } from 'redux/selectors/user'; export { makeSelectFetchingCostInfoForUri, diff --git a/src/redux/actions/user.js b/src/redux/actions/user.js index 5b5d7c8..6ce67a5 100644 --- a/src/redux/actions/user.js +++ b/src/redux/actions/user.js @@ -25,6 +25,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 +64,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 +364,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 +378,7 @@ export function doUserInviteNew(email) { ); dispatch(doFetchInviteStatus()); + return success; }) .catch(error => { dispatch({ @@ -387,6 +389,40 @@ export function doUserInviteNew(email) { }; } +export function doUserSetReferrer(referrer, shouldClaim) { + return dispatch => { + dispatch({ + type: ACTIONS.USER_SET_REFERRER_STARTED, + }); + + 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()); + } + }) + .catch(error => { + dispatch({ + type: ACTIONS.USER_SET_REFERRER_FAILURE, + data: { error }, + }); + }); + }; +} + export function doClaimYoutubeChannels() { return dispatch => { dispatch({ diff --git a/src/redux/reducers/user.js b/src/redux/reducers/user.js index 1de781a..2efd7d1 100644 --- a/src/redux/reducers/user.js +++ b/src/redux/reducers/user.js @@ -15,23 +15,28 @@ const defaultState = { inviteStatusIsPending: false, invitesRemaining: undefined, invitees: undefined, + referralLink: undefined, + referralCode: undefined, user: undefined, + accessToken: undefined, youtubeChannelImportPending: false, youtubeChannelImportErrorMessage: '', + setReferrerIsPending: false, + setReferrerError: '', }; 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, { + setReferrerIsPending: true, + setReferrerError: defaultState.setReferrerError, + }); + +reducers[ACTIONS.USER_SET_REFERRER_SUCCESS] = state => + Object.assign({}, state, { + setReferrerIsPending: false, + setReferrerError: defaultState.setReferrerError, + }); + +reducers[ACTIONS.USER_SET_REFERRER_FAILURE] = (state, action) => + Object.assign({}, state, { + setReferrerIsPending: false, + setReferrerError: action.data.error.message, + }); + export function userReducer(state = defaultState, action) { const handler = reducers[action.type]; if (handler) return handler(state, action); diff --git a/src/redux/selectors/user.js b/src/redux/selectors/user.js index 1857926..d6156c8 100644 --- a/src/redux/selectors/user.js +++ b/src/redux/selectors/user.js @@ -152,6 +152,11 @@ export const selectUserInviteReferralLink = createSelector( state => state.referralLink ); +export const selectUserInviteReferralCode = createSelector( + selectState, + state => state.referralCode +); + 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.setReferrerIsPending +); + +export const selectSetReferrerError = createSelector(selectState, state => state.setReferrerError); + export const selectYouTubeImportVideosComplete = createSelector(selectState, state => { const total = state.youtubeChannelImportTotal; const complete = state.youtubeChannelImportComplete || 0; diff --git a/src/rewards.js b/src/rewards.js index 3da7418..e9deb92 100644 --- a/src/rewards.js +++ b/src/rewards.js @@ -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';