redux housekeeping for yt import pending and errors

This commit is contained in:
jessop 2019-09-17 17:01:10 -04:00 committed by Sean Yesmunt
parent 1890985bec
commit 34b91fca23
6 changed files with 173 additions and 36 deletions

50
dist/bundle.es.js vendored
View file

@ -994,6 +994,8 @@ const selectUserInviteStatusFailed = reselect.createSelector(selectUserInvitesRe
const selectUserInviteNewIsPending = reselect.createSelector(selectState$2, state => state.inviteNewIsPending); const selectUserInviteNewIsPending = reselect.createSelector(selectState$2, state => state.inviteNewIsPending);
const selectUserInviteNewErrorMessage = reselect.createSelector(selectState$2, state => state.inviteNewErrorMessage); const selectUserInviteNewErrorMessage = reselect.createSelector(selectState$2, state => state.inviteNewErrorMessage);
const selectUserInviteReferralLink = reselect.createSelector(selectState$2, state => state.referralLink); 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() { function doFetchInviteStatus() {
return dispatch => { return dispatch => {
@ -1367,11 +1369,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({
@ -1380,9 +1385,21 @@ 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 => {
dispatch({
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_FAILURE,
data: String(error)
});
});
}; };
} }
@ -2475,7 +2492,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, {
@ -2657,6 +2676,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);
@ -3068,6 +3102,8 @@ exports.selectUserIsVerificationCandidate = selectUserIsVerificationCandidate;
exports.selectUserPhone = selectUserPhone; exports.selectUserPhone = selectUserPhone;
exports.selectUserVerifiedEmail = selectUserVerifiedEmail; exports.selectUserVerifiedEmail = selectUserVerifiedEmail;
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;

93
dist/bundle.js vendored
View file

@ -385,6 +385,10 @@ __webpack_require__.r(__webpack_exports__);
/* 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__, "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 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"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectFetchingCostInfoForUri", function() { return redux_selectors_cost_info__WEBPACK_IMPORTED_MODULE_28__["makeSelectFetchingCostInfoForUri"]; });
@ -2287,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__, "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__(13); /* 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__); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__);
@ -2383,6 +2389,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;
});
/***/ }), /***/ }),
/* 19 */ /* 19 */
@ -2811,28 +2823,42 @@ 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) {
dispatch({
type: lbry_redux__WEBPACK_IMPORTED_MODULE_0__["ACTIONS"].USER_YOUTUBE_IMPORT_FAILURE,
data: String(error)
});
}); });
}; };
} }
@ -4050,7 +4076,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) {
@ -4284,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() { 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

@ -153,6 +153,8 @@ export {
selectUserInviteReferralLink, selectUserInviteReferralLink,
selectUserVerifiedEmail, selectUserVerifiedEmail,
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 =>
@ -221,6 +223,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

@ -141,3 +141,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
);