Merge pull request #57 from lbryio/youtubeChannels

related to claiming youtube channels
This commit is contained in:
Sean Yesmunt 2019-09-23 11:18:27 -04:00 committed by GitHub
commit ebc8122c99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 230 additions and 3 deletions

61
dist/bundle.es.js vendored
View file

@ -972,6 +972,7 @@ const selectUserPhone = reselect.createSelector(selectUser, user => user ? user.
const selectUserCountryCode = reselect.createSelector(selectUser, user => user ? user.country_code : null);
const selectEmailToVerify = reselect.createSelector(selectState$2, selectUserEmail, (state, userEmail) => state.emailToVerify || userEmail);
const selectPhoneToVerify = reselect.createSelector(selectState$2, selectUserPhone, (state, userPhone) => state.phoneToVerify || userPhone);
const selectYoutubeChannels = reselect.createSelector(selectUser, user => user ? user.youtube_channels : null);
const selectUserIsRewardApproved = reselect.createSelector(selectUser, user => user && user.is_reward_approved);
const selectEmailNewIsPending = reselect.createSelector(selectState$2, state => state.emailNewIsPending);
const selectEmailNewErrorMessage = reselect.createSelector(selectState$2, state => state.emailNewErrorMessage);
@ -993,6 +994,8 @@ 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 selectYTImportPending = reselect.createSelector(selectState$2, state => state.ytChannelImportPending);
const selectYTImportError = reselect.createSelector(selectState$2, state => state.ytChannelImportErrorMessage);
function doFetchInviteStatus() {
return dispatch => {
@ -1364,6 +1367,41 @@ function doUserInviteNew(email) {
});
};
}
function doClaimYoutubeChannels() {
return dispatch => {
dispatch({
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_STARTED
});
lbryRedux.Lbry.address_list().then(addressList => addressList.sort((a, b) => a.used_times - b.used_times)[0]).then(address => Lbryio.call('yt', 'transfer', {
address: address.address,
public_key: address.pubkey
}).then(response => {
if (response && response.success) {
Promise.all(response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.channel_certificate) {
return lbryRedux.Lbry.channel_import({
channel_data: channelMeta.channel.channel_certificate
});
}
return null;
})).then(() => {
const actions = [{
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED
}];
actions.push(doUserFetch());
actions.push(lbryRedux.doFetchChannelListMine());
dispatch(lbryRedux.batchActions(...actions));
});
}
})).catch(error => {
dispatch({
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_FAILURE,
data: String(error)
});
});
};
}
function doRewardList() {
return dispatch => {
@ -2454,7 +2492,9 @@ const defaultState$3 = {
inviteStatusIsPending: false,
invitesRemaining: undefined,
invitees: undefined,
user: undefined
user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
};
reducers$2[lbryRedux.ACTIONS.AUTHENTICATION_STARTED] = state => Object.assign({}, state, {
@ -2636,6 +2676,21 @@ reducers$2[lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = state => Object
invitees: null
});
reducers$2[lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_STARTED] = state => Object.assign({}, state, {
ytChannelImportPending: true,
ytChannelImportErrorMessage: ''
});
reducers$2[lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED] = state => Object.assign({}, state, {
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
});
reducers$2[lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_FAILURE] = (state, action) => Object.assign({}, state, {
ytChannelImportPending: false,
ytChannelImportErrorMessage: action.data
});
function userReducer(state = defaultState$3, action) {
const handler = reducers$2[action.type];
if (handler) return handler(state, action);
@ -2923,6 +2978,7 @@ exports.doCheckSync = doCheckSync;
exports.doClaimEligiblePurchaseRewards = doClaimEligiblePurchaseRewards;
exports.doClaimRewardClearError = doClaimRewardClearError;
exports.doClaimRewardType = doClaimRewardType;
exports.doClaimYoutubeChannels = doClaimYoutubeChannels;
exports.doCompleteFirstRun = doCompleteFirstRun;
exports.doFetchAccessToken = doFetchAccessToken;
exports.doFetchCostInfoForUri = doFetchCostInfoForUri;
@ -3046,6 +3102,9 @@ exports.selectUserIsVerificationCandidate = selectUserIsVerificationCandidate;
exports.selectUserPhone = selectUserPhone;
exports.selectUserVerifiedEmail = selectUserVerifiedEmail;
exports.selectViewMode = selectViewMode;
exports.selectYTImportError = selectYTImportError;
exports.selectYTImportPending = selectYTImportPending;
exports.selectYoutubeChannels = selectYoutubeChannels;
exports.setSubscriptionLatest = setSubscriptionLatest;
exports.statsReducer = statsReducer;
exports.subscriptionsReducer = subscriptions;

87
dist/bundle.js vendored
View file

@ -196,6 +196,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doUserInviteNew", function() { return redux_actions_user__WEBPACK_IMPORTED_MODULE_8__["doUserInviteNew"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doClaimYoutubeChannels", function() { return redux_actions_user__WEBPACK_IMPORTED_MODULE_8__["doClaimYoutubeChannels"]; });
/* harmony import */ var redux_actions_cost_info__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(22);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchCostInfoForUri", function() { return redux_actions_cost_info__WEBPACK_IMPORTED_MODULE_9__["doFetchCostInfoForUri"]; });
@ -381,6 +383,12 @@ __webpack_require__.r(__webpack_exports__);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectUserVerifiedEmail", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_27__["selectUserVerifiedEmail"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYoutubeChannels", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_27__["selectYoutubeChannels"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYTImportPending", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_27__["selectYTImportPending"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYTImportError", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_27__["selectYTImportError"]; });
/* harmony import */ var redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(38);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectFetchingCostInfoForUri", function() { return redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_28__["makeSelectFetchingCostInfoForUri"]; });
@ -2261,6 +2269,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectUserCountryCode", function() { return selectUserCountryCode; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectEmailToVerify", function() { return selectEmailToVerify; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectPhoneToVerify", function() { return selectPhoneToVerify; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectYoutubeChannels", function() { return selectYoutubeChannels; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectUserIsRewardApproved", function() { return selectUserIsRewardApproved; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectEmailNewIsPending", function() { return selectEmailNewIsPending; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectEmailNewErrorMessage", function() { return selectEmailNewErrorMessage; });
@ -2282,6 +2291,8 @@ __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__, "selectYTImportPending", function() { return selectYTImportPending; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectYTImportError", function() { return selectYTImportError; });
/* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(13);
/* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__);
@ -2312,6 +2323,9 @@ var selectEmailToVerify = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSe
var selectPhoneToVerify = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, selectUserPhone, function (state, userPhone) {
return state.phoneToVerify || userPhone;
});
var selectYoutubeChannels = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectUser, function (user) {
return user ? user.youtube_channels : null;
});
var selectUserIsRewardApproved = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectUser, function (user) {
return user && user.is_reward_approved;
});
@ -2375,6 +2389,12 @@ var selectUserInviteNewErrorMessage = Object(reselect__WEBPACK_IMPORTED_MODULE_0
var selectUserInviteReferralLink = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.referralLink;
});
var selectYTImportPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.ytChannelImportPending;
});
var selectYTImportError = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.ytChannelImportErrorMessage;
});
/***/ }),
/* 19 */
@ -2399,6 +2419,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__, "doClaimYoutubeChannels", function() { return doClaimYoutubeChannels; });
/* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
/* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lbry_redux__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var redux_actions_rewards__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(16);
@ -2800,6 +2821,47 @@ function doUserInviteNew(email) {
});
};
}
function doClaimYoutubeChannels() {
return function (dispatch) {
dispatch({
type: lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_STARTED
});
lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].address_list().then(function (addressList) {
return addressList.sort(function (a, b) {
return a.used_times - b.used_times;
})[0];
}).then(function (address) {
return lbryio__WEBPACK_IMPORTED_MODULE_4__["default"].call('yt', 'transfer', {
address: address.address,
public_key: address.pubkey
}).then(function (response) {
if (response && response.success) {
Promise.all(response.map(function (channelMeta) {
if (channelMeta && channelMeta.channel && channelMeta.channel.channel_certificate) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].channel_import({
channel_data: channelMeta.channel.channel_certificate
});
}
return null;
})).then(function () {
var actions = [{
type: lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_COMPLETED
}];
actions.push(doUserFetch());
actions.push(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_0__["doFetchChannelListMine"])());
dispatch(lbry_redux__WEBPACK_IMPORTED_MODULE_0__["batchActions"].apply(void 0, actions));
});
}
});
})["catch"](function (error) {
dispatch({
type: lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_FAILURE,
data: String(error)
});
});
};
}
/***/ }),
/* 20 */
@ -4014,7 +4076,9 @@ var defaultState = {
inviteStatusIsPending: false,
invitesRemaining: undefined,
invitees: undefined,
user: undefined
user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
};
reducers[lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].AUTHENTICATION_STARTED] = function (state) {
@ -4248,6 +4312,27 @@ reducers[lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_INVITE_STATUS_F
});
};
reducers[lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_STARTED] = function (state) {
return Object.assign({}, state, {
ytChannelImportPending: true,
ytChannelImportErrorMessage: ''
});
};
reducers[lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_COMPLETED] = function (state) {
return Object.assign({}, state, {
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
});
};
reducers[lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_FAILURE] = function (state, action) {
return Object.assign({}, state, {
ytChannelImportPending: false,
ytChannelImportErrorMessage: action.data
});
};
function userReducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments.length > 1 ? arguments[1] : undefined;

