add doSyncApply action. rename some state properties.

This commit is contained in:
Akinwale Ariwodola 2019-05-24 18:06:20 +01:00
parent 54ef55d430
commit 470b47a0ee
7 changed files with 278 additions and 43 deletions

94
dist/bundle.es.js vendored
View file

@ -79,6 +79,9 @@ 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';
const SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT'; const SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT';
const SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED';
const SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED';
const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED';
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,
@ -144,7 +147,10 @@ var action_types = /*#__PURE__*/Object.freeze({
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_COMPLETED: SYNC_APPLY_COMPLETED,
SYNC_APPLY_FAILED: SYNC_APPLY_FAILED
}); });
const Lbryio = { const Lbryio = {
@ -2063,6 +2069,7 @@ function doGetSync(password) {
if (response.changed) { if (response.changed) {
const syncHash = response.hash; const syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data;
lbryRedux.Lbry.sync_apply({ lbryRedux.Lbry.sync_apply({
password, password,
data: response.data data: response.data
@ -2105,6 +2112,39 @@ function doGetSync(password) {
}); });
}; };
} }
function doSyncApply(syncHash, syncData, password) {
return dispatch => {
dispatch({
type: SYNC_APPLY_STARTED
});
lbryRedux.Lbry.sync_apply({
password,
data: syncData
}).then(({
hash: walletHash,
data: walletData
}) => {
dispatch({
type: SYNC_APPLY_COMPLETED
});
if (walletHash !== syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData));
} // set the default account
dispatch(doSetDefaultAccount());
}).catch(error => {
dispatch({
type: SYNC_APPLY_FAILED,
data: {
error: 'Invalid password. Please provide the password for your previously synchronised wallet.'
}
});
});
};
}
function doCheckSync() { function doCheckSync() {
return dispatch => { return dispatch => {
dispatch({ dispatch({
@ -2115,7 +2155,9 @@ function doCheckSync() {
hash hash
}, 'post').then(response => { }, 'post').then(response => {
const data = { const data = {
hasSyncedWallet: true hasSyncedWallet: true,
syncHash: response.hash,
syncData: response.data
}; };
dispatch({ dispatch({
type: GET_SYNC_COMPLETED, type: GET_SYNC_COMPLETED,
@ -2610,39 +2652,58 @@ const reducers$3 = {};
const defaultState$8 = { const defaultState$8 = {
hasSyncedWallet: false, hasSyncedWallet: false,
syncHash: null, syncHash: null,
syncData: null,
setSyncErrorMessage: null, setSyncErrorMessage: null,
retrievingSync: false, syncApplyErrorMessage: '',
settingSync: false syncApplyIsPending: false,
getSyncIsPending: false,
setSyncIsPending: false
}; };
reducers$3[GET_SYNC_STARTED] = state => Object.assign({}, state, { reducers$3[GET_SYNC_STARTED] = state => Object.assign({}, state, {
retrievingSync: true getSyncIsPending: true
}); });
reducers$3[GET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, { reducers$3[GET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
syncHash: action.data.syncHash, syncHash: action.data.syncHash,
syncData: action.data.syncData,
hasSyncedWallet: action.data.hasSyncedWallet, hasSyncedWallet: action.data.hasSyncedWallet,
retrievingSync: false getSyncIsPending: false
}); });
reducers$3[SET_SYNC_STARTED] = state => Object.assign({}, state, { reducers$3[SET_SYNC_STARTED] = state => Object.assign({}, state, {
settingSync: true, setSyncIsPending: true,
setSyncErrorMessage: null setSyncErrorMessage: null
}); });
reducers$3[SET_SYNC_FAILED] = (state, action) => Object.assign({}, state, { reducers$3[SET_SYNC_FAILED] = (state, action) => Object.assign({}, state, {
settingSync: true, setSyncIsPending: false,
setSyncErrorMessage: action.data.error setSyncErrorMessage: action.data.error
}); });
reducers$3[SET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, { reducers$3[SET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
settingSync: false, setSyncIsPending: false,
setSyncErrorMessage: null, setSyncErrorMessage: null,
hasSyncedWallet: true, hasSyncedWallet: true,
// sync was successful, so the user has a synced wallet at this point // sync was successful, so the user has a synced wallet at this point
syncHash: action.data.syncHash syncHash: action.data.syncHash
}); });
reducers$3[SYNC_APPLY_STARTED] = state => Object.assign({}, state, {
syncApplyIsPending: true,
syncApplyErrorMessage: ''
});
reducers$3[SYNC_APPLY_COMPLETED] = state => Object.assign({}, state, {
syncApplyIsPending: false,
syncApplyErrorMessage: ''
});
reducers$3[SYNC_APPLY_FAILED] = (state, action) => Object.assign({}, state, {
syncApplyIsPending: false,
syncApplyErrorMessage: action.data.error
});
function syncReducer(state = defaultState$8, action) { function syncReducer(state = defaultState$8, 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);
@ -2679,9 +2740,12 @@ const selectState$8 = state => state.sync || {};
const selectHasSyncedWallet = reselect.createSelector(selectState$8, state => state.hasSyncedWallet); const selectHasSyncedWallet = reselect.createSelector(selectState$8, state => state.hasSyncedWallet);
const selectSyncHash = reselect.createSelector(selectState$8, state => state.syncHash); const selectSyncHash = reselect.createSelector(selectState$8, state => state.syncHash);
const selectSyncData = reselect.createSelector(selectState$8, state => state.syncData);
const selectSetSyncErrorMessage = reselect.createSelector(selectState$8, state => state.setSyncErrorMessage); const selectSetSyncErrorMessage = reselect.createSelector(selectState$8, state => state.setSyncErrorMessage);
const selectIsRetrievingSync = reselect.createSelector(selectState$8, state => state.retrievingSync); const selectGetSyncIsPending = reselect.createSelector(selectState$8, state => state.getSyncIsPending);
const selectIsSettingSync = reselect.createSelector(selectState$8, state => state.settingSync); const selectSetSyncIsPending = reselect.createSelector(selectState$8, state => state.setSyncIsPending);
const selectSyncApplyIsPending = reselect.createSelector(selectState$8, state => state.syncApplyIsPending);
const selectSyncApplyErrorMessage = reselect.createSelector(selectState$8, state => state.syncApplyErrorMessage);
exports.LBRYINC_ACTIONS = action_types; exports.LBRYINC_ACTIONS = action_types;
exports.Lbryio = Lbryio; exports.Lbryio = Lbryio;
@ -2721,6 +2785,7 @@ exports.doSetDefaultAccount = doSetDefaultAccount;
exports.doSetSync = doSetSync; exports.doSetSync = doSetSync;
exports.doSetViewMode = doSetViewMode; exports.doSetViewMode = doSetViewMode;
exports.doShowSuggestedSubs = doShowSuggestedSubs; exports.doShowSuggestedSubs = doShowSuggestedSubs;
exports.doSyncApply = doSyncApply;
exports.doUpdateUnreadSubscriptions = doUpdateUnreadSubscriptions; exports.doUpdateUnreadSubscriptions = doUpdateUnreadSubscriptions;
exports.doUserCheckEmailVerified = doUserCheckEmailVerified; exports.doUserCheckEmailVerified = doUserCheckEmailVerified;
exports.doUserEmailNew = doUserEmailNew; exports.doUserEmailNew = doUserEmailNew;
@ -2770,14 +2835,13 @@ exports.selectFetchingFeaturedUris = selectFetchingFeaturedUris;
exports.selectFetchingRewards = selectFetchingRewards; exports.selectFetchingRewards = selectFetchingRewards;
exports.selectFetchingTrendingUris = selectFetchingTrendingUris; exports.selectFetchingTrendingUris = selectFetchingTrendingUris;
exports.selectFirstRunCompleted = selectFirstRunCompleted; exports.selectFirstRunCompleted = selectFirstRunCompleted;
exports.selectGetSyncIsPending = selectGetSyncIsPending;
exports.selectHasSyncedWallet = selectHasSyncedWallet; exports.selectHasSyncedWallet = selectHasSyncedWallet;
exports.selectIdentityVerifyErrorMessage = selectIdentityVerifyErrorMessage; exports.selectIdentityVerifyErrorMessage = selectIdentityVerifyErrorMessage;
exports.selectIdentityVerifyIsPending = selectIdentityVerifyIsPending; exports.selectIdentityVerifyIsPending = selectIdentityVerifyIsPending;
exports.selectIsAuthenticating = selectIsAuthenticating; exports.selectIsAuthenticating = selectIsAuthenticating;
exports.selectIsFetchingSubscriptions = selectIsFetchingSubscriptions; exports.selectIsFetchingSubscriptions = selectIsFetchingSubscriptions;
exports.selectIsFetchingSuggested = selectIsFetchingSuggested; exports.selectIsFetchingSuggested = selectIsFetchingSuggested;
exports.selectIsRetrievingSync = selectIsRetrievingSync;
exports.selectIsSettingSync = selectIsSettingSync;
exports.selectPhoneNewErrorMessage = selectPhoneNewErrorMessage; exports.selectPhoneNewErrorMessage = selectPhoneNewErrorMessage;
exports.selectPhoneNewIsPending = selectPhoneNewIsPending; exports.selectPhoneNewIsPending = selectPhoneNewIsPending;
exports.selectPhoneToVerify = selectPhoneToVerify; exports.selectPhoneToVerify = selectPhoneToVerify;
@ -2786,12 +2850,16 @@ exports.selectPhoneVerifyIsPending = selectPhoneVerifyIsPending;
exports.selectReferralReward = selectReferralReward; exports.selectReferralReward = selectReferralReward;
exports.selectRewardContentClaimIds = selectRewardContentClaimIds; exports.selectRewardContentClaimIds = selectRewardContentClaimIds;
exports.selectSetSyncErrorMessage = selectSetSyncErrorMessage; exports.selectSetSyncErrorMessage = selectSetSyncErrorMessage;
exports.selectSetSyncIsPending = selectSetSyncIsPending;
exports.selectShowSuggestedSubs = selectShowSuggestedSubs; exports.selectShowSuggestedSubs = selectShowSuggestedSubs;
exports.selectSubscriptionClaims = selectSubscriptionClaims; exports.selectSubscriptionClaims = selectSubscriptionClaims;
exports.selectSubscriptions = selectSubscriptions; exports.selectSubscriptions = selectSubscriptions;
exports.selectSubscriptionsBeingFetched = selectSubscriptionsBeingFetched; exports.selectSubscriptionsBeingFetched = selectSubscriptionsBeingFetched;
exports.selectSuggested = selectSuggested; exports.selectSuggested = selectSuggested;
exports.selectSuggestedChannels = selectSuggestedChannels; exports.selectSuggestedChannels = selectSuggestedChannels;
exports.selectSyncApplyErrorMessage = selectSyncApplyErrorMessage;
exports.selectSyncApplyIsPending = selectSyncApplyIsPending;
exports.selectSyncData = selectSyncData;
exports.selectSyncHash = selectSyncHash; exports.selectSyncHash = selectSyncHash;
exports.selectTrendingUris = selectTrendingUris; exports.selectTrendingUris = selectTrendingUris;
exports.selectUnclaimedRewardValue = selectUnclaimedRewardValue; exports.selectUnclaimedRewardValue = selectUnclaimedRewardValue;

119
dist/bundle.js vendored
View file

@ -216,6 +216,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doSetDefaultAccount", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doSetDefaultAccount"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doSetDefaultAccount", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doSetDefaultAccount"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doSyncApply", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doSyncApply"]; });
/* harmony import */ var redux_reducers_auth__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(26); /* harmony import */ var redux_reducers_auth__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(26);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "authReducer", function() { return redux_reducers_auth__WEBPACK_IMPORTED_MODULE_13__["authReducer"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "authReducer", function() { return redux_reducers_auth__WEBPACK_IMPORTED_MODULE_13__["authReducer"]; });
@ -395,13 +397,19 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(39); /* harmony import */ var redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(39);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectHasSyncedWallet", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectHasSyncedWallet"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectHasSyncedWallet", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectHasSyncedWallet"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSyncData", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSyncData"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSyncHash", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSyncHash"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSyncHash", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSyncHash"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSetSyncErrorMessage", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSetSyncErrorMessage"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSetSyncErrorMessage", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSetSyncErrorMessage"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectIsRetrievingSync", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectIsRetrievingSync"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectGetSyncIsPending", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectGetSyncIsPending"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectIsSettingSync", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectIsSettingSync"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSetSyncIsPending", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSetSyncIsPending"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSyncApplyIsPending", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSyncApplyIsPending"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectSyncApplyErrorMessage", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_29__["selectSyncApplyErrorMessage"]; });
@ -512,6 +520,9 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_SYNC_FAILED", function() { return SET_SYNC_FAILED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_SYNC_FAILED", function() { return SET_SYNC_FAILED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_SYNC_COMPLETED", function() { return SET_SYNC_COMPLETED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_SYNC_COMPLETED", function() { return SET_SYNC_COMPLETED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_DEFAULT_ACCOUNT", function() { return SET_DEFAULT_ACCOUNT; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_DEFAULT_ACCOUNT", function() { return SET_DEFAULT_ACCOUNT; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SYNC_APPLY_STARTED", function() { return SYNC_APPLY_STARTED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SYNC_APPLY_COMPLETED", function() { return SYNC_APPLY_COMPLETED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SYNC_APPLY_FAILED", function() { return SYNC_APPLY_FAILED; });
// Auth Token // Auth Token
var GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE'; var GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE';
var GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED'; var GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED';
@ -583,6 +594,9 @@ var SET_SYNC_STARTED = 'SET_SYNC_STARTED';
var SET_SYNC_FAILED = 'SET_SYNC_FAILED'; var SET_SYNC_FAILED = 'SET_SYNC_FAILED';
var SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED'; var SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED';
var SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT'; var SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT';
var SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED';
var SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED';
var SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED';
/***/ }), /***/ }),
/* 2 */ /* 2 */
@ -3403,6 +3417,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSetSync", function() { return doSetSync; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSetSync", function() { return doSetSync; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSetDefaultAccount", function() { return doSetDefaultAccount; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSetDefaultAccount", function() { return doSetDefaultAccount; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doGetSync", function() { return doGetSync; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doGetSync", function() { return doGetSync; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSyncApply", function() { return doSyncApply; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return doCheckSync; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return doCheckSync; });
/* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); /* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
/* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); /* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
@ -3494,6 +3509,7 @@ function doGetSync(password) {
if (response.changed) { if (response.changed) {
var syncHash = response.hash; var syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data;
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({ lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password, password: password,
data: response.data data: response.data
@ -3537,6 +3553,38 @@ function doGetSync(password) {
}); });
}; };
} }
function doSyncApply(syncHash, syncData, password) {
return function (dispatch) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_STARTED"]
});
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password,
data: syncData
}).then(function (_ref3) {
var walletHash = _ref3.hash,
walletData = _ref3.data;
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_COMPLETED"]
});
if (walletHash !== syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData));
} // set the default account
dispatch(doSetDefaultAccount());
})["catch"](function (error) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_FAILED"],
data: {
error: 'Invalid password. Please provide the password for your previously synchronised wallet.'
}
});
});
};
}
function doCheckSync() { function doCheckSync() {
return function (dispatch) { return function (dispatch) {
dispatch({ dispatch({
@ -3547,7 +3595,9 @@ function doCheckSync() {
hash: hash hash: hash
}, 'post').then(function (response) { }, 'post').then(function (response) {
var data = { var data = {
hasSyncedWallet: true hasSyncedWallet: true,
syncHash: response.hash,
syncData: response.data
}; };
dispatch({ dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"], type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
@ -4201,42 +4251,46 @@ var reducers = {};
var defaultState = { var defaultState = {
hasSyncedWallet: false, hasSyncedWallet: false,
syncHash: null, syncHash: null,
syncData: null,
setSyncErrorMessage: null, setSyncErrorMessage: null,
retrievingSync: false, syncApplyErrorMessage: '',
settingSync: false syncApplyIsPending: false,
getSyncIsPending: false,
setSyncIsPending: false
}; };
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_STARTED"]] = function (state) { reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_STARTED"]] = function (state) {
return Object.assign({}, state, { return Object.assign({}, state, {
retrievingSync: true getSyncIsPending: true
}); });
}; };
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"]] = function (state, action) { reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"]] = function (state, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
syncHash: action.data.syncHash, syncHash: action.data.syncHash,
syncData: action.data.syncData,
hasSyncedWallet: action.data.hasSyncedWallet, hasSyncedWallet: action.data.hasSyncedWallet,
retrievingSync: false getSyncIsPending: false
}); });
}; };
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_STARTED"]] = function (state) { reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_STARTED"]] = function (state) {
return Object.assign({}, state, { return Object.assign({}, state, {
settingSync: true, setSyncIsPending: true,
setSyncErrorMessage: null setSyncErrorMessage: null
}); });
}; };
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_FAILED"]] = function (state, action) { reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_FAILED"]] = function (state, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
settingSync: true, setSyncIsPending: false,
setSyncErrorMessage: action.data.error setSyncErrorMessage: action.data.error
}); });
}; };
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_COMPLETED"]] = function (state, action) { reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_COMPLETED"]] = function (state, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
settingSync: false, setSyncIsPending: false,
setSyncErrorMessage: null, setSyncErrorMessage: null,
hasSyncedWallet: true, hasSyncedWallet: true,
// sync was successful, so the user has a synced wallet at this point // sync was successful, so the user has a synced wallet at this point
@ -4244,6 +4298,27 @@ reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_COMPLETED
}); });
}; };
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_STARTED"]] = function (state) {
return Object.assign({}, state, {
syncApplyIsPending: true,
syncApplyErrorMessage: ''
});
};
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_COMPLETED"]] = function (state) {
return Object.assign({}, state, {
syncApplyIsPending: false,
syncApplyErrorMessage: ''
});
};
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_FAILED"]] = function (state, action) {
return Object.assign({}, state, {
syncApplyIsPending: false,
syncApplyErrorMessage: action.data.error
});
};
function syncReducer() { function syncReducer() {
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;
@ -4394,9 +4469,12 @@ var makeSelectViewCountForUri = function makeSelectViewCountForUri(uri) {
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectHasSyncedWallet", function() { return selectHasSyncedWallet; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectHasSyncedWallet", function() { return selectHasSyncedWallet; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSyncHash", function() { return selectSyncHash; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSyncHash", function() { return selectSyncHash; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSyncData", function() { return selectSyncData; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSetSyncErrorMessage", function() { return selectSetSyncErrorMessage; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSetSyncErrorMessage", function() { return selectSetSyncErrorMessage; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectIsRetrievingSync", function() { return selectIsRetrievingSync; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectGetSyncIsPending", function() { return selectGetSyncIsPending; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectIsSettingSync", function() { return selectIsSettingSync; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSetSyncIsPending", function() { return selectSetSyncIsPending; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSyncApplyIsPending", function() { return selectSyncApplyIsPending; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSyncApplyErrorMessage", function() { return selectSyncApplyErrorMessage; });
/* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(14); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(14);
/* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__);
@ -4411,14 +4489,23 @@ var selectHasSyncedWallet = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["create
var selectSyncHash = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { var selectSyncHash = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.syncHash; return state.syncHash;
}); });
var selectSyncData = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.syncData;
});
var selectSetSyncErrorMessage = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { var selectSetSyncErrorMessage = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.setSyncErrorMessage; return state.setSyncErrorMessage;
}); });
var selectIsRetrievingSync = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { var selectGetSyncIsPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.retrievingSync; return state.getSyncIsPending;
}); });
var selectIsSettingSync = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { var selectSetSyncIsPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.settingSync; return state.setSyncIsPending;
});
var selectSyncApplyIsPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.syncApplyIsPending;
});
var selectSyncApplyErrorMessage = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.syncApplyErrorMessage;
}); });
/***/ }) /***/ })

View file

@ -77,3 +77,6 @@ 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';
export const SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT'; export const SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT';
export const SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED';
export const SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED';
export const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED';

View file

@ -59,7 +59,13 @@ export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist'; export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage'; export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage';
export { doFetchViewCount } from 'redux/actions/stats'; export { doFetchViewCount } from 'redux/actions/stats';
export { doCheckSync, doGetSync, doSetSync, doSetDefaultAccount } from 'redux/actions/sync'; export {
doCheckSync,
doGetSync,
doSetSync,
doSetDefaultAccount,
doSyncApply,
} from 'redux/actions/sync';
// reducers // reducers
export { authReducer } from 'redux/reducers/auth'; export { authReducer } from 'redux/reducers/auth';
@ -156,8 +162,11 @@ export {
export { makeSelectViewCountForUri } from 'redux/selectors/stats'; export { makeSelectViewCountForUri } from 'redux/selectors/stats';
export { export {
selectHasSyncedWallet, selectHasSyncedWallet,
selectSyncData,
selectSyncHash, selectSyncHash,
selectSetSyncErrorMessage, selectSetSyncErrorMessage,
selectIsRetrievingSync, selectGetSyncIsPending,
selectIsSettingSync, selectSetSyncIsPending,
selectSyncApplyIsPending,
selectSyncApplyErrorMessage,
} from 'redux/selectors/sync'; } from 'redux/selectors/sync';

View file

@ -74,6 +74,8 @@ export function doGetSync(password) {
if (response.changed) { if (response.changed) {
const syncHash = response.hash; const syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data;
Lbry.sync_apply({ password, data: response.data }).then( Lbry.sync_apply({ password, data: response.data }).then(
({ hash: walletHash, data: walletData }) => { ({ hash: walletHash, data: walletData }) => {
if (walletHash !== syncHash) { if (walletHash !== syncHash) {
@ -106,6 +108,38 @@ export function doGetSync(password) {
}; };
} }
export function doSyncApply(syncHash, syncData, password) {
return dispatch => {
dispatch({
type: ACTIONS.SYNC_APPLY_STARTED,
});
Lbry.sync_apply({ password, data: syncData })
.then(({ hash: walletHash, data: walletData }) => {
dispatch({
type: ACTIONS.SYNC_APPLY_COMPLETED,
});
if (walletHash !== syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData));
}
// set the default account
dispatch(doSetDefaultAccount());
})
.catch(() => {
dispatch({
type: ACTIONS.SYNC_APPLY_FAILED,
data: {
error:
'Invalid password specified. Please enter the password for your previously synchronised wallet.',
},
});
});
};
}
export function doCheckSync() { export function doCheckSync() {
return dispatch => { return dispatch => {
dispatch({ dispatch({
@ -114,8 +148,8 @@ export function doCheckSync() {
Lbry.sync_hash().then(hash => { Lbry.sync_hash().then(hash => {
Lbryio.call('sync', 'get', { hash }, 'post') Lbryio.call('sync', 'get', { hash }, 'post')
.then(() => { .then(response => {
const data = { hasSyncedWallet: true }; const data = { hasSyncedWallet: true, syncHash: response.hash, syncData: response.data };
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
}) })
.catch(() => { .catch(() => {

View file

@ -4,43 +4,65 @@ const reducers = {};
const defaultState = { const defaultState = {
hasSyncedWallet: false, hasSyncedWallet: false,
syncHash: null, syncHash: null,
syncData: null,
setSyncErrorMessage: null, setSyncErrorMessage: null,
retrievingSync: false, syncApplyErrorMessage: '',
settingSync: false, syncApplyIsPending: false,
getSyncIsPending: false,
setSyncIsPending: false,
}; };
reducers[ACTIONS.GET_SYNC_STARTED] = state => reducers[ACTIONS.GET_SYNC_STARTED] = state =>
Object.assign({}, state, { Object.assign({}, state, {
retrievingSync: true, getSyncIsPending: true,
}); });
reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) => reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) =>
Object.assign({}, state, { Object.assign({}, state, {
syncHash: action.data.syncHash, syncHash: action.data.syncHash,
syncData: action.data.syncData,
hasSyncedWallet: action.data.hasSyncedWallet, hasSyncedWallet: action.data.hasSyncedWallet,
retrievingSync: false, getSyncIsPending: false,
}); });
reducers[ACTIONS.SET_SYNC_STARTED] = state => reducers[ACTIONS.SET_SYNC_STARTED] = state =>
Object.assign({}, state, { Object.assign({}, state, {
settingSync: true, setSyncIsPending: true,
setSyncErrorMessage: null, setSyncErrorMessage: null,
}); });
reducers[ACTIONS.SET_SYNC_FAILED] = (state, action) => reducers[ACTIONS.SET_SYNC_FAILED] = (state, action) =>
Object.assign({}, state, { Object.assign({}, state, {
settingSync: true, setSyncIsPending: false,
setSyncErrorMessage: action.data.error, setSyncErrorMessage: action.data.error,
}); });
reducers[ACTIONS.SET_SYNC_COMPLETED] = (state, action) => reducers[ACTIONS.SET_SYNC_COMPLETED] = (state, action) =>
Object.assign({}, state, { Object.assign({}, state, {
settingSync: false, setSyncIsPending: false,
setSyncErrorMessage: null, setSyncErrorMessage: null,
hasSyncedWallet: true, // sync was successful, so the user has a synced wallet at this point hasSyncedWallet: true, // sync was successful, so the user has a synced wallet at this point
syncHash: action.data.syncHash, syncHash: action.data.syncHash,
}); });
reducers[ACTIONS.SYNC_APPLY_STARTED] = state =>
Object.assign({}, state, {
syncApplyIsPending: true,
syncApplyErrorMessage: '',
});
reducers[ACTIONS.SYNC_APPLY_COMPLETED] = state =>
Object.assign({}, state, {
syncApplyIsPending: false,
syncApplyErrorMessage: '',
});
reducers[ACTIONS.SYNC_APPLY_FAILED] = (state, action) =>
Object.assign({}, state, {
syncApplyIsPending: false,
syncApplyErrorMessage: action.data.error,
});
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

@ -6,11 +6,23 @@ export const selectHasSyncedWallet = createSelector(selectState, state => state.
export const selectSyncHash = createSelector(selectState, state => state.syncHash); export const selectSyncHash = createSelector(selectState, state => state.syncHash);
export const selectSyncData = createSelector(selectState, state => state.syncData);
export const selectSetSyncErrorMessage = createSelector( export const selectSetSyncErrorMessage = createSelector(
selectState, selectState,
state => state.setSyncErrorMessage state => state.setSyncErrorMessage
); );
export const selectIsRetrievingSync = createSelector(selectState, state => state.retrievingSync); export const selectGetSyncIsPending = createSelector(selectState, state => state.getSyncIsPending);
export const selectIsSettingSync = createSelector(selectState, state => state.settingSync); export const selectSetSyncIsPending = createSelector(selectState, state => state.setSyncIsPending);
export const selectSyncApplyIsPending = createSelector(
selectState,
state => state.syncApplyIsPending
);
export const selectSyncApplyErrorMessage = createSelector(
selectState,
state => state.syncApplyErrorMessage
);