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 selectUserInviteNewErrorMessage = reselect.createSelector(selectState$1, state => state.inviteNewErrorMessage);
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() {
return dispatch => {
@ -1092,11 +1094,14 @@ function doUserInviteNew(email) {
}
function doClaimYoutubeChannels() {
return dispatch => {
lbryRedux.Lbry.address_unused().then(address => // add dispatch started here
Lbryio.call('yt', 'transfer', {
address
dispatch({
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_STARTED
});
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 => {
if (response && response.length) {
if (response && response.success) {
Promise.all(response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) {
return lbryRedux.Lbry.channel_import({
@ -1105,9 +1110,22 @@ function doClaimYoutubeChannels() {
}
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,
invitesRemaining: undefined,
invitees: undefined,
user: undefined
user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
};
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
});
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);
@ -2994,6 +3029,8 @@ exports.selectUserIsRewardApproved = selectUserIsRewardApproved;
exports.selectUserIsVerificationCandidate = selectUserIsVerificationCandidate;
exports.selectUserPhone = selectUserPhone;
exports.selectViewMode = selectViewMode;
exports.selectYTImportError = selectYTImportError;
exports.selectYTImportPending = selectYTImportPending;
exports.selectYoutubeChannels = selectYoutubeChannels;
exports.setSubscriptionLatest = setSubscriptionLatest;
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__, "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 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__, "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__(14);
/* 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) {
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 */
@ -2409,28 +2421,43 @@ function doUserInviteNew(email) {
}
function doClaimYoutubeChannels() {
return function (dispatch) {
lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].address_unused().then(function (address) {
return (// add dispatch started here
lbryio__WEBPACK_IMPORTED_MODULE_4__["default"].call('yt', 'transfer', {
address: address
}).then(function (response) {
if (response && response.length) {
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
});
}
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.find(function (el) {
return el.used_times === 0;
});
}).then(function (address) {
return lbryio__WEBPACK_IMPORTED_MODULE_4__["default"].call('yt', 'transfer', {
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;
})).then(function () {
return dispatch(doUserFetch());
}); // update the channel data the form uses
}
})
);
})["catch"](function (e) {
return console.error('Transfering channels failed', e);
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) {
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,
invitesRemaining: undefined,
invitees: undefined,
user: undefined
user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: ''
};
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() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments.length > 1 ? arguments[1] : undefined;

View file

@ -149,6 +149,8 @@ export {
selectUserInviteNewErrorMessage,
selectUserInviteReferralLink,
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,
@ -385,11 +385,17 @@ export function doUserInviteNew(email) {
export function doClaimYoutubeChannels() {
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 =>
// add dispatch started here
Lbryio.call('yt', 'transfer', { address }).then(response => {
if (response && response.length) {
Lbryio.call('yt', 'transfer', {
address: address.address,
public_key: address.public_key,
}).then(response => {
if (response && response.success) {
Promise.all(
response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.transferable) {
@ -399,10 +405,24 @@ export function doClaimYoutubeChannels() {
}
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,
invitees: undefined,
user: undefined,
ytChannelImportPending: false,
ytChannelImportErrorMessage: '',
};
reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
@ -220,6 +222,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

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