View file

@ -57,6 +57,7 @@ export {
doUserResendVerificationEmail,
doUserIdentityVerify,
doUserInviteNew,
doClaimYoutubeChannels,
} from 'redux/actions/user';
export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
@ -151,6 +152,9 @@ export {
selectUserInviteNewErrorMessage,
selectUserInviteReferralLink,
selectUserVerifiedEmail,
selectYoutubeChannels,
selectYTImportPending,
selectYTImportError,
} from 'redux/selectors/user';
export {
makeSelectFetchingCostInfoForUri,

View file

@ -1,4 +1,4 @@
import { ACTIONS, Lbry, doToast } from 'lbry-redux';
import { ACTIONS, Lbry, doToast, doFetchChannelListMine, batchActions } from 'lbry-redux';
import { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
import {
selectEmailToVerify,
@ -382,3 +382,47 @@ export function doUserInviteNew(email) {
});
};
}
export function doClaimYoutubeChannels() {
return dispatch => {
dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_STARTED,
});
Lbry.address_list()
.then(addressList => addressList.sort((a, b) => a.used_times - b.used_times)[0])
.then(address =>
Lbryio.call('yt', 'transfer', {
address: address.address,
public_key: address.pubkey,
}).then(response => {
if (response && response.success) {
Promise.all(
response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.channel_certificate) {
return Lbry.channel_import({
channel_data: channelMeta.channel.channel_certificate,
});
}
return null;
})
).then(() => {
const actions = [
{
type: ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED,
},
];
actions.push(doUserFetch());
actions.push(doFetchChannelListMine());
dispatch(batchActions(...actions));
});
}
})
)
.catch(error => {
dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_FAILURE,
data: String(error),
});
});
};
}

