From faf8271cac9a66e1b1fb3642ba7e6e48e89f6ef0 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 1 Feb 2019 12:19:45 -0500 Subject: [PATCH 1/4] update: call doFetchInviteStatus after claiming referral reward --- dist/bundle.js | 250 ++++++++++++++++++----------------- src/redux/actions/rewards.js | 3 + 2 files changed, 130 insertions(+), 123 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 8f2aeac..9a64a94 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -148,7 +148,7 @@ Object.defineProperty(exports, 'doFetchRewardedContent', { } }); -var _user = __webpack_require__(13); +var _user = __webpack_require__(12); Object.defineProperty(exports, 'doFetchInviteStatus', { enumerable: true, @@ -573,7 +573,7 @@ var _lbryio = __webpack_require__(3); var _lbryio2 = _interopRequireDefault(_lbryio); -var _rewards4 = __webpack_require__(12); +var _rewards4 = __webpack_require__(13); var _rewards5 = _interopRequireDefault(_rewards4); @@ -7957,7 +7957,9 @@ var _rewards = __webpack_require__(9); var _user = __webpack_require__(11); -var _rewards2 = __webpack_require__(12); +var _user2 = __webpack_require__(12); + +var _rewards2 = __webpack_require__(13); var _rewards3 = _interopRequireDefault(_rewards2); @@ -8027,6 +8029,8 @@ function doClaimRewardType(rewardType) { }); if (successReward.reward_type === _rewards3.default.TYPE_NEW_USER && _rewards3.default.callbacks.claimFirstRewardSuccess) { _rewards3.default.callbacks.claimFirstRewardSuccess(); + } else if (successReward.reward_type === _rewards3.default.TYPE_REFERRAL) { + dispatch((0, _user2.doFetchInviteStatus)()); } dispatch(doRewardList()); @@ -8473,125 +8477,6 @@ var selectUserInviteNewErrorMessage = exports.selectUserInviteNewErrorMessage = "use strict"; -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; - -var _lbryRedux = __webpack_require__(4); - -var _lbryio = __webpack_require__(3); - -var _lbryio2 = _interopRequireDefault(_lbryio); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var rewards = {}; - -rewards.TYPE_NEW_DEVELOPER = 'new_developer'; -rewards.TYPE_NEW_USER = 'new_user'; -rewards.TYPE_CONFIRM_EMAIL = 'verified_email'; -rewards.TYPE_FIRST_CHANNEL = 'new_channel'; -rewards.TYPE_FIRST_STREAM = 'first_stream'; -rewards.TYPE_MANY_DOWNLOADS = 'many_downloads'; -rewards.TYPE_FIRST_PUBLISH = 'first_publish'; -rewards.TYPE_FEATURED_DOWNLOAD = 'featured_download'; -rewards.TYPE_REFERRAL = 'referral'; -rewards.TYPE_REWARD_CODE = 'reward_code'; -rewards.TYPE_SUBSCRIPTION = 'subscription'; -rewards.YOUTUBE_CREATOR = 'youtube_creator'; - -rewards.claimReward = function (type, rewardParams) { - function requestReward(resolve, reject, params) { - if (!_lbryio2.default.enabled) { - reject(new Error(__('Rewards are not enabled.'))); - return; - } - - _lbryio2.default.call('reward', 'new', params, 'post').then(function (reward) { - var message = reward.reward_notification || 'You have claimed a ' + reward.reward_amount + ' LBC reward.'; - - // Display global notice - var action = (0, _lbryRedux.doToast)({ - message: message, - linkText: __('Show All'), - linkTarget: '/rewards' - }); - window.store.dispatch(action); - - if (rewards.callbacks.claimRewardSuccess) { - rewards.callbacks.claimRewardSuccess(); - } - - resolve(reward); - }, reject); - } - - return new Promise(function (resolve, reject) { - _lbryRedux.Lbry.address_unused().then(function (address) { - var params = _extends({ - reward_type: type, - wallet_address: address - }, rewardParams); - - switch (type) { - case rewards.TYPE_FIRST_CHANNEL: - _lbryRedux.Lbry.claim_list_mine().then(function (claims) { - var claim = claims.find(function (foundClaim) { - return foundClaim.name.length && foundClaim.name[0] === '@' && foundClaim.txid.length && foundClaim.type === 'claim'; - }); - if (claim) { - params.transaction_id = claim.txid; - requestReward(resolve, reject, params); - } else { - reject(new Error(__('Please create a channel identity first.'))); - } - }).catch(reject); - break; - - case rewards.TYPE_FIRST_PUBLISH: - _lbryRedux.Lbry.claim_list_mine().then(function (claims) { - var claim = claims.find(function (foundClaim) { - return foundClaim.name.length && foundClaim.name[0] !== '@' && foundClaim.txid.length && foundClaim.type === 'claim'; - }); - if (claim) { - params.transaction_id = claim.txid; - requestReward(resolve, reject, params); - } else { - reject(claims.length ? new Error(__('Please publish something and wait for confirmation by the network to claim this reward.')) : new Error(__('Please publish something to claim this reward.'))); - } - }).catch(reject); - break; - - case rewards.TYPE_FIRST_STREAM: - case rewards.TYPE_NEW_USER: - default: - requestReward(resolve, reject, params); - } - }); - }); -}; -rewards.callbacks = { - // Set any callbacks that require code not found in this project - claimRewardSuccess: null, - claimFirstRewardSuccess: null, - rewardApprovalRequired: null -}; - -rewards.setCallback = function (name, method) { - rewards.callbacks[name] = method; -}; - -exports.default = rewards; - -/***/ }), -/* 13 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - Object.defineProperty(exports, "__esModule", { value: true }); @@ -8619,7 +8504,7 @@ var _rewards = __webpack_require__(8); var _user = __webpack_require__(11); -var _rewards2 = __webpack_require__(12); +var _rewards2 = __webpack_require__(13); var _rewards3 = _interopRequireDefault(_rewards2); @@ -8970,6 +8855,125 @@ function doUserInviteNew(email) { }; } +/***/ }), +/* 13 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _lbryRedux = __webpack_require__(4); + +var _lbryio = __webpack_require__(3); + +var _lbryio2 = _interopRequireDefault(_lbryio); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var rewards = {}; + +rewards.TYPE_NEW_DEVELOPER = 'new_developer'; +rewards.TYPE_NEW_USER = 'new_user'; +rewards.TYPE_CONFIRM_EMAIL = 'verified_email'; +rewards.TYPE_FIRST_CHANNEL = 'new_channel'; +rewards.TYPE_FIRST_STREAM = 'first_stream'; +rewards.TYPE_MANY_DOWNLOADS = 'many_downloads'; +rewards.TYPE_FIRST_PUBLISH = 'first_publish'; +rewards.TYPE_FEATURED_DOWNLOAD = 'featured_download'; +rewards.TYPE_REFERRAL = 'referral'; +rewards.TYPE_REWARD_CODE = 'reward_code'; +rewards.TYPE_SUBSCRIPTION = 'subscription'; +rewards.YOUTUBE_CREATOR = 'youtube_creator'; + +rewards.claimReward = function (type, rewardParams) { + function requestReward(resolve, reject, params) { + if (!_lbryio2.default.enabled) { + reject(new Error(__('Rewards are not enabled.'))); + return; + } + + _lbryio2.default.call('reward', 'new', params, 'post').then(function (reward) { + var message = reward.reward_notification || 'You have claimed a ' + reward.reward_amount + ' LBC reward.'; + + // Display global notice + var action = (0, _lbryRedux.doToast)({ + message: message, + linkText: __('Show All'), + linkTarget: '/rewards' + }); + window.store.dispatch(action); + + if (rewards.callbacks.claimRewardSuccess) { + rewards.callbacks.claimRewardSuccess(); + } + + resolve(reward); + }, reject); + } + + return new Promise(function (resolve, reject) { + _lbryRedux.Lbry.address_unused().then(function (address) { + var params = _extends({ + reward_type: type, + wallet_address: address + }, rewardParams); + + switch (type) { + case rewards.TYPE_FIRST_CHANNEL: + _lbryRedux.Lbry.claim_list_mine().then(function (claims) { + var claim = claims.find(function (foundClaim) { + return foundClaim.name.length && foundClaim.name[0] === '@' && foundClaim.txid.length && foundClaim.type === 'claim'; + }); + if (claim) { + params.transaction_id = claim.txid; + requestReward(resolve, reject, params); + } else { + reject(new Error(__('Please create a channel identity first.'))); + } + }).catch(reject); + break; + + case rewards.TYPE_FIRST_PUBLISH: + _lbryRedux.Lbry.claim_list_mine().then(function (claims) { + var claim = claims.find(function (foundClaim) { + return foundClaim.name.length && foundClaim.name[0] !== '@' && foundClaim.txid.length && foundClaim.type === 'claim'; + }); + if (claim) { + params.transaction_id = claim.txid; + requestReward(resolve, reject, params); + } else { + reject(claims.length ? new Error(__('Please publish something and wait for confirmation by the network to claim this reward.')) : new Error(__('Please publish something to claim this reward.'))); + } + }).catch(reject); + break; + + case rewards.TYPE_FIRST_STREAM: + case rewards.TYPE_NEW_USER: + default: + requestReward(resolve, reject, params); + } + }); + }); +}; +rewards.callbacks = { + // Set any callbacks that require code not found in this project + claimRewardSuccess: null, + claimFirstRewardSuccess: null, + rewardApprovalRequired: null +}; + +rewards.setCallback = function (name, method) { + rewards.callbacks[name] = method; +}; + +exports.default = rewards; + /***/ }), /* 14 */ /***/ (function(module, exports, __webpack_require__) { diff --git a/src/redux/actions/rewards.js b/src/redux/actions/rewards.js index d9f6369..4a0df89 100644 --- a/src/redux/actions/rewards.js +++ b/src/redux/actions/rewards.js @@ -2,6 +2,7 @@ import Lbryio from 'lbryio'; import { ACTIONS, doError } from 'lbry-redux'; import { selectUnclaimedRewards } from 'redux/selectors/rewards'; import { selectUserIsRewardApproved } from 'redux/selectors/user'; +import { doFetchInviteStatus } from 'redux/actions/user'; import rewards from 'rewards'; export function doRewardList() { @@ -72,6 +73,8 @@ export function doClaimRewardType(rewardType, options = {}) { rewards.callbacks.claimFirstRewardSuccess ) { rewards.callbacks.claimFirstRewardSuccess(); + } else if (successReward.reward_type === rewards.TYPE_REFERRAL) { + dispatch(doFetchInviteStatus()); } dispatch(doRewardList()); -- 2.45.2 From 0cc1b6d78d4a76e81fcaac4e47569f04b6f719b9 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Sun, 3 Feb 2019 22:21:44 -0500 Subject: [PATCH 2/4] add selectReferralReward selector --- dist/bundle.js | 278 ++++++++++++++++++--------------- src/index.js | 1 + src/redux/selectors/rewards.js | 7 + 3 files changed, 156 insertions(+), 130 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 9a64a94..9a39448 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -104,7 +104,7 @@ return /******/ (function(modules) { // webpackBootstrap Object.defineProperty(exports, "__esModule", { value: true }); -exports.selectUserInviteNewErrorMessage = exports.selectUserInviteNewIsPending = exports.selectUserInviteStatusFailed = exports.selectUserInvitees = exports.selectUserInvitesRemaining = exports.selectUserInviteStatusIsPending = exports.selectAccessToken = exports.selectUserIsVerificationCandidate = exports.selectIdentityVerifyErrorMessage = exports.selectIdentityVerifyIsPending = exports.selectPhoneVerifyIsPending = exports.selectPhoneVerifyErrorMessage = exports.selectEmailVerifyErrorMessage = exports.selectEmailVerifyIsPending = exports.selectPhoneNewIsPending = exports.selectPhoneNewErrorMessage = exports.selectEmailNewErrorMessage = exports.selectEmailNewIsPending = exports.selectUserIsRewardApproved = exports.selectPhoneToVerify = exports.selectEmailToVerify = exports.selectUserCountryCode = exports.selectUserPhone = exports.selectUserEmail = exports.selectUser = exports.selectUserIsPending = exports.selectAuthenticationIsPending = exports.selectRewardContentClaimIds = exports.selectRewardByType = exports.selectClaimRewardError = exports.selectClaimErrorsByType = exports.selectIsClaimRewardPending = exports.selectClaimsPendingByType = exports.selectUnclaimedRewardValue = exports.selectFetchingRewards = exports.selectUnclaimedRewards = exports.selectClaimedRewardsByTransactionId = exports.selectClaimedRewards = exports.selectClaimedRewardsById = exports.selectUnclaimedRewardsByType = exports.makeSelectRewardByType = exports.makeSelectRewardAmountByType = exports.makeSelectIsRewardClaimPending = exports.makeSelectClaimRewardError = exports.selectIsAuthenticating = exports.selectAuthToken = exports.userReducer = exports.rewardsReducer = exports.authReducer = exports.doUserInviteNew = exports.doUserIdentityVerify = exports.doUserResendVerificationEmail = exports.doFetchAccessToken = exports.doUserPhoneVerify = exports.doUserPhoneVerifyFailure = exports.doUserPhoneReset = exports.doUserPhoneNew = exports.doUserEmailVerify = exports.doUserEmailVerifyFailure = exports.doUserEmailToVerify = exports.doUserCheckEmailVerified = exports.doUserEmailNew = exports.doUserFetch = exports.doAuthenticate = exports.doInstallNew = exports.doFetchInviteStatus = exports.doFetchRewardedContent = exports.doClaimRewardClearError = exports.doClaimEligiblePurchaseRewards = exports.doClaimRewardType = exports.doRewardList = exports.doGenerateAuthToken = exports.rewards = exports.Lbryio = exports.LBRYINC_ACTIONS = undefined; +exports.selectUserInviteNewErrorMessage = exports.selectUserInviteNewIsPending = exports.selectUserInviteStatusFailed = exports.selectUserInvitees = exports.selectUserInvitesRemaining = exports.selectUserInviteStatusIsPending = exports.selectAccessToken = exports.selectUserIsVerificationCandidate = exports.selectIdentityVerifyErrorMessage = exports.selectIdentityVerifyIsPending = exports.selectPhoneVerifyIsPending = exports.selectPhoneVerifyErrorMessage = exports.selectEmailVerifyErrorMessage = exports.selectEmailVerifyIsPending = exports.selectPhoneNewIsPending = exports.selectPhoneNewErrorMessage = exports.selectEmailNewErrorMessage = exports.selectEmailNewIsPending = exports.selectUserIsRewardApproved = exports.selectPhoneToVerify = exports.selectEmailToVerify = exports.selectUserCountryCode = exports.selectUserPhone = exports.selectUserEmail = exports.selectUser = exports.selectUserIsPending = exports.selectAuthenticationIsPending = exports.selectReferralReward = exports.selectRewardContentClaimIds = exports.selectRewardByType = exports.selectClaimRewardError = exports.selectClaimErrorsByType = exports.selectIsClaimRewardPending = exports.selectClaimsPendingByType = exports.selectUnclaimedRewardValue = exports.selectFetchingRewards = exports.selectUnclaimedRewards = exports.selectClaimedRewardsByTransactionId = exports.selectClaimedRewards = exports.selectClaimedRewardsById = exports.selectUnclaimedRewardsByType = exports.makeSelectRewardByType = exports.makeSelectRewardAmountByType = exports.makeSelectIsRewardClaimPending = exports.makeSelectClaimRewardError = exports.selectIsAuthenticating = exports.selectAuthToken = exports.userReducer = exports.rewardsReducer = exports.authReducer = exports.doUserInviteNew = exports.doUserIdentityVerify = exports.doUserResendVerificationEmail = exports.doFetchAccessToken = exports.doUserPhoneVerify = exports.doUserPhoneVerifyFailure = exports.doUserPhoneReset = exports.doUserPhoneNew = exports.doUserEmailVerify = exports.doUserEmailVerifyFailure = exports.doUserEmailToVerify = exports.doUserCheckEmailVerified = exports.doUserEmailNew = exports.doUserFetch = exports.doAuthenticate = exports.doInstallNew = exports.doFetchInviteStatus = exports.doFetchRewardedContent = exports.doClaimRewardClearError = exports.doClaimEligiblePurchaseRewards = exports.doClaimRewardType = exports.doRewardList = exports.doGenerateAuthToken = exports.rewards = exports.Lbryio = exports.LBRYINC_ACTIONS = undefined; var _auth = __webpack_require__(1); @@ -148,7 +148,7 @@ Object.defineProperty(exports, 'doFetchRewardedContent', { } }); -var _user = __webpack_require__(12); +var _user = __webpack_require__(13); Object.defineProperty(exports, 'doFetchInviteStatus', { enumerable: true, @@ -399,8 +399,14 @@ Object.defineProperty(exports, 'selectRewardContentClaimIds', { return _rewards3.selectRewardContentClaimIds; } }); +Object.defineProperty(exports, 'selectReferralReward', { + enumerable: true, + get: function get() { + return _rewards3.selectReferralReward; + } +}); -var _user3 = __webpack_require__(11); +var _user3 = __webpack_require__(12); Object.defineProperty(exports, 'selectAuthenticationIsPending', { enumerable: true, @@ -573,7 +579,7 @@ var _lbryio = __webpack_require__(3); var _lbryio2 = _interopRequireDefault(_lbryio); -var _rewards4 = __webpack_require__(13); +var _rewards4 = __webpack_require__(11); var _rewards5 = _interopRequireDefault(_rewards4); @@ -7955,11 +7961,11 @@ var _lbryRedux = __webpack_require__(4); var _rewards = __webpack_require__(9); -var _user = __webpack_require__(11); +var _user = __webpack_require__(12); -var _user2 = __webpack_require__(12); +var _user2 = __webpack_require__(13); -var _rewards2 = __webpack_require__(13); +var _rewards2 = __webpack_require__(11); var _rewards3 = _interopRequireDefault(_rewards2); @@ -8121,10 +8127,16 @@ function doFetchRewardedContent() { Object.defineProperty(exports, "__esModule", { value: true }); -exports.selectRewardContentClaimIds = exports.makeSelectRewardAmountByType = exports.makeSelectRewardByType = exports.makeSelectClaimRewardError = exports.selectClaimErrorsByType = exports.makeSelectIsRewardClaimPending = exports.selectClaimsPendingByType = exports.selectUnclaimedRewardValue = exports.selectFetchingRewards = exports.selectUnclaimedRewards = exports.selectClaimedRewardsByTransactionId = exports.selectClaimedRewards = exports.selectClaimedRewardsById = exports.selectUnclaimedRewardsByType = undefined; +exports.selectReferralReward = exports.selectRewardContentClaimIds = exports.makeSelectRewardAmountByType = exports.makeSelectRewardByType = exports.makeSelectClaimRewardError = exports.selectClaimErrorsByType = exports.makeSelectIsRewardClaimPending = exports.selectClaimsPendingByType = exports.selectUnclaimedRewardValue = exports.selectFetchingRewards = exports.selectUnclaimedRewards = exports.selectClaimedRewardsByTransactionId = exports.selectClaimedRewards = exports.selectClaimedRewardsById = exports.selectUnclaimedRewardsByType = undefined; var _reselect = __webpack_require__(10); +var _rewards = __webpack_require__(11); + +var _rewards2 = _interopRequireDefault(_rewards); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + var selectState = function selectState(state) { return state.rewards || {}; }; @@ -8213,6 +8225,12 @@ var selectRewardContentClaimIds = exports.selectRewardContentClaimIds = (0, _res return state.rewardedContentClaimIds; }); +var selectReferralReward = exports.selectReferralReward = (0, _reselect.createSelector)(selectUnclaimedRewards, function (unclaimedRewards) { + return unclaimedRewards.filter(function (reward) { + return reward.reward_type === _rewards2.default.TYPE_REFERRAL; + })[0]; +}); + /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { @@ -8351,6 +8369,125 @@ function createStructuredSelector(selectors) { "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _lbryRedux = __webpack_require__(4); + +var _lbryio = __webpack_require__(3); + +var _lbryio2 = _interopRequireDefault(_lbryio); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var rewards = {}; + +rewards.TYPE_NEW_DEVELOPER = 'new_developer'; +rewards.TYPE_NEW_USER = 'new_user'; +rewards.TYPE_CONFIRM_EMAIL = 'verified_email'; +rewards.TYPE_FIRST_CHANNEL = 'new_channel'; +rewards.TYPE_FIRST_STREAM = 'first_stream'; +rewards.TYPE_MANY_DOWNLOADS = 'many_downloads'; +rewards.TYPE_FIRST_PUBLISH = 'first_publish'; +rewards.TYPE_FEATURED_DOWNLOAD = 'featured_download'; +rewards.TYPE_REFERRAL = 'referral'; +rewards.TYPE_REWARD_CODE = 'reward_code'; +rewards.TYPE_SUBSCRIPTION = 'subscription'; +rewards.YOUTUBE_CREATOR = 'youtube_creator'; + +rewards.claimReward = function (type, rewardParams) { + function requestReward(resolve, reject, params) { + if (!_lbryio2.default.enabled) { + reject(new Error(__('Rewards are not enabled.'))); + return; + } + + _lbryio2.default.call('reward', 'new', params, 'post').then(function (reward) { + var message = reward.reward_notification || 'You have claimed a ' + reward.reward_amount + ' LBC reward.'; + + // Display global notice + var action = (0, _lbryRedux.doToast)({ + message: message, + linkText: __('Show All'), + linkTarget: '/rewards' + }); + window.store.dispatch(action); + + if (rewards.callbacks.claimRewardSuccess) { + rewards.callbacks.claimRewardSuccess(); + } + + resolve(reward); + }, reject); + } + + return new Promise(function (resolve, reject) { + _lbryRedux.Lbry.address_unused().then(function (address) { + var params = _extends({ + reward_type: type, + wallet_address: address + }, rewardParams); + + switch (type) { + case rewards.TYPE_FIRST_CHANNEL: + _lbryRedux.Lbry.claim_list_mine().then(function (claims) { + var claim = claims.find(function (foundClaim) { + return foundClaim.name.length && foundClaim.name[0] === '@' && foundClaim.txid.length && foundClaim.type === 'claim'; + }); + if (claim) { + params.transaction_id = claim.txid; + requestReward(resolve, reject, params); + } else { + reject(new Error(__('Please create a channel identity first.'))); + } + }).catch(reject); + break; + + case rewards.TYPE_FIRST_PUBLISH: + _lbryRedux.Lbry.claim_list_mine().then(function (claims) { + var claim = claims.find(function (foundClaim) { + return foundClaim.name.length && foundClaim.name[0] !== '@' && foundClaim.txid.length && foundClaim.type === 'claim'; + }); + if (claim) { + params.transaction_id = claim.txid; + requestReward(resolve, reject, params); + } else { + reject(claims.length ? new Error(__('Please publish something and wait for confirmation by the network to claim this reward.')) : new Error(__('Please publish something to claim this reward.'))); + } + }).catch(reject); + break; + + case rewards.TYPE_FIRST_STREAM: + case rewards.TYPE_NEW_USER: + default: + requestReward(resolve, reject, params); + } + }); + }); +}; +rewards.callbacks = { + // Set any callbacks that require code not found in this project + claimRewardSuccess: null, + claimFirstRewardSuccess: null, + rewardApprovalRequired: null +}; + +rewards.setCallback = function (name, method) { + rewards.callbacks[name] = method; +}; + +exports.default = rewards; + +/***/ }), +/* 12 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + Object.defineProperty(exports, "__esModule", { value: true }); @@ -8471,7 +8608,7 @@ var selectUserInviteNewErrorMessage = exports.selectUserInviteNewErrorMessage = }); /***/ }), -/* 12 */ +/* 13 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -8502,9 +8639,9 @@ var _lbryRedux = __webpack_require__(4); var _rewards = __webpack_require__(8); -var _user = __webpack_require__(11); +var _user = __webpack_require__(12); -var _rewards2 = __webpack_require__(13); +var _rewards2 = __webpack_require__(11); var _rewards3 = _interopRequireDefault(_rewards2); @@ -8855,125 +8992,6 @@ function doUserInviteNew(email) { }; } -/***/ }), -/* 13 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; - -var _lbryRedux = __webpack_require__(4); - -var _lbryio = __webpack_require__(3); - -var _lbryio2 = _interopRequireDefault(_lbryio); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var rewards = {}; - -rewards.TYPE_NEW_DEVELOPER = 'new_developer'; -rewards.TYPE_NEW_USER = 'new_user'; -rewards.TYPE_CONFIRM_EMAIL = 'verified_email'; -rewards.TYPE_FIRST_CHANNEL = 'new_channel'; -rewards.TYPE_FIRST_STREAM = 'first_stream'; -rewards.TYPE_MANY_DOWNLOADS = 'many_downloads'; -rewards.TYPE_FIRST_PUBLISH = 'first_publish'; -rewards.TYPE_FEATURED_DOWNLOAD = 'featured_download'; -rewards.TYPE_REFERRAL = 'referral'; -rewards.TYPE_REWARD_CODE = 'reward_code'; -rewards.TYPE_SUBSCRIPTION = 'subscription'; -rewards.YOUTUBE_CREATOR = 'youtube_creator'; - -rewards.claimReward = function (type, rewardParams) { - function requestReward(resolve, reject, params) { - if (!_lbryio2.default.enabled) { - reject(new Error(__('Rewards are not enabled.'))); - return; - } - - _lbryio2.default.call('reward', 'new', params, 'post').then(function (reward) { - var message = reward.reward_notification || 'You have claimed a ' + reward.reward_amount + ' LBC reward.'; - - // Display global notice - var action = (0, _lbryRedux.doToast)({ - message: message, - linkText: __('Show All'), - linkTarget: '/rewards' - }); - window.store.dispatch(action); - - if (rewards.callbacks.claimRewardSuccess) { - rewards.callbacks.claimRewardSuccess(); - } - - resolve(reward); - }, reject); - } - - return new Promise(function (resolve, reject) { - _lbryRedux.Lbry.address_unused().then(function (address) { - var params = _extends({ - reward_type: type, - wallet_address: address - }, rewardParams); - - switch (type) { - case rewards.TYPE_FIRST_CHANNEL: - _lbryRedux.Lbry.claim_list_mine().then(function (claims) { - var claim = claims.find(function (foundClaim) { - return foundClaim.name.length && foundClaim.name[0] === '@' && foundClaim.txid.length && foundClaim.type === 'claim'; - }); - if (claim) { - params.transaction_id = claim.txid; - requestReward(resolve, reject, params); - } else { - reject(new Error(__('Please create a channel identity first.'))); - } - }).catch(reject); - break; - - case rewards.TYPE_FIRST_PUBLISH: - _lbryRedux.Lbry.claim_list_mine().then(function (claims) { - var claim = claims.find(function (foundClaim) { - return foundClaim.name.length && foundClaim.name[0] !== '@' && foundClaim.txid.length && foundClaim.type === 'claim'; - }); - if (claim) { - params.transaction_id = claim.txid; - requestReward(resolve, reject, params); - } else { - reject(claims.length ? new Error(__('Please publish something and wait for confirmation by the network to claim this reward.')) : new Error(__('Please publish something to claim this reward.'))); - } - }).catch(reject); - break; - - case rewards.TYPE_FIRST_STREAM: - case rewards.TYPE_NEW_USER: - default: - requestReward(resolve, reject, params); - } - }); - }); -}; -rewards.callbacks = { - // Set any callbacks that require code not found in this project - claimRewardSuccess: null, - claimFirstRewardSuccess: null, - rewardApprovalRequired: null -}; - -rewards.setCallback = function (name, method) { - rewards.callbacks[name] = method; -}; - -exports.default = rewards; - /***/ }), /* 14 */ /***/ (function(module, exports, __webpack_require__) { diff --git a/src/index.js b/src/index.js index 8258765..1e30c86 100644 --- a/src/index.js +++ b/src/index.js @@ -62,6 +62,7 @@ export { selectClaimRewardError, selectRewardByType, selectRewardContentClaimIds, + selectReferralReward, } from 'redux/selectors/rewards'; export { selectAuthenticationIsPending, diff --git a/src/redux/selectors/rewards.js b/src/redux/selectors/rewards.js index 56fa8fb..0977c3d 100644 --- a/src/redux/selectors/rewards.js +++ b/src/redux/selectors/rewards.js @@ -1,4 +1,5 @@ import { createSelector } from 'reselect'; +import REWARDS from 'rewards'; const selectState = state => state.rewards || {}; @@ -67,3 +68,9 @@ export const selectRewardContentClaimIds = createSelector( selectState, state => state.rewardedContentClaimIds ); + +export const selectReferralReward = createSelector( + selectUnclaimedRewards, + unclaimedRewards => + unclaimedRewards.filter(reward => reward.reward_type === REWARDS.TYPE_REFERRAL)[0] +); -- 2.45.2 From 375cc397d8c33cc335f1735c951741c15ae31181 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Sun, 3 Feb 2019 22:30:32 -0500 Subject: [PATCH 3/4] show error snackbar instead of modal for reward fail --- dist/bundle.js | 2 +- src/redux/actions/rewards.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 9a39448..656a41a 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -8052,7 +8052,7 @@ function doClaimRewardType(rewardType) { }); if (options.notifyError) { - dispatch((0, _lbryRedux.doError)(error.message)); + dispatch((0, _lbryRedux.doToast)({ message: error.message, isError: true })); } }; diff --git a/src/redux/actions/rewards.js b/src/redux/actions/rewards.js index 4a0df89..22eb19e 100644 --- a/src/redux/actions/rewards.js +++ b/src/redux/actions/rewards.js @@ -1,5 +1,5 @@ import Lbryio from 'lbryio'; -import { ACTIONS, doError } from 'lbry-redux'; +import { ACTIONS, doToast } from 'lbry-redux'; import { selectUnclaimedRewards } from 'redux/selectors/rewards'; import { selectUserIsRewardApproved } from 'redux/selectors/user'; import { doFetchInviteStatus } from 'redux/actions/user'; @@ -90,7 +90,7 @@ export function doClaimRewardType(rewardType, options = {}) { }); if (options.notifyError) { - dispatch(doError(error.message)); + dispatch(doToast({ message: error.message, isError: true })); } }; -- 2.45.2 From da78018f7253d5e73dbc86f2edae62d1ec173484 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 4 Feb 2019 12:03:26 -0500 Subject: [PATCH 4/4] call rewardList after invite status so rewards are updated based on invites --- dist/bundle.js | 2 ++ src/redux/actions/user.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/bundle.js b/dist/bundle.js index 656a41a..1e097a7 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -8658,6 +8658,8 @@ function doFetchInviteStatus() { }); _lbryio2.default.call('user', 'invite_status').then(function (status) { + dispatch((0, _rewards.doRewardList)()); + dispatch({ type: _lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS, data: { diff --git a/src/redux/actions/user.js b/src/redux/actions/user.js index 36bad29..ea199c2 100644 --- a/src/redux/actions/user.js +++ b/src/redux/actions/user.js @@ -16,6 +16,8 @@ export function doFetchInviteStatus() { Lbryio.call('user', 'invite_status') .then(status => { + dispatch(doRewardList()); + dispatch({ type: ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS, data: { -- 2.45.2