redux housekeeping for yt import pending and errors

This commit is contained in:
jessop 2019-09-17 17:01:10 -04:00
parent fb237c9186
commit 54d58414ce
6 changed files with 175 additions and 36 deletions

51
dist/bundle.es.js vendored
View file

@ -719,6 +719,8 @@ const selectUserInviteStatusFailed = reselect.createSelector(selectUserInvitesRe
const selectUserInviteNewIsPending = reselect.createSelector(selectState$1, state => state.inviteNewIsPending); const selectUserInviteNewIsPending = reselect.createSelector(selectState$1, state => state.inviteNewIsPending);
const selectUserInviteNewErrorMessage = reselect.createSelector(selectState$1, state => state.inviteNewErrorMessage); const selectUserInviteNewErrorMessage = reselect.createSelector(selectState$1, state => state.inviteNewErrorMessage);
const selectUserInviteReferralLink = reselect.createSelector(selectState$1, state => state.referralLink); const selectUserInviteReferralLink = reselect.createSelector(selectState$1, state => state.referralLink);
const selectYTImportPending = reselect.createSelector(selectState$1, state => state.ytChannelImportPending);
const selectYTImportError = reselect.createSelector(selectState$1, state => state.ytChannelImportErrorMessage);
function doFetchInviteStatus() { function doFetchInviteStatus() {
return dispatch => { return dispatch => {
@ -1092,11 +1094,14 @@ function doUserInviteNew(email) {
} }
function doClaimYoutubeChannels() { function doClaimYoutubeChannels() {
return dispatch => { return dispatch => {
lbryRedux.Lbry.address_unused().then(address => // add dispatch started here dispatch({
Lbryio.call('yt', 'transfer', { type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_STARTED
address });
lbryRedux.Lbry.address_list().then(addressList => addressList.find(el => el.used_times === 0)).then(address => Lbryio.call('yt', 'transfer', {
address: address.address,
public_key: address.public_key
}).then(response => { }).then(response => {
if (response && response.length) { if (response && response.success) {
Promise.all(response.map(channelMeta => { Promise.all(response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) { if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) {
return lbryRedux.Lbry.channel_import({ return lbryRedux.Lbry.channel_import({
@ -1105,9 +1110,22 @@ function doClaimYoutubeChannels() {
} }
return null; return null;
})).then(() => dispatch(doUserFetch())); // update the channel data the form uses })).then(() => {
const actions = [{
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED
}];
actions.push(doUserFetch());
actions.push(lbryRedux.doFetchChannelListMine());
dispatch(lbryRedux.batchActions(...actions));
});
} }
})).catch(e => console.error('Transfering channels failed', e)); })).catch(error => {
console.error('Youtube import error:', error);
dispatch({
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_FAILURE,
data: String(error)
});
});
}; };
} }
@ -2403,7 +2421,9 @@ const defaultState$3 = {
inviteStatusIsPending: false, inviteStatusIsPending: false,
invitesRemaining: undefined, invitesRemaining: undefined,
invitees: undefined, invitees: undefined,
user: undefined user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
}; };
reducers$2[lbryRedux.ACTIONS.AUTHENTICATION_STARTED] = state => Object.assign({}, state, { reducers$2[lbryRedux.ACTIONS.AUTHENTICATION_STARTED] = state => Object.assign({}, state, {
@ -2584,6 +2604,21 @@ reducers$2[lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = state => Object
invitees: null 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) { function userReducer(state = defaultState$3, action) {
const handler = reducers$2[action.type]; const handler = reducers$2[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);
@ -2994,6 +3029,8 @@ exports.selectUserIsRewardApproved = selectUserIsRewardApproved;
exports.selectUserIsVerificationCandidate = selectUserIsVerificationCandidate; exports.selectUserIsVerificationCandidate = selectUserIsVerificationCandidate;
exports.selectUserPhone = selectUserPhone; exports.selectUserPhone = selectUserPhone;
exports.selectViewMode = selectViewMode; exports.selectViewMode = selectViewMode;
exports.selectYTImportError = selectYTImportError;
exports.selectYTImportPending = selectYTImportPending;
exports.selectYoutubeChannels = selectYoutubeChannels; exports.selectYoutubeChannels = selectYoutubeChannels;
exports.setSubscriptionLatest = setSubscriptionLatest; exports.setSubscriptionLatest = setSubscriptionLatest;
exports.statsReducer = statsReducer; exports.statsReducer = statsReducer;

94
dist/bundle.js vendored
View file

@ -380,6 +380,10 @@ __webpack_require__.r(__webpack_exports__);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYoutubeChannels", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_26__["selectYoutubeChannels"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYoutubeChannels", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_26__["selectYoutubeChannels"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYTImportPending", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_26__["selectYTImportPending"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectYTImportError", function() { return redux_selectors_user__WEBPACK_IMPORTED_MODULE_26__["selectYTImportError"]; });
/* harmony import */ var redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(37); /* harmony import */ var redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(37);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectFetchingCostInfoForUri", function() { return redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_27__["makeSelectFetchingCostInfoForUri"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectFetchingCostInfoForUri", function() { return redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_27__["makeSelectFetchingCostInfoForUri"]; });
@ -1888,6 +1892,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__, "selectUserInviteNewIsPending", function() { return selectUserInviteNewIsPending; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectUserInviteNewErrorMessage", function() { return selectUserInviteNewErrorMessage; }); /* 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__, "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__(14); /* 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__); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__);
@ -1981,6 +1987,12 @@ var selectUserInviteNewErrorMessage = Object(reselect__WEBPACK_IMPORTED_MODULE_0
var selectUserInviteReferralLink = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { var selectUserInviteReferralLink = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.referralLink; 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;
});
/***/ }), /***/ }),
/* 16 */ /* 16 */
@ -2409,28 +2421,43 @@ function doUserInviteNew(email) {
} }
function doClaimYoutubeChannels() { function doClaimYoutubeChannels() {
return function (dispatch) { return function (dispatch) {
lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].address_unused().then(function (address) { dispatch({
return (// add dispatch started here type: lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_STARTED
lbryio__WEBPACK_IMPORTED_MODULE_4__["default"].call('yt', 'transfer', { });
address: address lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].address_list().then(function (addressList) {
}).then(function (response) { return addressList.find(function (el) {
if (response && response.length) { return el.used_times === 0;
Promise.all(response.map(function (channelMeta) { });
if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) { }).then(function (address) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].channel_import({ return lbryio__WEBPACK_IMPORTED_MODULE_4__["default"].call('yt', 'transfer', {
channel_data: channelMeta.channel.channel_certificate address: address.address,
}); public_key: address.public_key
} }).then(function (response) {
if (response && response.success) {
Promise.all(response.map(function (channelMeta) {
if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].channel_import({
channel_data: channelMeta.channel.channel_certificate
});
}
return null; return null;
})).then(function () { })).then(function () {
return dispatch(doUserFetch()); var actions = [{
}); // update the channel data the form uses 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"])());
})["catch"](function (e) { dispatch(lbry_redux__WEBPACK_IMPORTED_MODULE_0__["batchActions"].apply(void 0, actions));
return console.error('Transfering channels failed', e); });
}
});
})["catch"](function (error) {
console.error('Youtube import error:', error);
dispatch({
type: lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_FAILURE,
data: String(error)
});
}); });
}; };
} }
@ -3938,7 +3965,9 @@ var defaultState = {
inviteStatusIsPending: false, inviteStatusIsPending: false,
invitesRemaining: undefined, invitesRemaining: undefined,
invitees: undefined, invitees: undefined,
user: undefined user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
}; };
reducers[lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].AUTHENTICATION_STARTED] = function (state) { reducers[lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].AUTHENTICATION_STARTED] = function (state) {
@ -4171,6 +4200,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() { function userReducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments.length > 1 ? arguments[1] : undefined; var action = arguments.length > 1 ? arguments[1] : undefined;

View file

@ -149,6 +149,8 @@ export {
selectUserInviteNewErrorMessage, selectUserInviteNewErrorMessage,
selectUserInviteReferralLink, selectUserInviteReferralLink,
selectYoutubeChannels, selectYoutubeChannels,
selectYTImportPending,
selectYTImportError,
} from 'redux/selectors/user'; } from 'redux/selectors/user';
export { export {
makeSelectFetchingCostInfoForUri, 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 { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
import { import {
selectEmailToVerify, selectEmailToVerify,
@ -385,11 +385,17 @@ export function doUserInviteNew(email) {
export function doClaimYoutubeChannels() { export function doClaimYoutubeChannels() {
return dispatch => { return dispatch => {
Lbry.address_unused() dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_STARTED,
});
Lbry.address_list()
.then(addressList => addressList.find(el => el.used_times === 0))
.then(address => .then(address =>
// add dispatch started here Lbryio.call('yt', 'transfer', {
Lbryio.call('yt', 'transfer', { address }).then(response => { address: address.address,
if (response && response.length) { public_key: address.public_key,
}).then(response => {
if (response && response.success) {
Promise.all( Promise.all(
response.map(channelMeta => { response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) { if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) {
@ -399,10 +405,24 @@ export function doClaimYoutubeChannels() {
} }
return null; return null;
}) })
).then(() => dispatch(doUserFetch())); // update the channel data the form uses ).then(() => {
const actions = [
{
type: ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED,
},
];
actions.push(doUserFetch());
actions.push(doFetchChannelListMine());
dispatch(batchActions(...actions));
});
} }
}) })
) )
.catch(e => console.error('Transfering channels failed', e)); .catch(error => {
dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_FAILURE,
data: String(error),
});
});
}; };
} }

View file

@ -14,6 +14,8 @@ const defaultState = {
invitesRemaining: undefined, invitesRemaining: undefined,
invitees: undefined, invitees: undefined,
user: undefined, user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: '',
}; };
reducers[ACTIONS.AUTHENTICATION_STARTED] = state => reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
@ -220,6 +222,24 @@ reducers[ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = state =>
invitees: null, 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) { export function userReducer(state = defaultState, action) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -136,3 +136,13 @@ export const selectUserInviteReferralLink = createSelector(
selectState, selectState,
state => state.referralLink state => state.referralLink
); );
export const selectYTImportPending = createSelector(
selectState,
state => state.ytChannelImportPending
);
export const selectYTImportError = createSelector(
selectState,
state => state.ytChannelImportErrorMessage
);