View file

@ -14,6 +14,8 @@ const defaultState = {
invitesRemaining: undefined,
invitees: undefined,
user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: '',
};
reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
@ -221,6 +223,24 @@ reducers[ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = state =>
invitees: null,
});
reducers[ACTIONS.USER_YOUTUBE_IMPORT_STARTED] = state =>
Object.assign({}, state, {
ytChannelImportPending: true,
ytChannelImportErrorMessage: '',
});
reducers[ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED] = state =>
Object.assign({}, state, {
ytChannelImportPending: false,
ytChannelImportErrorMessage: '',
});
reducers[ACTIONS.USER_YOUTUBE_IMPORT_FAILURE] = (state, action) =>
Object.assign({}, state, {
ytChannelImportPending: false,
ytChannelImportErrorMessage: action.data,
});
export function userReducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);

View file

@ -38,6 +38,11 @@ export const selectPhoneToVerify = createSelector(
(state, userPhone) => state.phoneToVerify || userPhone
);
export const selectYoutubeChannels = createSelector(
selectUser,
user => (user ? user.youtube_channels : null)
);
export const selectUserIsRewardApproved = createSelector(
selectUser,
user => user && user.is_reward_approved
@ -136,3 +141,13 @@ export const selectUserInviteReferralLink = createSelector(
selectState,
state => state.referralLink
);
export const selectYTImportPending = createSelector(
selectState,
state => state.ytChannelImportPending
);
export const selectYTImportError = createSelector(
selectState,
state => state.ytChannelImportErrorMessage
);