Changes needed for additional youtube transfer UI #62

Merged
neb-b merged 4 commits from onboarding into master 2019-10-07 04:40:02 +02:00
13 changed files with 1269 additions and 761 deletions

View file

@ -22,6 +22,7 @@
"__": true "__": true
}, },
"rules": { "rules": {
"consistent-return": 0,
"import/no-commonjs": "warn", "import/no-commonjs": "warn",
"import/no-amd": "warn", "import/no-amd": "warn",
"import/prefer-default-export": "ignore", "import/prefer-default-export": "ignore",

452
dist/bundle.es.js vendored
View file

@ -8,10 +8,46 @@ var lbryRedux = require('lbry-redux');
var querystring = _interopDefault(require('querystring')); var querystring = _interopDefault(require('querystring'));
var reselect = require('reselect'); var reselect = require('reselect');
// Auth Token // User
const GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE'; const GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE';
const GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED'; const GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED';
const GENERATE_AUTH_TOKEN_SUCCESS = 'GENERATE_AUTH_TOKEN_SUCCESS'; // Claims const GENERATE_AUTH_TOKEN_SUCCESS = 'GENERATE_AUTH_TOKEN_SUCCESS';
const AUTHENTICATION_STARTED = 'AUTHENTICATION_STARTED';
const AUTHENTICATION_SUCCESS = 'AUTHENTICATION_SUCCESS';
const AUTHENTICATION_FAILURE = 'AUTHENTICATION_FAILURE';
const USER_EMAIL_DECLINE = 'USER_EMAIL_DECLINE';
const USER_EMAIL_NEW_STARTED = 'USER_EMAIL_NEW_STARTED';
const USER_EMAIL_NEW_SUCCESS = 'USER_EMAIL_NEW_SUCCESS';
const USER_EMAIL_NEW_EXISTS = 'USER_EMAIL_NEW_EXISTS';
const USER_EMAIL_NEW_FAILURE = 'USER_EMAIL_NEW_FAILURE';
const USER_EMAIL_VERIFY_SET = 'USER_EMAIL_VERIFY_SET';
const USER_EMAIL_VERIFY_STARTED = 'USER_EMAIL_VERIFY_STARTED';
const USER_EMAIL_VERIFY_SUCCESS = 'USER_EMAIL_VERIFY_SUCCESS';
const USER_EMAIL_VERIFY_FAILURE = 'USER_EMAIL_VERIFY_FAILURE';
const USER_EMAIL_VERIFY_RETRY = 'USER_EMAIL_VERIFY_RETRY';
const USER_PHONE_RESET = 'USER_PHONE_RESET';
const USER_PHONE_NEW_STARTED = 'USER_PHONE_NEW_STARTED';
const USER_PHONE_NEW_SUCCESS = 'USER_PHONE_NEW_SUCCESS';
const USER_PHONE_NEW_FAILURE = 'USER_PHONE_NEW_FAILURE';
const USER_PHONE_VERIFY_STARTED = 'USER_PHONE_VERIFY_STARTED';
const USER_PHONE_VERIFY_SUCCESS = 'USER_PHONE_VERIFY_SUCCESS';
const USER_PHONE_VERIFY_FAILURE = 'USER_PHONE_VERIFY_FAILURE';
const USER_IDENTITY_VERIFY_STARTED = 'USER_IDENTITY_VERIFY_STARTED';
const USER_IDENTITY_VERIFY_SUCCESS = 'USER_IDENTITY_VERIFY_SUCCESS';
const USER_IDENTITY_VERIFY_FAILURE = 'USER_IDENTITY_VERIFY_FAILURE';
const USER_FETCH_STARTED = 'USER_FETCH_STARTED';
const USER_FETCH_SUCCESS = 'USER_FETCH_SUCCESS';
const USER_FETCH_FAILURE = 'USER_FETCH_FAILURE';
const USER_INVITE_STATUS_FETCH_STARTED = 'USER_INVITE_STATUS_FETCH_STARTED';
const USER_INVITE_STATUS_FETCH_SUCCESS = 'USER_INVITE_STATUS_FETCH_SUCCESS';
const USER_INVITE_STATUS_FETCH_FAILURE = 'USER_INVITE_STATUS_FETCH_FAILURE';
const USER_INVITE_NEW_STARTED = 'USER_INVITE_NEW_STARTED';
const USER_INVITE_NEW_SUCCESS = 'USER_INVITE_NEW_SUCCESS';
const USER_INVITE_NEW_FAILURE = 'USER_INVITE_NEW_FAILURE';
const FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS';
const USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED';
const USER_YOUTUBE_IMPORT_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE';
const USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS'; // Claims
const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED'; const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
const FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED'; const FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED';
@ -83,6 +119,7 @@ const FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED'; // Cross-device S
const GET_SYNC_STARTED = 'GET_SYNC_STARTED'; const GET_SYNC_STARTED = 'GET_SYNC_STARTED';
const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED';
const GET_SYNC_FAILED = 'GET_SYNC_FAILED';
const SET_SYNC_STARTED = 'SET_SYNC_STARTED'; const SET_SYNC_STARTED = 'SET_SYNC_STARTED';
const SET_SYNC_FAILED = 'SET_SYNC_FAILED'; const SET_SYNC_FAILED = 'SET_SYNC_FAILED';
const SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED'; const SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED';
@ -90,11 +127,48 @@ const SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT';
const SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED'; const SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED';
const SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED'; const SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED';
const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED'; const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED';
const SYNC_RESET = 'SYNC_RESET';
var action_types = /*#__PURE__*/Object.freeze({ var action_types = /*#__PURE__*/Object.freeze({
GENERATE_AUTH_TOKEN_FAILURE: GENERATE_AUTH_TOKEN_FAILURE, GENERATE_AUTH_TOKEN_FAILURE: GENERATE_AUTH_TOKEN_FAILURE,
GENERATE_AUTH_TOKEN_STARTED: GENERATE_AUTH_TOKEN_STARTED, GENERATE_AUTH_TOKEN_STARTED: GENERATE_AUTH_TOKEN_STARTED,
GENERATE_AUTH_TOKEN_SUCCESS: GENERATE_AUTH_TOKEN_SUCCESS, GENERATE_AUTH_TOKEN_SUCCESS: GENERATE_AUTH_TOKEN_SUCCESS,
AUTHENTICATION_STARTED: AUTHENTICATION_STARTED,
AUTHENTICATION_SUCCESS: AUTHENTICATION_SUCCESS,
AUTHENTICATION_FAILURE: AUTHENTICATION_FAILURE,
USER_EMAIL_DECLINE: USER_EMAIL_DECLINE,
USER_EMAIL_NEW_STARTED: USER_EMAIL_NEW_STARTED,
USER_EMAIL_NEW_SUCCESS: USER_EMAIL_NEW_SUCCESS,
USER_EMAIL_NEW_EXISTS: USER_EMAIL_NEW_EXISTS,
USER_EMAIL_NEW_FAILURE: USER_EMAIL_NEW_FAILURE,
USER_EMAIL_VERIFY_SET: USER_EMAIL_VERIFY_SET,
USER_EMAIL_VERIFY_STARTED: USER_EMAIL_VERIFY_STARTED,
USER_EMAIL_VERIFY_SUCCESS: USER_EMAIL_VERIFY_SUCCESS,
USER_EMAIL_VERIFY_FAILURE: USER_EMAIL_VERIFY_FAILURE,
USER_EMAIL_VERIFY_RETRY: USER_EMAIL_VERIFY_RETRY,
USER_PHONE_RESET: USER_PHONE_RESET,
USER_PHONE_NEW_STARTED: USER_PHONE_NEW_STARTED,
USER_PHONE_NEW_SUCCESS: USER_PHONE_NEW_SUCCESS,
USER_PHONE_NEW_FAILURE: USER_PHONE_NEW_FAILURE,
USER_PHONE_VERIFY_STARTED: USER_PHONE_VERIFY_STARTED,
USER_PHONE_VERIFY_SUCCESS: USER_PHONE_VERIFY_SUCCESS,
USER_PHONE_VERIFY_FAILURE: USER_PHONE_VERIFY_FAILURE,
USER_IDENTITY_VERIFY_STARTED: USER_IDENTITY_VERIFY_STARTED,
USER_IDENTITY_VERIFY_SUCCESS: USER_IDENTITY_VERIFY_SUCCESS,
USER_IDENTITY_VERIFY_FAILURE: USER_IDENTITY_VERIFY_FAILURE,
USER_FETCH_STARTED: USER_FETCH_STARTED,
USER_FETCH_SUCCESS: USER_FETCH_SUCCESS,
USER_FETCH_FAILURE: USER_FETCH_FAILURE,
USER_INVITE_STATUS_FETCH_STARTED: USER_INVITE_STATUS_FETCH_STARTED,
USER_INVITE_STATUS_FETCH_SUCCESS: USER_INVITE_STATUS_FETCH_SUCCESS,
USER_INVITE_STATUS_FETCH_FAILURE: USER_INVITE_STATUS_FETCH_FAILURE,
USER_INVITE_NEW_STARTED: USER_INVITE_NEW_STARTED,
USER_INVITE_NEW_SUCCESS: USER_INVITE_NEW_SUCCESS,
USER_INVITE_NEW_FAILURE: USER_INVITE_NEW_FAILURE,
FETCH_ACCESS_TOKEN_SUCCESS: FETCH_ACCESS_TOKEN_SUCCESS,
USER_YOUTUBE_IMPORT_STARTED: USER_YOUTUBE_IMPORT_STARTED,
USER_YOUTUBE_IMPORT_FAILURE: USER_YOUTUBE_IMPORT_FAILURE,
USER_YOUTUBE_IMPORT_SUCCESS: USER_YOUTUBE_IMPORT_SUCCESS,
FETCH_FEATURED_CONTENT_STARTED: FETCH_FEATURED_CONTENT_STARTED, FETCH_FEATURED_CONTENT_STARTED: FETCH_FEATURED_CONTENT_STARTED,
FETCH_FEATURED_CONTENT_COMPLETED: FETCH_FEATURED_CONTENT_COMPLETED, FETCH_FEATURED_CONTENT_COMPLETED: FETCH_FEATURED_CONTENT_COMPLETED,
FETCH_TRENDING_CONTENT_STARTED: FETCH_TRENDING_CONTENT_STARTED, FETCH_TRENDING_CONTENT_STARTED: FETCH_TRENDING_CONTENT_STARTED,
@ -159,13 +233,25 @@ var action_types = /*#__PURE__*/Object.freeze({
FETCH_SUB_COUNT_COMPLETED: FETCH_SUB_COUNT_COMPLETED, FETCH_SUB_COUNT_COMPLETED: FETCH_SUB_COUNT_COMPLETED,
GET_SYNC_STARTED: GET_SYNC_STARTED, GET_SYNC_STARTED: GET_SYNC_STARTED,
GET_SYNC_COMPLETED: GET_SYNC_COMPLETED, GET_SYNC_COMPLETED: GET_SYNC_COMPLETED,
GET_SYNC_FAILED: GET_SYNC_FAILED,
SET_SYNC_STARTED: SET_SYNC_STARTED, SET_SYNC_STARTED: SET_SYNC_STARTED,
SET_SYNC_FAILED: SET_SYNC_FAILED, SET_SYNC_FAILED: SET_SYNC_FAILED,
SET_SYNC_COMPLETED: SET_SYNC_COMPLETED, SET_SYNC_COMPLETED: SET_SYNC_COMPLETED,
SET_DEFAULT_ACCOUNT: SET_DEFAULT_ACCOUNT, SET_DEFAULT_ACCOUNT: SET_DEFAULT_ACCOUNT,
SYNC_APPLY_STARTED: SYNC_APPLY_STARTED, SYNC_APPLY_STARTED: SYNC_APPLY_STARTED,
SYNC_APPLY_COMPLETED: SYNC_APPLY_COMPLETED, SYNC_APPLY_COMPLETED: SYNC_APPLY_COMPLETED,
SYNC_APPLY_FAILED: SYNC_APPLY_FAILED SYNC_APPLY_FAILED: SYNC_APPLY_FAILED,
SYNC_RESET: SYNC_RESET
});
const NOT_TRANSFERRED = 'not_transferred';
const PENDING_TRANSFER = 'pending_transfer';
const COMPLETED_TRANSFER = 'completed_transfer';
var youtube = /*#__PURE__*/Object.freeze({
NOT_TRANSFERRED: NOT_TRANSFERRED,
PENDING_TRANSFER: PENDING_TRANSFER,
COMPLETED_TRANSFER: COMPLETED_TRANSFER
}); });
const Lbryio = { const Lbryio = {
@ -1040,18 +1126,26 @@ 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 selectYouTubeImportPending = reselect.createSelector(selectState$2, state => state.youtubeChannelImportPending);
const selectYTImportError = reselect.createSelector(selectState$2, state => state.ytChannelImportErrorMessage); const selectYouTubeImportError = reselect.createSelector(selectState$2, state => state.youtubeChannelImportErrorMessage);
const selectYouTubeImportVideosComplete = reselect.createSelector(selectState$2, state => {
const total = state.youtubeChannelImportTotal;
const complete = state.youtubeChannelImportComplete || 0;
if (total) {
return [complete, total];
}
});
function doFetchInviteStatus() { function doFetchInviteStatus() {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_STARTED type: USER_INVITE_STATUS_FETCH_STARTED
}); });
Promise.all([Lbryio.call('user', 'invite_status'), Lbryio.call('user_referral_code', 'list')]).then(([status, code]) => { Promise.all([Lbryio.call('user', 'invite_status'), Lbryio.call('user_referral_code', 'list')]).then(([status, code]) => {
dispatch(doRewardList()); dispatch(doRewardList());
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS, type: USER_INVITE_STATUS_FETCH_SUCCESS,
data: { data: {
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0, invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
invitees: status.invitees, invitees: status.invitees,
@ -1060,7 +1154,7 @@ function doFetchInviteStatus() {
}); });
}).catch(error => { }).catch(error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE, type: USER_INVITE_STATUS_FETCH_FAILURE,
data: { data: {
error error
} }
@ -1087,12 +1181,12 @@ function doInstallNew(appVersion, os = null) {
function doAuthenticate(appVersion, os = null) { function doAuthenticate(appVersion, os = null) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.AUTHENTICATION_STARTED type: AUTHENTICATION_STARTED
}); });
Lbryio.authenticate().then(user => { Lbryio.authenticate().then(user => {
// analytics.setUser(user); // analytics.setUser(user);
dispatch({ dispatch({
type: lbryRedux.ACTIONS.AUTHENTICATION_SUCCESS, type: AUTHENTICATION_SUCCESS,
data: { data: {
user user
} }
@ -1102,7 +1196,7 @@ function doAuthenticate(appVersion, os = null) {
doInstallNew(appVersion, os); doInstallNew(appVersion, os);
}).catch(error => { }).catch(error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.AUTHENTICATION_FAILURE, type: AUTHENTICATION_FAILURE,
data: { data: {
error error
} }
@ -1113,20 +1207,19 @@ function doAuthenticate(appVersion, os = null) {
function doUserFetch() { function doUserFetch() {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_FETCH_STARTED type: USER_FETCH_STARTED
}); });
Lbryio.getCurrentUser().then(user => { Lbryio.getCurrentUser().then(user => {
// analytics.setUser(user);
dispatch(doRewardList()); dispatch(doRewardList());
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_FETCH_SUCCESS, type: USER_FETCH_SUCCESS,
data: { data: {
user user
} }
}); });
}).catch(error => { }).catch(error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_FETCH_FAILURE, type: USER_FETCH_FAILURE,
data: { data: {
error error
} }
@ -1141,7 +1234,7 @@ function doUserCheckEmailVerified() {
if (user.has_verified_email) { if (user.has_verified_email) {
dispatch(doRewardList()); dispatch(doRewardList());
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_FETCH_SUCCESS, type: USER_FETCH_SUCCESS,
data: { data: {
user user
} }
@ -1152,13 +1245,13 @@ function doUserCheckEmailVerified() {
} }
function doUserPhoneReset() { function doUserPhoneReset() {
return { return {
type: lbryRedux.ACTIONS.USER_PHONE_RESET type: USER_PHONE_RESET
}; };
} }
function doUserPhoneNew(phone, countryCode) { function doUserPhoneNew(phone, countryCode) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_PHONE_NEW_STARTED, type: USER_PHONE_NEW_STARTED,
data: { data: {
phone, phone,
country_code: countryCode country_code: countryCode
@ -1167,7 +1260,7 @@ function doUserPhoneNew(phone, countryCode) {
const success = () => { const success = () => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_PHONE_NEW_SUCCESS, type: USER_PHONE_NEW_SUCCESS,
data: { data: {
phone phone
} }
@ -1176,7 +1269,7 @@ function doUserPhoneNew(phone, countryCode) {
const failure = error => { const failure = error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_PHONE_NEW_FAILURE, type: USER_PHONE_NEW_FAILURE,
data: { data: {
error error
} }
@ -1191,7 +1284,7 @@ function doUserPhoneNew(phone, countryCode) {
} }
function doUserPhoneVerifyFailure(error) { function doUserPhoneVerifyFailure(error) {
return { return {
type: lbryRedux.ACTIONS.USER_PHONE_VERIFY_FAILURE, type: USER_PHONE_VERIFY_FAILURE,
data: { data: {
error error
} }
@ -1202,7 +1295,7 @@ function doUserPhoneVerify(verificationCode) {
const phoneNumber = selectPhoneToVerify(getState()); const phoneNumber = selectPhoneToVerify(getState());
const countryCode = selectUserCountryCode(getState()); const countryCode = selectUserCountryCode(getState());
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_PHONE_VERIFY_STARTED, type: USER_PHONE_VERIFY_STARTED,
code: verificationCode code: verificationCode
}); });
Lbryio.call('user', 'phone_number_confirm', { Lbryio.call('user', 'phone_number_confirm', {
@ -1212,7 +1305,7 @@ function doUserPhoneVerify(verificationCode) {
}, 'post').then(user => { }, 'post').then(user => {
if (user.is_identity_verified) { if (user.is_identity_verified) {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_PHONE_VERIFY_SUCCESS, type: USER_PHONE_VERIFY_SUCCESS,
data: { data: {
user user
} }
@ -1225,7 +1318,7 @@ function doUserPhoneVerify(verificationCode) {
function doUserEmailToVerify(email) { function doUserEmailToVerify(email) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_VERIFY_SET, type: USER_EMAIL_VERIFY_SET,
data: { data: {
email email
} }
@ -1235,13 +1328,13 @@ function doUserEmailToVerify(email) {
function doUserEmailNew(email) { function doUserEmailNew(email) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_NEW_STARTED, type: USER_EMAIL_NEW_STARTED,
email email
}); });
const success = () => { const success = () => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_NEW_SUCCESS, type: USER_EMAIL_NEW_SUCCESS,
data: { data: {
email email
} }
@ -1251,7 +1344,7 @@ function doUserEmailNew(email) {
const failure = error => { const failure = error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_NEW_FAILURE, type: USER_EMAIL_NEW_FAILURE,
data: { data: {
error error
} }
@ -1276,13 +1369,13 @@ function doUserEmailNew(email) {
function doUserResendVerificationEmail(email) { function doUserResendVerificationEmail(email) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_VERIFY_RETRY, type: USER_EMAIL_VERIFY_RETRY,
email email
}); });
const success = () => { const success = () => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_NEW_SUCCESS, type: USER_EMAIL_NEW_SUCCESS,
data: { data: {
email email
} }
@ -1292,7 +1385,7 @@ function doUserResendVerificationEmail(email) {
const failure = error => { const failure = error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_NEW_FAILURE, type: USER_EMAIL_NEW_FAILURE,
data: { data: {
error error
} }
@ -1310,7 +1403,7 @@ function doUserResendVerificationEmail(email) {
} }
function doUserEmailVerifyFailure(error) { function doUserEmailVerifyFailure(error) {
return { return {
type: lbryRedux.ACTIONS.USER_EMAIL_VERIFY_FAILURE, type: USER_EMAIL_VERIFY_FAILURE,
data: { data: {
error error
} }
@ -1320,7 +1413,7 @@ function doUserEmailVerify(verificationToken, recaptcha) {
return (dispatch, getState) => { return (dispatch, getState) => {
const email = selectEmailToVerify(getState()); const email = selectEmailToVerify(getState());
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_VERIFY_STARTED, type: USER_EMAIL_VERIFY_STARTED,
code: verificationToken, code: verificationToken,
recaptcha recaptcha
}); });
@ -1331,7 +1424,7 @@ function doUserEmailVerify(verificationToken, recaptcha) {
}, 'post').then(userEmail => { }, 'post').then(userEmail => {
if (userEmail.is_verified) { if (userEmail.is_verified) {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_EMAIL_VERIFY_SUCCESS, type: USER_EMAIL_VERIFY_SUCCESS,
data: { data: {
email email
} }
@ -1346,7 +1439,7 @@ function doUserEmailVerify(verificationToken, recaptcha) {
function doFetchAccessToken() { function doFetchAccessToken() {
return dispatch => { return dispatch => {
const success = token => dispatch({ const success = token => dispatch({
type: lbryRedux.ACTIONS.FETCH_ACCESS_TOKEN_SUCCESS, type: FETCH_ACCESS_TOKEN_SUCCESS,
data: { data: {
token token
} }
@ -1358,7 +1451,7 @@ function doFetchAccessToken() {
function doUserIdentityVerify(stripeToken) { function doUserIdentityVerify(stripeToken) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_IDENTITY_VERIFY_STARTED, type: USER_IDENTITY_VERIFY_STARTED,
token: stripeToken token: stripeToken
}); });
Lbryio.call('user', 'verify_identity', { Lbryio.call('user', 'verify_identity', {
@ -1366,7 +1459,7 @@ function doUserIdentityVerify(stripeToken) {
}, 'post').then(user => { }, 'post').then(user => {
if (user.is_identity_verified) { if (user.is_identity_verified) {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_IDENTITY_VERIFY_SUCCESS, type: USER_IDENTITY_VERIFY_SUCCESS,
data: { data: {
user user
} }
@ -1377,7 +1470,7 @@ function doUserIdentityVerify(stripeToken) {
} }
}).catch(error => { }).catch(error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_IDENTITY_VERIFY_FAILURE, type: USER_IDENTITY_VERIFY_FAILURE,
data: { data: {
error: error.toString() error: error.toString()
} }
@ -1388,13 +1481,13 @@ function doUserIdentityVerify(stripeToken) {
function doUserInviteNew(email) { function doUserInviteNew(email) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_INVITE_NEW_STARTED type: USER_INVITE_NEW_STARTED
}); });
Lbryio.call('user', 'invite', { Lbryio.call('user', 'invite', {
email email
}, 'post').then(() => { }, 'post').then(() => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_INVITE_NEW_SUCCESS, type: USER_INVITE_NEW_SUCCESS,
data: { data: {
email email
} }
@ -1405,7 +1498,7 @@ function doUserInviteNew(email) {
dispatch(doFetchInviteStatus()); dispatch(doFetchInviteStatus());
}).catch(error => { }).catch(error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_INVITE_NEW_FAILURE, type: USER_INVITE_NEW_FAILURE,
data: { data: {
error error
} }
@ -1416,14 +1509,16 @@ function doUserInviteNew(email) {
function doClaimYoutubeChannels() { function doClaimYoutubeChannels() {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_STARTED type: 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', { let transferResponse;
return 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, address: address.address,
public_key: address.pubkey public_key: address.pubkey
}).then(response => { }).then(response => {
if (response && response.success) { if (response && response.length) {
Promise.all(response.map(channelMeta => { transferResponse = response;
return Promise.all(response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.channel_certificate) { if (channelMeta && channelMeta.channel && channelMeta.channel.channel_certificate) {
return lbryRedux.Lbry.channel_import({ return lbryRedux.Lbry.channel_import({
channel_data: channelMeta.channel.channel_certificate channel_data: channelMeta.channel.channel_certificate
@ -1433,7 +1528,8 @@ function doClaimYoutubeChannels() {
return null; return null;
})).then(() => { })).then(() => {
const actions = [{ const actions = [{
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED type: USER_YOUTUBE_IMPORT_SUCCESS,
data: transferResponse
}]; }];
actions.push(doUserFetch()); actions.push(doUserFetch());
actions.push(lbryRedux.doFetchChannelListMine()); actions.push(lbryRedux.doFetchChannelListMine());
@ -1442,7 +1538,29 @@ function doClaimYoutubeChannels() {
} }
})).catch(error => { })).catch(error => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_FAILURE, type: USER_YOUTUBE_IMPORT_FAILURE,
data: String(error)
});
});
};
}
function doCheckYoutubeTransfer() {
return dispatch => {
dispatch({
type: USER_YOUTUBE_IMPORT_STARTED
});
return Lbryio.call('yt', 'transfer').then(response => {
if (response && response.length) {
dispatch({
type: USER_YOUTUBE_IMPORT_SUCCESS,
data: response
});
} else {
throw new Error();
}
}).catch(error => {
dispatch({
type: USER_YOUTUBE_IMPORT_FAILURE,
data: String(error) data: String(error)
}); });
}); });
@ -1508,6 +1626,9 @@ function doClaimRewardType(rewardType, options = {}) {
}); });
const success = successReward => { const success = successReward => {
// Temporary timeout to ensure the sdk has the correct balance after claiming a reward
setTimeout(() => {
dispatch(lbryRedux.doUpdateBalance()).then(() => {
dispatch({ dispatch({
type: lbryRedux.ACTIONS.CLAIM_REWARD_SUCCESS, type: lbryRedux.ACTIONS.CLAIM_REWARD_SUCCESS,
data: { data: {
@ -1526,6 +1647,8 @@ function doClaimRewardType(rewardType, options = {}) {
if (options.callback) { if (options.callback) {
options.callback(); options.callback();
} }
});
}, 1000);
}; };
const failure = error => { const failure = error => {
@ -1549,7 +1672,7 @@ function doClaimRewardType(rewardType, options = {}) {
} }
}; };
rewards.claimReward(rewardType, params).then(success, failure); return rewards.claimReward(rewardType, params).then(success, failure);
}; };
} }
function doClaimEligiblePurchaseRewards() { function doClaimEligiblePurchaseRewards() {
@ -2203,41 +2326,6 @@ const doFetchSubCount = claimId => dispatch => {
}); });
}; };
function doSetSync(oldHash, newHash, data) {
return dispatch => {
dispatch({
type: SET_SYNC_STARTED
});
Lbryio.call('sync', 'set', {
old_hash: oldHash,
new_hash: newHash,
data
}, 'post').then(response => {
if (!response.hash) {
return dispatch({
type: SET_SYNC_FAILED,
data: {
error: 'No hash returned for sync/set.'
}
});
}
return dispatch({
type: SET_SYNC_COMPLETED,
data: {
syncHash: response.hash
}
});
}).catch(error => {
dispatch({
type: SET_SYNC_FAILED,
data: {
error
}
});
});
};
}
function doSetDefaultAccount(success, failure) { function doSetDefaultAccount(success, failure) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
@ -2276,12 +2364,10 @@ function doSetDefaultAccount(success, failure) {
failure(err); failure(err);
} }
}); });
} else { } else if (failure) {
// no default account to set // no default account to set
if (failure) {
failure('Could not set a default account'); // fail failure('Could not set a default account'); // fail
} }
}
}).catch(err => { }).catch(err => {
if (failure) { if (failure) {
failure(err); failure(err);
@ -2289,33 +2375,81 @@ function doSetDefaultAccount(success, failure) {
}); });
}; };
} }
function doGetSync(password) { function doSetSync(oldHash, newHash, data) {
return dispatch => {
dispatch({
type: SET_SYNC_STARTED
});
return Lbryio.call('sync', 'set', {
old_hash: oldHash,
new_hash: newHash,
data
}, 'post').then(response => {
if (!response.hash) {
throw Error('No hash returned for sync/set.');
}
return dispatch({
type: SET_SYNC_COMPLETED,
data: {
syncHash: response.hash
}
});
}).catch(error => {
dispatch({
type: SET_SYNC_FAILED,
data: {
error
}
});
});
};
}
function doGetSync(password = '', shouldSetDefaultAccount) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: GET_SYNC_STARTED type: GET_SYNC_STARTED
}); });
const data = {};
lbryRedux.Lbry.sync_hash().then(hash => { lbryRedux.Lbry.sync_hash().then(hash => {
Lbryio.call('sync', 'get', { Lbryio.call('sync', 'get', {
hash hash
}, 'post').then(response => { }, 'post').then(response => {
const data = {
hasSyncedWallet: true
};
if (response.changed) {
const syncHash = response.hash; const syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data; data.syncData = response.data;
lbryRedux.Lbry.sync_apply({ data.hasSyncedWallet = true;
if (response.changed || shouldSetDefaultAccount) {
return lbryRedux.Lbry.sync_apply({
password, password,
data: response.data data: response.data
}).then(({ }).then(({
hash: walletHash, hash: walletHash,
data: walletData data: walletData
}) => { }) => {
if (walletHash !== syncHash) { dispatch({
type: GET_SYNC_COMPLETED,
data
});
if (walletHash !== syncHash || shouldSetDefaultAccount) {
// different local hash, need to synchronise // different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData)); dispatch(doSetSync(syncHash, walletHash, walletData));
if (shouldSetDefaultAccount) {
dispatch(doSetDefaultAccount(() => {
lbryRedux.Lbry.status().then(status => {
if (status.wallet.is_locked) {
lbryRedux.Lbry.account_unlock({
password
});
}
dispatch(lbryRedux.doFetchChannelListMine());
});
}));
}
} }
}); });
} }
@ -2325,6 +2459,14 @@ function doGetSync(password) {
data data
}); });
}).catch(() => { }).catch(() => {
if (data.hasSyncedWallet) {
dispatch({
type: GET_SYNC_FAILED,
data: {
error: 'Error getting synced wallet'
}
});
} else {
// user doesn't have a synced wallet // user doesn't have a synced wallet
dispatch({ dispatch({
type: GET_SYNC_COMPLETED, type: GET_SYNC_COMPLETED,
@ -2339,8 +2481,9 @@ function doGetSync(password) {
password password
}).then(({ }).then(({
hash: walletHash, hash: walletHash,
data data: syncApplyData
}) => dispatch(doSetSync('', walletHash, data))); }) => dispatch(doSetSync('', walletHash, syncApplyData, password)));
}
}); });
}); });
}; };
@ -2407,6 +2550,14 @@ function doCheckSync() {
}); });
}; };
} }
function doResetSync() {
return dispatch => new Promise(resolve => {
dispatch({
type: SYNC_RESET
});
resolve();
});
}
const reducers = {}; const reducers = {};
const defaultState$1 = { const defaultState$1 = {
@ -2562,44 +2713,44 @@ const defaultState$3 = {
invitesRemaining: undefined, invitesRemaining: undefined,
invitees: undefined, invitees: undefined,
user: undefined, user: undefined,
ytChannelImportPending: false, youtubeChannelImportPending: false,
ytChannelImportErrorMessage: '' youtubeChannelImportErrorMessage: ''
}; };
reducers$2[lbryRedux.ACTIONS.AUTHENTICATION_STARTED] = state => Object.assign({}, state, { reducers$2[AUTHENTICATION_STARTED] = state => Object.assign({}, state, {
authenticationIsPending: true, authenticationIsPending: true,
userIsPending: true, userIsPending: true,
user: defaultState$3.user user: defaultState$3.user
}); });
reducers$2[lbryRedux.ACTIONS.AUTHENTICATION_SUCCESS] = (state, action) => Object.assign({}, state, { reducers$2[AUTHENTICATION_SUCCESS] = (state, action) => Object.assign({}, state, {
authenticationIsPending: false, authenticationIsPending: false,
userIsPending: false, userIsPending: false,
user: action.data.user user: action.data.user
}); });
reducers$2[lbryRedux.ACTIONS.AUTHENTICATION_FAILURE] = state => Object.assign({}, state, { reducers$2[AUTHENTICATION_FAILURE] = state => Object.assign({}, state, {
authenticationIsPending: false, authenticationIsPending: false,
userIsPending: false, userIsPending: false,
user: null user: null
}); });
reducers$2[lbryRedux.ACTIONS.USER_FETCH_STARTED] = state => Object.assign({}, state, { reducers$2[USER_FETCH_STARTED] = state => Object.assign({}, state, {
userIsPending: true userIsPending: true
}); });
reducers$2[lbryRedux.ACTIONS.USER_FETCH_SUCCESS] = (state, action) => Object.assign({}, state, { reducers$2[USER_FETCH_SUCCESS] = (state, action) => Object.assign({}, state, {
userIsPending: false, userIsPending: false,
user: action.data.user, user: action.data.user,
emailToVerify: action.data.user.has_verified_email ? null : state.emailToVerify emailToVerify: action.data.user.has_verified_email ? null : state.emailToVerify
}); });
reducers$2[lbryRedux.ACTIONS.USER_FETCH_FAILURE] = state => Object.assign({}, state, { reducers$2[USER_FETCH_FAILURE] = state => Object.assign({}, state, {
userIsPending: true, userIsPending: true,
user: null user: null
}); });
reducers$2[lbryRedux.ACTIONS.USER_PHONE_NEW_STARTED] = (state, action) => { reducers$2[USER_PHONE_NEW_STARTED] = (state, action) => {
const user = Object.assign({}, state.user); const user = Object.assign({}, state.user);
user.country_code = action.data.country_code; user.country_code = action.data.country_code;
return Object.assign({}, state, { return Object.assign({}, state, {
@ -2609,42 +2760,42 @@ reducers$2[lbryRedux.ACTIONS.USER_PHONE_NEW_STARTED] = (state, action) => {
}); });
}; };
reducers$2[lbryRedux.ACTIONS.USER_PHONE_NEW_SUCCESS] = (state, action) => Object.assign({}, state, { reducers$2[USER_PHONE_NEW_SUCCESS] = (state, action) => Object.assign({}, state, {
phoneToVerify: action.data.phone, phoneToVerify: action.data.phone,
phoneNewIsPending: false phoneNewIsPending: false
}); });
reducers$2[lbryRedux.ACTIONS.USER_PHONE_RESET] = state => Object.assign({}, state, { reducers$2[USER_PHONE_RESET] = state => Object.assign({}, state, {
phoneToVerify: null phoneToVerify: null
}); });
reducers$2[lbryRedux.ACTIONS.USER_PHONE_NEW_FAILURE] = (state, action) => Object.assign({}, state, { reducers$2[USER_PHONE_NEW_FAILURE] = (state, action) => Object.assign({}, state, {
phoneNewIsPending: false, phoneNewIsPending: false,
phoneNewErrorMessage: action.data.error phoneNewErrorMessage: action.data.error
}); });
reducers$2[lbryRedux.ACTIONS.USER_PHONE_VERIFY_STARTED] = state => Object.assign({}, state, { reducers$2[USER_PHONE_VERIFY_STARTED] = state => Object.assign({}, state, {
phoneVerifyIsPending: true, phoneVerifyIsPending: true,
phoneVerifyErrorMessage: '' phoneVerifyErrorMessage: ''
}); });
reducers$2[lbryRedux.ACTIONS.USER_PHONE_VERIFY_SUCCESS] = (state, action) => Object.assign({}, state, { reducers$2[USER_PHONE_VERIFY_SUCCESS] = (state, action) => Object.assign({}, state, {
phoneToVerify: '', phoneToVerify: '',
phoneVerifyIsPending: false, phoneVerifyIsPending: false,
user: action.data.user user: action.data.user
}); });
reducers$2[lbryRedux.ACTIONS.USER_PHONE_VERIFY_FAILURE] = (state, action) => Object.assign({}, state, { reducers$2[USER_PHONE_VERIFY_FAILURE] = (state, action) => Object.assign({}, state, {
phoneVerifyIsPending: false, phoneVerifyIsPending: false,
phoneVerifyErrorMessage: action.data.error phoneVerifyErrorMessage: action.data.error
}); });
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_NEW_STARTED] = state => Object.assign({}, state, { reducers$2[USER_EMAIL_NEW_STARTED] = state => Object.assign({}, state, {
emailNewIsPending: true, emailNewIsPending: true,
emailNewErrorMessage: '' emailNewErrorMessage: ''
}); });
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_NEW_SUCCESS] = (state, action) => { reducers$2[USER_EMAIL_NEW_SUCCESS] = (state, action) => {
const user = Object.assign({}, state.user); const user = Object.assign({}, state.user);
user.primary_email = action.data.email; user.primary_email = action.data.email;
return Object.assign({}, state, { return Object.assign({}, state, {
@ -2654,22 +2805,22 @@ reducers$2[lbryRedux.ACTIONS.USER_EMAIL_NEW_SUCCESS] = (state, action) => {
}); });
}; };
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_NEW_EXISTS] = (state, action) => Object.assign({}, state, { reducers$2[USER_EMAIL_NEW_EXISTS] = (state, action) => Object.assign({}, state, {
emailToVerify: action.data.email, emailToVerify: action.data.email,
emailNewIsPending: false emailNewIsPending: false
}); });
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_NEW_FAILURE] = (state, action) => Object.assign({}, state, { reducers$2[USER_EMAIL_NEW_FAILURE] = (state, action) => Object.assign({}, state, {
emailNewIsPending: false, emailNewIsPending: false,
emailNewErrorMessage: action.data.error emailNewErrorMessage: action.data.error
}); });
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_VERIFY_STARTED] = state => Object.assign({}, state, { reducers$2[USER_EMAIL_VERIFY_STARTED] = state => Object.assign({}, state, {
emailVerifyIsPending: true, emailVerifyIsPending: true,
emailVerifyErrorMessage: '' emailVerifyErrorMessage: ''
}); });
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_VERIFY_SUCCESS] = (state, action) => { reducers$2[USER_EMAIL_VERIFY_SUCCESS] = (state, action) => {
const user = Object.assign({}, state.user); const user = Object.assign({}, state.user);
user.primary_email = action.data.email; user.primary_email = action.data.email;
return Object.assign({}, state, { return Object.assign({}, state, {
@ -2679,32 +2830,32 @@ reducers$2[lbryRedux.ACTIONS.USER_EMAIL_VERIFY_SUCCESS] = (state, action) => {
}); });
}; };
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_VERIFY_FAILURE] = (state, action) => Object.assign({}, state, { reducers$2[USER_EMAIL_VERIFY_FAILURE] = (state, action) => Object.assign({}, state, {
emailVerifyIsPending: false, emailVerifyIsPending: false,
emailVerifyErrorMessage: action.data.error emailVerifyErrorMessage: action.data.error
}); });
reducers$2[lbryRedux.ACTIONS.USER_EMAIL_VERIFY_SET] = (state, action) => Object.assign({}, state, { reducers$2[USER_EMAIL_VERIFY_SET] = (state, action) => Object.assign({}, state, {
emailToVerify: action.data.email emailToVerify: action.data.email
}); });
reducers$2[lbryRedux.ACTIONS.USER_IDENTITY_VERIFY_STARTED] = state => Object.assign({}, state, { reducers$2[USER_IDENTITY_VERIFY_STARTED] = state => Object.assign({}, state, {
identityVerifyIsPending: true, identityVerifyIsPending: true,
identityVerifyErrorMessage: '' identityVerifyErrorMessage: ''
}); });
reducers$2[lbryRedux.ACTIONS.USER_IDENTITY_VERIFY_SUCCESS] = (state, action) => Object.assign({}, state, { reducers$2[USER_IDENTITY_VERIFY_SUCCESS] = (state, action) => Object.assign({}, state, {
identityVerifyIsPending: false, identityVerifyIsPending: false,
identityVerifyErrorMessage: '', identityVerifyErrorMessage: '',
user: action.data.user user: action.data.user
}); });
reducers$2[lbryRedux.ACTIONS.USER_IDENTITY_VERIFY_FAILURE] = (state, action) => Object.assign({}, state, { reducers$2[USER_IDENTITY_VERIFY_FAILURE] = (state, action) => Object.assign({}, state, {
identityVerifyIsPending: false, identityVerifyIsPending: false,
identityVerifyErrorMessage: action.data.error identityVerifyErrorMessage: action.data.error
}); });
reducers$2[lbryRedux.ACTIONS.FETCH_ACCESS_TOKEN_SUCCESS] = (state, action) => { reducers$2[FETCH_ACCESS_TOKEN_SUCCESS] = (state, action) => {
const { const {
token token
} = action.data; } = action.data;
@ -2713,51 +2864,57 @@ reducers$2[lbryRedux.ACTIONS.FETCH_ACCESS_TOKEN_SUCCESS] = (state, action) => {
}); });
}; };
reducers$2[lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_STARTED] = state => Object.assign({}, state, { reducers$2[USER_INVITE_STATUS_FETCH_STARTED] = state => Object.assign({}, state, {
inviteStatusIsPending: true inviteStatusIsPending: true
}); });
reducers$2[lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS] = (state, action) => Object.assign({}, state, { reducers$2[USER_INVITE_STATUS_FETCH_SUCCESS] = (state, action) => Object.assign({}, state, {
inviteStatusIsPending: false, inviteStatusIsPending: false,
invitesRemaining: action.data.invitesRemaining, invitesRemaining: action.data.invitesRemaining,
invitees: action.data.invitees, invitees: action.data.invitees,
referralLink: action.data.referralLink referralLink: action.data.referralLink
}); });
reducers$2[lbryRedux.ACTIONS.USER_INVITE_NEW_STARTED] = state => Object.assign({}, state, { reducers$2[USER_INVITE_NEW_STARTED] = state => Object.assign({}, state, {
inviteNewIsPending: true, inviteNewIsPending: true,
inviteNewErrorMessage: '' inviteNewErrorMessage: ''
}); });
reducers$2[lbryRedux.ACTIONS.USER_INVITE_NEW_SUCCESS] = state => Object.assign({}, state, { reducers$2[USER_INVITE_NEW_SUCCESS] = state => Object.assign({}, state, {
inviteNewIsPending: false, inviteNewIsPending: false,
inviteNewErrorMessage: '' inviteNewErrorMessage: ''
}); });
reducers$2[lbryRedux.ACTIONS.USER_INVITE_NEW_FAILURE] = (state, action) => Object.assign({}, state, { reducers$2[USER_INVITE_NEW_FAILURE] = (state, action) => Object.assign({}, state, {
inviteNewIsPending: false, inviteNewIsPending: false,
inviteNewErrorMessage: action.data.error.message inviteNewErrorMessage: action.data.error.message
}); });
reducers$2[lbryRedux.ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = state => Object.assign({}, state, { reducers$2[USER_INVITE_STATUS_FETCH_FAILURE] = state => Object.assign({}, state, {
inviteStatusIsPending: false, inviteStatusIsPending: false,
invitesRemaining: null, invitesRemaining: null,
invitees: null invitees: null
}); });
reducers$2[lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_STARTED] = state => Object.assign({}, state, { reducers$2[USER_YOUTUBE_IMPORT_STARTED] = state => Object.assign({}, state, {
ytChannelImportPending: true, youtubeChannelImportPending: true,
ytChannelImportErrorMessage: '' youtubeChannelImportErrorMessage: ''
}); });
reducers$2[lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED] = state => Object.assign({}, state, { reducers$2[USER_YOUTUBE_IMPORT_SUCCESS] = (state, action) => {
ytChannelImportPending: false, const total = action.data.reduce((acc, value) => acc + value.total_published_videos, 0);
ytChannelImportErrorMessage: '' const complete = action.data.reduce((acc, value) => acc + value.total_transferred, 0);
return Object.assign({}, state, {
youtubeChannelImportPending: false,
youtubeChannelImportErrorMessage: '',
youtubeChannelImportTotal: total,
youtubeChannelImportComplete: complete
}); });
};
reducers$2[lbryRedux.ACTIONS.USER_YOUTUBE_IMPORT_FAILURE] = (state, action) => Object.assign({}, state, { reducers$2[USER_YOUTUBE_IMPORT_FAILURE] = (state, action) => Object.assign({}, state, {
ytChannelImportPending: false, youtubeChannelImportPending: false,
ytChannelImportErrorMessage: action.data youtubeChannelImportErrorMessage: action.data
}); });
function userReducer(state = defaultState$3, action) { function userReducer(state = defaultState$3, action) {
@ -2952,6 +3109,7 @@ const defaultState$9 = {
syncHash: null, syncHash: null,
syncData: null, syncData: null,
setSyncErrorMessage: null, setSyncErrorMessage: null,
getSyncErrorMessage: null,
syncApplyErrorMessage: '', syncApplyErrorMessage: '',
syncApplyIsPending: false, syncApplyIsPending: false,
getSyncIsPending: false, getSyncIsPending: false,
@ -2960,7 +3118,8 @@ const defaultState$9 = {
}; };
reducers$3[GET_SYNC_STARTED] = state => Object.assign({}, state, { reducers$3[GET_SYNC_STARTED] = state => Object.assign({}, state, {
getSyncIsPending: true getSyncIsPending: true,
getSyncErrorMessage: null
}); });
reducers$3[GET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, { reducers$3[GET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
@ -2971,6 +3130,11 @@ reducers$3[GET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
hashChanged: action.data.hashChanged hashChanged: action.data.hashChanged
}); });
reducers$3[GET_SYNC_FAILED] = (state, action) => Object.assign({}, state, {
getSyncIsPending: false,
getSyncErrorMessage: action.data.error
});
reducers$3[SET_SYNC_STARTED] = state => Object.assign({}, state, { reducers$3[SET_SYNC_STARTED] = state => Object.assign({}, state, {
setSyncIsPending: true, setSyncIsPending: true,
setSyncErrorMessage: null setSyncErrorMessage: null
@ -3004,6 +3168,8 @@ reducers$3[SYNC_APPLY_FAILED] = (state, action) => Object.assign({}, state, {
syncApplyErrorMessage: action.data.error syncApplyErrorMessage: action.data.error
}); });
reducers$3[SYNC_RESET] = () => defaultState$9;
function syncReducer(state = defaultState$9, action) { function syncReducer(state = defaultState$9, action) {
const handler = reducers$3[action.type]; const handler = reducers$3[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);
@ -3047,6 +3213,7 @@ const selectHasSyncedWallet = reselect.createSelector(selectState$9, state => st
const selectSyncHash = reselect.createSelector(selectState$9, state => state.syncHash); const selectSyncHash = reselect.createSelector(selectState$9, state => state.syncHash);
const selectSyncData = reselect.createSelector(selectState$9, state => state.syncData); const selectSyncData = reselect.createSelector(selectState$9, state => state.syncData);
const selectSetSyncErrorMessage = reselect.createSelector(selectState$9, state => state.setSyncErrorMessage); const selectSetSyncErrorMessage = reselect.createSelector(selectState$9, state => state.setSyncErrorMessage);
const selectGetSyncErrorMessage = reselect.createSelector(selectState$9, state => state.getSyncErrorMessage);
const selectGetSyncIsPending = reselect.createSelector(selectState$9, state => state.getSyncIsPending); const selectGetSyncIsPending = reselect.createSelector(selectState$9, state => state.getSyncIsPending);
const selectSetSyncIsPending = reselect.createSelector(selectState$9, state => state.setSyncIsPending); const selectSetSyncIsPending = reselect.createSelector(selectState$9, state => state.setSyncIsPending);
const selectHashChanged = reselect.createSelector(selectState$9, state => state.hashChanged); const selectHashChanged = reselect.createSelector(selectState$9, state => state.hashChanged);
@ -3055,6 +3222,7 @@ const selectSyncApplyErrorMessage = reselect.createSelector(selectState$9, state
exports.LBRYINC_ACTIONS = action_types; exports.LBRYINC_ACTIONS = action_types;
exports.Lbryio = Lbryio; exports.Lbryio = Lbryio;
exports.YOUTUBE_STATUSES = youtube;
exports.authReducer = authReducer; exports.authReducer = authReducer;
exports.blacklistReducer = blacklistReducer; exports.blacklistReducer = blacklistReducer;
exports.costInfoReducer = costInfoReducer; exports.costInfoReducer = costInfoReducer;
@ -3068,6 +3236,7 @@ exports.doCheckSubscription = doCheckSubscription;
exports.doCheckSubscriptions = doCheckSubscriptions; exports.doCheckSubscriptions = doCheckSubscriptions;
exports.doCheckSubscriptionsInit = doCheckSubscriptionsInit; exports.doCheckSubscriptionsInit = doCheckSubscriptionsInit;
exports.doCheckSync = doCheckSync; exports.doCheckSync = doCheckSync;
exports.doCheckYoutubeTransfer = doCheckYoutubeTransfer;
exports.doClaimEligiblePurchaseRewards = doClaimEligiblePurchaseRewards; exports.doClaimEligiblePurchaseRewards = doClaimEligiblePurchaseRewards;
exports.doClaimRewardClearError = doClaimRewardClearError; exports.doClaimRewardClearError = doClaimRewardClearError;
exports.doClaimRewardType = doClaimRewardType; exports.doClaimRewardType = doClaimRewardType;
@ -3089,6 +3258,7 @@ exports.doGetSync = doGetSync;
exports.doInstallNew = doInstallNew; exports.doInstallNew = doInstallNew;
exports.doRemoveUnreadSubscription = doRemoveUnreadSubscription; exports.doRemoveUnreadSubscription = doRemoveUnreadSubscription;
exports.doRemoveUnreadSubscriptions = doRemoveUnreadSubscriptions; exports.doRemoveUnreadSubscriptions = doRemoveUnreadSubscriptions;
exports.doResetSync = doResetSync;
exports.doRewardList = doRewardList; exports.doRewardList = doRewardList;
exports.doSetDefaultAccount = doSetDefaultAccount; exports.doSetDefaultAccount = doSetDefaultAccount;
exports.doSetSync = doSetSync; exports.doSetSync = doSetSync;
@ -3147,6 +3317,7 @@ exports.selectFetchingRewards = selectFetchingRewards;
exports.selectFetchingTrendingUris = selectFetchingTrendingUris; exports.selectFetchingTrendingUris = selectFetchingTrendingUris;
exports.selectFilteredOutpoints = selectFilteredOutpoints; exports.selectFilteredOutpoints = selectFilteredOutpoints;
exports.selectFirstRunCompleted = selectFirstRunCompleted; exports.selectFirstRunCompleted = selectFirstRunCompleted;
exports.selectGetSyncErrorMessage = selectGetSyncErrorMessage;
exports.selectGetSyncIsPending = selectGetSyncIsPending; exports.selectGetSyncIsPending = selectGetSyncIsPending;
exports.selectHasSyncedWallet = selectHasSyncedWallet; exports.selectHasSyncedWallet = selectHasSyncedWallet;
exports.selectHashChanged = selectHashChanged; exports.selectHashChanged = selectHashChanged;
@ -3197,8 +3368,9 @@ 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.selectYouTubeImportError = selectYouTubeImportError;
exports.selectYTImportPending = selectYTImportPending; exports.selectYouTubeImportPending = selectYouTubeImportPending;
exports.selectYouTubeImportVideosComplete = selectYouTubeImportVideosComplete;
exports.selectYoutubeChannels = selectYoutubeChannels; exports.selectYoutubeChannels = selectYoutubeChannels;
exports.setSubscriptionLatest = setSubscriptionLatest; exports.setSubscriptionLatest = setSubscriptionLatest;
exports.statsReducer = statsReducer; exports.statsReducer = statsReducer;

1113
dist/bundle.js vendored

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,43 @@
// Auth Token // User
export const GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE'; export const GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE';
export const GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED'; export const GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED';
export const GENERATE_AUTH_TOKEN_SUCCESS = 'GENERATE_AUTH_TOKEN_SUCCESS'; export const GENERATE_AUTH_TOKEN_SUCCESS = 'GENERATE_AUTH_TOKEN_SUCCESS';
export const AUTHENTICATION_STARTED = 'AUTHENTICATION_STARTED';
export const AUTHENTICATION_SUCCESS = 'AUTHENTICATION_SUCCESS';
neb-b commented 2019-10-01 05:19:42 +02:00 (Migrated from github.com)
Review

We were importing all of these from lbry-redux. Not sure why

We were importing all of these from `lbry-redux`. Not sure why
export const AUTHENTICATION_FAILURE = 'AUTHENTICATION_FAILURE';
export const USER_EMAIL_DECLINE = 'USER_EMAIL_DECLINE';
export const USER_EMAIL_NEW_STARTED = 'USER_EMAIL_NEW_STARTED';
export const USER_EMAIL_NEW_SUCCESS = 'USER_EMAIL_NEW_SUCCESS';
export const USER_EMAIL_NEW_EXISTS = 'USER_EMAIL_NEW_EXISTS';
export const USER_EMAIL_NEW_FAILURE = 'USER_EMAIL_NEW_FAILURE';
export const USER_EMAIL_VERIFY_SET = 'USER_EMAIL_VERIFY_SET';
export const USER_EMAIL_VERIFY_STARTED = 'USER_EMAIL_VERIFY_STARTED';
export const USER_EMAIL_VERIFY_SUCCESS = 'USER_EMAIL_VERIFY_SUCCESS';
export const USER_EMAIL_VERIFY_FAILURE = 'USER_EMAIL_VERIFY_FAILURE';
export const USER_EMAIL_VERIFY_RETRY = 'USER_EMAIL_VERIFY_RETRY';
export const USER_PHONE_RESET = 'USER_PHONE_RESET';
export const USER_PHONE_NEW_STARTED = 'USER_PHONE_NEW_STARTED';
export const USER_PHONE_NEW_SUCCESS = 'USER_PHONE_NEW_SUCCESS';
export const USER_PHONE_NEW_FAILURE = 'USER_PHONE_NEW_FAILURE';
export const USER_PHONE_VERIFY_STARTED = 'USER_PHONE_VERIFY_STARTED';
export const USER_PHONE_VERIFY_SUCCESS = 'USER_PHONE_VERIFY_SUCCESS';
export const USER_PHONE_VERIFY_FAILURE = 'USER_PHONE_VERIFY_FAILURE';
export const USER_IDENTITY_VERIFY_STARTED = 'USER_IDENTITY_VERIFY_STARTED';
export const USER_IDENTITY_VERIFY_SUCCESS = 'USER_IDENTITY_VERIFY_SUCCESS';
export const USER_IDENTITY_VERIFY_FAILURE = 'USER_IDENTITY_VERIFY_FAILURE';
export const USER_FETCH_STARTED = 'USER_FETCH_STARTED';
export const USER_FETCH_SUCCESS = 'USER_FETCH_SUCCESS';
export const USER_FETCH_FAILURE = 'USER_FETCH_FAILURE';
export const USER_INVITE_STATUS_FETCH_STARTED = 'USER_INVITE_STATUS_FETCH_STARTED';
export const USER_INVITE_STATUS_FETCH_SUCCESS = 'USER_INVITE_STATUS_FETCH_SUCCESS';
export const USER_INVITE_STATUS_FETCH_FAILURE = 'USER_INVITE_STATUS_FETCH_FAILURE';
export const USER_INVITE_NEW_STARTED = 'USER_INVITE_NEW_STARTED';
export const USER_INVITE_NEW_SUCCESS = 'USER_INVITE_NEW_SUCCESS';
export const USER_INVITE_NEW_FAILURE = 'USER_INVITE_NEW_FAILURE';
export const FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS';
export const USER_YOUTUBE_IMPORT_STARTED = 'USER_YOUTUBE_IMPORT_STARTED';
export const USER_YOUTUBE_IMPORT_FAILURE = 'USER_YOUTUBE_IMPORT_FAILURE';
export const USER_YOUTUBE_IMPORT_SUCCESS = 'USER_YOUTUBE_IMPORT_SUCCESS';
// Claims // Claims
export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED'; export const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
@ -82,6 +118,7 @@ export const FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED';
// Cross-device Sync // Cross-device Sync
export const GET_SYNC_STARTED = 'GET_SYNC_STARTED'; export const GET_SYNC_STARTED = 'GET_SYNC_STARTED';
export const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; export const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED';
export const GET_SYNC_FAILED = 'GET_SYNC_FAILED';
export const SET_SYNC_STARTED = 'SET_SYNC_STARTED'; export const SET_SYNC_STARTED = 'SET_SYNC_STARTED';
export const SET_SYNC_FAILED = 'SET_SYNC_FAILED'; export const SET_SYNC_FAILED = 'SET_SYNC_FAILED';
export const SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED'; export const SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED';
@ -89,3 +126,4 @@ export const SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT';
export const SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED'; export const SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED';
export const SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED'; export const SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED';
export const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED'; export const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED';
export const SYNC_RESET = 'SYNC_RESET';

3
src/constants/youtube.js Normal file
View file

@ -0,0 +1,3 @@
export const NOT_TRANSFERRED = 'not_transferred';
export const PENDING_TRANSFER = 'pending_transfer';
export const COMPLETED_TRANSFER = 'completed_transfer';

View file

@ -1,4 +1,5 @@
import * as LBRYINC_ACTIONS from 'constants/action_types'; import * as LBRYINC_ACTIONS from 'constants/action_types';
import * as YOUTUBE_STATUSES from 'constants/youtube';
import Lbryio from 'lbryio'; import Lbryio from 'lbryio';
import rewards from 'rewards'; import rewards from 'rewards';
import subscriptionsReducer from 'redux/reducers/subscriptions'; import subscriptionsReducer from 'redux/reducers/subscriptions';
@ -7,7 +8,7 @@ import subscriptionsReducer from 'redux/reducers/subscriptions';
export { userStateSyncMiddleware } from 'redux/middleware/sync'; export { userStateSyncMiddleware } from 'redux/middleware/sync';
// constants // constants
export { LBRYINC_ACTIONS }; export { LBRYINC_ACTIONS, YOUTUBE_STATUSES };
// Lbryio and rewards // Lbryio and rewards
export { Lbryio, rewards }; export { Lbryio, rewards };
@ -58,6 +59,7 @@ export {
doUserIdentityVerify, doUserIdentityVerify,
doUserInviteNew, doUserInviteNew,
doClaimYoutubeChannels, doClaimYoutubeChannels,
doCheckYoutubeTransfer,
} from 'redux/actions/user'; } from 'redux/actions/user';
export { doFetchCostInfoForUri } from 'redux/actions/cost_info'; export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist'; export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
@ -70,6 +72,7 @@ export {
doSetSync, doSetSync,
doSetDefaultAccount, doSetDefaultAccount,
doSyncApply, doSyncApply,
doResetSync,
} from 'redux/actions/sync'; } from 'redux/actions/sync';
// reducers // reducers
@ -153,8 +156,9 @@ export {
selectUserInviteReferralLink, selectUserInviteReferralLink,
selectUserVerifiedEmail, selectUserVerifiedEmail,
selectYoutubeChannels, selectYoutubeChannels,
selectYTImportPending, selectYouTubeImportPending,
selectYTImportError, selectYouTubeImportError,
selectYouTubeImportVideosComplete,
} from 'redux/selectors/user'; } from 'redux/selectors/user';
export { export {
makeSelectFetchingCostInfoForUri, makeSelectFetchingCostInfoForUri,
@ -176,6 +180,7 @@ export {
selectSyncData, selectSyncData,
selectSyncHash, selectSyncHash,
selectSetSyncErrorMessage, selectSetSyncErrorMessage,
selectGetSyncErrorMessage,
selectGetSyncIsPending, selectGetSyncIsPending,
selectSetSyncIsPending, selectSetSyncIsPending,
selectSyncApplyIsPending, selectSyncApplyIsPending,

View file

@ -1,5 +1,5 @@
import Lbryio from 'lbryio'; import Lbryio from 'lbryio';
import { ACTIONS, doToast } from 'lbry-redux'; import { ACTIONS, doToast, doUpdateBalance } from 'lbry-redux';
import { selectUnclaimedRewards } from 'redux/selectors/rewards'; import { selectUnclaimedRewards } from 'redux/selectors/rewards';
import { selectUserIsRewardApproved } from 'redux/selectors/user'; import { selectUserIsRewardApproved } from 'redux/selectors/user';
import { doFetchInviteStatus } from 'redux/actions/user'; import { doFetchInviteStatus } from 'redux/actions/user';
@ -71,6 +71,9 @@ export function doClaimRewardType(rewardType, options = {}) {
}); });
const success = successReward => { const success = successReward => {
// Temporary timeout to ensure the sdk has the correct balance after claiming a reward
setTimeout(() => {
dispatch(doUpdateBalance()).then(() => {
dispatch({ dispatch({
type: ACTIONS.CLAIM_REWARD_SUCCESS, type: ACTIONS.CLAIM_REWARD_SUCCESS,
data: { data: {
@ -91,6 +94,8 @@ export function doClaimRewardType(rewardType, options = {}) {
if (options.callback) { if (options.callback) {
options.callback(); options.callback();
} }
});
}, 1000);
}; };
const failure = error => { const failure = error => {
@ -111,7 +116,7 @@ export function doClaimRewardType(rewardType, options = {}) {
} }
}; };
rewards.claimReward(rewardType, params).then(success, failure); return rewards.claimReward(rewardType, params).then(success, failure);
}; };
} }

View file

@ -1,35 +1,6 @@
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import Lbryio from 'lbryio'; import Lbryio from 'lbryio';
import { Lbry } from 'lbry-redux'; import { Lbry, doFetchChannelListMine } from 'lbry-redux';
export function doSetSync(oldHash, newHash, data) {
return dispatch => {
dispatch({
type: ACTIONS.SET_SYNC_STARTED,
});
Lbryio.call('sync', 'set', { old_hash: oldHash, new_hash: newHash, data }, 'post')
.then(response => {
if (!response.hash) {
return dispatch({
type: ACTIONS.SET_SYNC_FAILED,
data: { error: 'No hash returned for sync/set.' },
});
}
return dispatch({
type: ACTIONS.SET_SYNC_COMPLETED,
data: { syncHash: response.hash },
});
})
.catch(error => {
dispatch({
type: ACTIONS.SET_SYNC_FAILED,
data: { error },
});
});
};
}
export function doSetDefaultAccount(success, failure) { export function doSetDefaultAccount(success, failure) {
return dispatch => { return dispatch => {
@ -67,12 +38,10 @@ export function doSetDefaultAccount(success, failure) {
failure(err); failure(err);
} }
}); });
} else { } else if (failure) {
// no default account to set // no default account to set
if (failure) {
failure('Could not set a default account'); // fail failure('Could not set a default account'); // fail
} }
}
}) })
.catch(err => { .catch(err => {
if (failure) { if (failure) {
@ -82,26 +51,67 @@ export function doSetDefaultAccount(success, failure) {
}; };
} }
export function doGetSync(password) { export function doSetSync(oldHash, newHash, data) {
return dispatch => {
dispatch({
type: ACTIONS.SET_SYNC_STARTED,
});
return Lbryio.call('sync', 'set', { old_hash: oldHash, new_hash: newHash, data }, 'post')
.then(response => {
if (!response.hash) {
throw Error('No hash returned for sync/set.');
}
return dispatch({
type: ACTIONS.SET_SYNC_COMPLETED,
data: { syncHash: response.hash },
});
})
.catch(error => {
dispatch({
type: ACTIONS.SET_SYNC_FAILED,
data: { error },
});
});
};
}
export function doGetSync(password = '', shouldSetDefaultAccount) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
type: ACTIONS.GET_SYNC_STARTED, type: ACTIONS.GET_SYNC_STARTED,
}); });
const data = {};
Lbry.sync_hash().then(hash => { Lbry.sync_hash().then(hash => {
Lbryio.call('sync', 'get', { hash }, 'post') Lbryio.call('sync', 'get', { hash }, 'post')
.then(response => { .then(response => {
const data = { hasSyncedWallet: true };
if (response.changed) {
const syncHash = response.hash; const syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data; data.syncData = response.data;
data.hasSyncedWallet = true;
Lbry.sync_apply({ password, data: response.data }).then( if (response.changed || shouldSetDefaultAccount) {
return Lbry.sync_apply({ password, data: response.data }).then(
({ hash: walletHash, data: walletData }) => { ({ hash: walletHash, data: walletData }) => {
if (walletHash !== syncHash) { dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
if (walletHash !== syncHash || shouldSetDefaultAccount) {
// different local hash, need to synchronise // different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData)); dispatch(doSetSync(syncHash, walletHash, walletData));
if (shouldSetDefaultAccount) {
dispatch(
doSetDefaultAccount(() => {
Lbry.status().then(status => {
if (status.wallet.is_locked) {
Lbry.account_unlock({ password });
}
dispatch(doFetchChannelListMine());
});
})
);
}
} }
} }
); );
@ -110,6 +120,14 @@ export function doGetSync(password) {
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
}) })
.catch(() => { .catch(() => {
if (data.hasSyncedWallet) {
dispatch({
type: ACTIONS.GET_SYNC_FAILED,
data: {
error: 'Error getting synced wallet',
},
});
} else {
// user doesn't have a synced wallet // user doesn't have a synced wallet
dispatch({ dispatch({
type: ACTIONS.GET_SYNC_COMPLETED, type: ACTIONS.GET_SYNC_COMPLETED,
@ -118,9 +136,10 @@ export function doGetSync(password) {
// call sync_apply to get data to sync // call sync_apply to get data to sync
// first time sync. use any string for old hash // first time sync. use any string for old hash
Lbry.sync_apply({ password }).then(({ hash: walletHash, data }) => Lbry.sync_apply({ password }).then(({ hash: walletHash, data: syncApplyData }) =>
dispatch(doSetSync('', walletHash, data)) dispatch(doSetSync('', walletHash, syncApplyData, password))
); );
}
}); });
}); });
}; };
@ -182,3 +201,11 @@ export function doCheckSync() {
}); });
}; };
} }
export function doResetSync() {
return dispatch =>
new Promise(resolve => {
dispatch({ type: ACTIONS.SYNC_RESET });
resolve();
});
}

View file

@ -1,4 +1,5 @@
import { ACTIONS, Lbry, doToast, doFetchChannelListMine, batchActions } from 'lbry-redux'; import { Lbry, doToast, doFetchChannelListMine, batchActions } from 'lbry-redux';
import * as ACTIONS from 'constants/action_types';
import { doClaimRewardType, doRewardList } from 'redux/actions/rewards'; import { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
import { import {
selectEmailToVerify, selectEmailToVerify,
@ -84,9 +85,7 @@ export function doUserFetch() {
}); });
Lbryio.getCurrentUser() Lbryio.getCurrentUser()
.then(user => { .then(user => {
// analytics.setUser(user);
dispatch(doRewardList()); dispatch(doRewardList());
dispatch({ dispatch({
type: ACTIONS.USER_FETCH_SUCCESS, type: ACTIONS.USER_FETCH_SUCCESS,
data: { user }, data: { user },
@ -388,15 +387,18 @@ export function doClaimYoutubeChannels() {
dispatch({ dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_STARTED, type: ACTIONS.USER_YOUTUBE_IMPORT_STARTED,
}); });
Lbry.address_list()
let transferResponse;
return Lbry.address_list()
.then(addressList => addressList.sort((a, b) => a.used_times - b.used_times)[0]) .then(addressList => addressList.sort((a, b) => a.used_times - b.used_times)[0])
.then(address => .then(address =>
Lbryio.call('yt', 'transfer', { Lbryio.call('yt', 'transfer', {
address: address.address, address: address.address,
public_key: address.pubkey, public_key: address.pubkey,
}).then(response => { }).then(response => {
if (response && response.success) { if (response && response.length) {
Promise.all( transferResponse = response;
return Promise.all(
response.map(channelMeta => { response.map(channelMeta => {
if (channelMeta && channelMeta.channel && channelMeta.channel.channel_certificate) { if (channelMeta && channelMeta.channel && channelMeta.channel.channel_certificate) {
return Lbry.channel_import({ return Lbry.channel_import({
@ -408,7 +410,8 @@ export function doClaimYoutubeChannels() {
).then(() => { ).then(() => {
const actions = [ const actions = [
{ {
type: ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED, type: ACTIONS.USER_YOUTUBE_IMPORT_SUCCESS,
data: transferResponse,
}, },
]; ];
actions.push(doUserFetch()); actions.push(doUserFetch());
@ -426,3 +429,29 @@ export function doClaimYoutubeChannels() {
}); });
}; };
} }
export function doCheckYoutubeTransfer() {
return dispatch => {
dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_STARTED,
});
return Lbryio.call('yt', 'transfer')
.then(response => {
if (response && response.length) {
dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_SUCCESS,
data: response,
});
} else {
throw new Error();
}
})
.catch(error => {
dispatch({
type: ACTIONS.USER_YOUTUBE_IMPORT_FAILURE,
data: String(error),
});
});
};
}

View file

@ -6,6 +6,7 @@ const defaultState = {
syncHash: null, syncHash: null,
syncData: null, syncData: null,
setSyncErrorMessage: null, setSyncErrorMessage: null,
getSyncErrorMessage: null,
syncApplyErrorMessage: '', syncApplyErrorMessage: '',
syncApplyIsPending: false, syncApplyIsPending: false,
getSyncIsPending: false, getSyncIsPending: false,
@ -16,6 +17,7 @@ const defaultState = {
reducers[ACTIONS.GET_SYNC_STARTED] = state => reducers[ACTIONS.GET_SYNC_STARTED] = state =>
Object.assign({}, state, { Object.assign({}, state, {
getSyncIsPending: true, getSyncIsPending: true,
getSyncErrorMessage: null,
}); });
reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) => reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) =>
@ -27,6 +29,12 @@ reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) =>
hashChanged: action.data.hashChanged, hashChanged: action.data.hashChanged,
}); });
reducers[ACTIONS.GET_SYNC_FAILED] = (state, action) =>
Object.assign({}, state, {
getSyncIsPending: false,
getSyncErrorMessage: action.data.error,
});
reducers[ACTIONS.SET_SYNC_STARTED] = state => reducers[ACTIONS.SET_SYNC_STARTED] = state =>
Object.assign({}, state, { Object.assign({}, state, {
setSyncIsPending: true, setSyncIsPending: true,
@ -65,6 +73,8 @@ reducers[ACTIONS.SYNC_APPLY_FAILED] = (state, action) =>
syncApplyErrorMessage: action.data.error, syncApplyErrorMessage: action.data.error,
}); });
reducers[ACTIONS.SYNC_RESET] = () => defaultState;
export function syncReducer(state = defaultState, action) { export function syncReducer(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

@ -1,4 +1,4 @@
import { ACTIONS } from 'lbry-redux'; import * as ACTIONS from 'constants/action_types';
const reducers = {}; const reducers = {};
@ -14,8 +14,8 @@ const defaultState = {
invitesRemaining: undefined, invitesRemaining: undefined,
invitees: undefined, invitees: undefined,
user: undefined, user: undefined,
ytChannelImportPending: false, youtubeChannelImportPending: false,
ytChannelImportErrorMessage: '', youtubeChannelImportErrorMessage: '',
}; };
reducers[ACTIONS.AUTHENTICATION_STARTED] = state => reducers[ACTIONS.AUTHENTICATION_STARTED] = state =>
@ -225,20 +225,27 @@ reducers[ACTIONS.USER_INVITE_STATUS_FETCH_FAILURE] = state =>
reducers[ACTIONS.USER_YOUTUBE_IMPORT_STARTED] = state => reducers[ACTIONS.USER_YOUTUBE_IMPORT_STARTED] = state =>
Object.assign({}, state, { Object.assign({}, state, {
ytChannelImportPending: true, youtubeChannelImportPending: true,
ytChannelImportErrorMessage: '', youtubeChannelImportErrorMessage: '',
}); });
reducers[ACTIONS.USER_YOUTUBE_IMPORT_COMPLETED] = state => reducers[ACTIONS.USER_YOUTUBE_IMPORT_SUCCESS] = (state, action) => {
Object.assign({}, state, { const total = action.data.reduce((acc, value) => acc + value.total_published_videos, 0);
ytChannelImportPending: false,
ytChannelImportErrorMessage: '', const complete = action.data.reduce((acc, value) => acc + value.total_transferred, 0);
return Object.assign({}, state, {
youtubeChannelImportPending: false,
youtubeChannelImportErrorMessage: '',
youtubeChannelImportTotal: total,
youtubeChannelImportComplete: complete,
}); });
};
reducers[ACTIONS.USER_YOUTUBE_IMPORT_FAILURE] = (state, action) => reducers[ACTIONS.USER_YOUTUBE_IMPORT_FAILURE] = (state, action) =>
Object.assign({}, state, { Object.assign({}, state, {
ytChannelImportPending: false, youtubeChannelImportPending: false,
ytChannelImportErrorMessage: action.data, youtubeChannelImportErrorMessage: action.data,
}); });
export function userReducer(state = defaultState, action) { export function userReducer(state = defaultState, action) {

View file

@ -13,6 +13,11 @@ export const selectSetSyncErrorMessage = createSelector(
state => state.setSyncErrorMessage state => state.setSyncErrorMessage
); );
export const selectGetSyncErrorMessage = createSelector(
selectState,
state => state.getSyncErrorMessage
);
export const selectGetSyncIsPending = createSelector(selectState, state => state.getSyncIsPending); export const selectGetSyncIsPending = createSelector(selectState, state => state.getSyncIsPending);
export const selectSetSyncIsPending = createSelector(selectState, state => state.setSyncIsPending); export const selectSetSyncIsPending = createSelector(selectState, state => state.setSyncIsPending);

View file

@ -142,12 +142,21 @@ export const selectUserInviteReferralLink = createSelector(
state => state.referralLink state => state.referralLink
); );
export const selectYTImportPending = createSelector( export const selectYouTubeImportPending = createSelector(
selectState, selectState,
state => state.ytChannelImportPending state => state.youtubeChannelImportPending
); );
export const selectYTImportError = createSelector( export const selectYouTubeImportError = createSelector(
selectState, selectState,
state => state.ytChannelImportErrorMessage state => state.youtubeChannelImportErrorMessage
); );
export const selectYouTubeImportVideosComplete = createSelector(selectState, state => {
const total = state.youtubeChannelImportTotal;
const complete = state.youtubeChannelImportComplete || 0;
if (total) {
return [complete, total];
}
});