add doCheckSync action to check if user has a synced wallet (#39)
* add doCheckSync action to check if user has a synced wallet * add doSyncApply action. rename some state properties.
This commit is contained in:
parent
7ba14f1d88
commit
dcba831c6b
7 changed files with 361 additions and 41 deletions
124
dist/bundle.es.js
vendored
124
dist/bundle.es.js
vendored
|
@ -79,6 +79,9 @@ const SET_SYNC_STARTED = 'SET_SYNC_STARTED';
|
|||
const SET_SYNC_FAILED = 'SET_SYNC_FAILED';
|
||||
const SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED';
|
||||
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({
|
||||
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_FAILED: SET_SYNC_FAILED,
|
||||
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 = {
|
||||
|
@ -2024,7 +2030,7 @@ function doSetDefaultAccount() {
|
|||
} = accountList;
|
||||
let defaultId;
|
||||
|
||||
for (let i = 0; i < accounts.length; i++) {
|
||||
for (let i = 0; i < accounts.length; ++i) {
|
||||
if (accounts[i].satoshis > 0) {
|
||||
defaultId = accounts[i].id;
|
||||
break;
|
||||
|
@ -2063,6 +2069,7 @@ function doGetSync(password) {
|
|||
if (response.changed) {
|
||||
const syncHash = response.hash;
|
||||
data.syncHash = syncHash;
|
||||
data.syncData = response.data;
|
||||
lbryRedux.Lbry.sync_apply({
|
||||
password,
|
||||
data: response.data
|
||||
|
@ -2105,6 +2112,70 @@ 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(() => {
|
||||
dispatch({
|
||||
type: SYNC_APPLY_FAILED,
|
||||
data: {
|
||||
error: 'Invalid password specified. Please enter the password for your previously synchronised wallet.'
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
function doCheckSync() {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: GET_SYNC_STARTED
|
||||
});
|
||||
lbryRedux.Lbry.sync_hash().then(hash => {
|
||||
Lbryio.call('sync', 'get', {
|
||||
hash
|
||||
}, 'post').then(response => {
|
||||
const data = {
|
||||
hasSyncedWallet: true,
|
||||
syncHash: response.hash,
|
||||
syncData: response.data
|
||||
};
|
||||
dispatch({
|
||||
type: GET_SYNC_COMPLETED,
|
||||
data
|
||||
});
|
||||
}).catch(() => {
|
||||
// user doesn't have a synced wallet
|
||||
dispatch({
|
||||
type: GET_SYNC_COMPLETED,
|
||||
data: {
|
||||
hasSyncedWallet: false,
|
||||
syncHash: null
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const reducers = {};
|
||||
const defaultState$1 = {
|
||||
|
@ -2581,39 +2652,58 @@ const reducers$3 = {};
|
|||
const defaultState$8 = {
|
||||
hasSyncedWallet: false,
|
||||
syncHash: null,
|
||||
syncData: null,
|
||||
setSyncErrorMessage: null,
|
||||
retrievingSync: false,
|
||||
settingSync: false
|
||||
syncApplyErrorMessage: '',
|
||||
syncApplyIsPending: false,
|
||||
getSyncIsPending: false,
|
||||
setSyncIsPending: false
|
||||
};
|
||||
|
||||
reducers$3[GET_SYNC_STARTED] = state => Object.assign({}, state, {
|
||||
retrievingSync: true
|
||||
getSyncIsPending: true
|
||||
});
|
||||
|
||||
reducers$3[GET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
|
||||
syncHash: action.data.syncHash,
|
||||
syncData: action.data.syncData,
|
||||
hasSyncedWallet: action.data.hasSyncedWallet,
|
||||
retrievingSync: false
|
||||
getSyncIsPending: false
|
||||
});
|
||||
|
||||
reducers$3[SET_SYNC_STARTED] = state => Object.assign({}, state, {
|
||||
settingSync: true,
|
||||
setSyncIsPending: true,
|
||||
setSyncErrorMessage: null
|
||||
});
|
||||
|
||||
reducers$3[SET_SYNC_FAILED] = (state, action) => Object.assign({}, state, {
|
||||
settingSync: true,
|
||||
setSyncIsPending: false,
|
||||
setSyncErrorMessage: action.data.error
|
||||
});
|
||||
|
||||
reducers$3[SET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
|
||||
settingSync: false,
|
||||
setSyncIsPending: false,
|
||||
setSyncErrorMessage: null,
|
||||
hasSyncedWallet: true,
|
||||
// sync was successful, so the user has a synced wallet at this point
|
||||
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) {
|
||||
const handler = reducers$3[action.type];
|
||||
if (handler) return handler(state, action);
|
||||
|
@ -2650,9 +2740,12 @@ const selectState$8 = state => state.sync || {};
|
|||
|
||||
const selectHasSyncedWallet = reselect.createSelector(selectState$8, state => state.hasSyncedWallet);
|
||||
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 selectIsRetrievingSync = reselect.createSelector(selectState$8, state => state.retrievingSync);
|
||||
const selectIsSettingSync = reselect.createSelector(selectState$8, state => state.settingSync);
|
||||
const selectGetSyncIsPending = reselect.createSelector(selectState$8, state => state.getSyncIsPending);
|
||||
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.Lbryio = Lbryio;
|
||||
|
@ -2668,6 +2761,7 @@ exports.doChannelUnsubscribe = doChannelUnsubscribe;
|
|||
exports.doCheckSubscription = doCheckSubscription;
|
||||
exports.doCheckSubscriptions = doCheckSubscriptions;
|
||||
exports.doCheckSubscriptionsInit = doCheckSubscriptionsInit;
|
||||
exports.doCheckSync = doCheckSync;
|
||||
exports.doClaimEligiblePurchaseRewards = doClaimEligiblePurchaseRewards;
|
||||
exports.doClaimRewardClearError = doClaimRewardClearError;
|
||||
exports.doClaimRewardType = doClaimRewardType;
|
||||
|
@ -2691,6 +2785,7 @@ exports.doSetDefaultAccount = doSetDefaultAccount;
|
|||
exports.doSetSync = doSetSync;
|
||||
exports.doSetViewMode = doSetViewMode;
|
||||
exports.doShowSuggestedSubs = doShowSuggestedSubs;
|
||||
exports.doSyncApply = doSyncApply;
|
||||
exports.doUpdateUnreadSubscriptions = doUpdateUnreadSubscriptions;
|
||||
exports.doUserCheckEmailVerified = doUserCheckEmailVerified;
|
||||
exports.doUserEmailNew = doUserEmailNew;
|
||||
|
@ -2740,14 +2835,13 @@ exports.selectFetchingFeaturedUris = selectFetchingFeaturedUris;
|
|||
exports.selectFetchingRewards = selectFetchingRewards;
|
||||
exports.selectFetchingTrendingUris = selectFetchingTrendingUris;
|
||||
exports.selectFirstRunCompleted = selectFirstRunCompleted;
|
||||
exports.selectGetSyncIsPending = selectGetSyncIsPending;
|
||||
exports.selectHasSyncedWallet = selectHasSyncedWallet;
|
||||
exports.selectIdentityVerifyErrorMessage = selectIdentityVerifyErrorMessage;
|
||||
exports.selectIdentityVerifyIsPending = selectIdentityVerifyIsPending;
|
||||
exports.selectIsAuthenticating = selectIsAuthenticating;
|
||||
exports.selectIsFetchingSubscriptions = selectIsFetchingSubscriptions;
|
||||
exports.selectIsFetchingSuggested = selectIsFetchingSuggested;
|
||||
exports.selectIsRetrievingSync = selectIsRetrievingSync;
|
||||
exports.selectIsSettingSync = selectIsSettingSync;
|
||||
exports.selectPhoneNewErrorMessage = selectPhoneNewErrorMessage;
|
||||
exports.selectPhoneNewIsPending = selectPhoneNewIsPending;
|
||||
exports.selectPhoneToVerify = selectPhoneToVerify;
|
||||
|
@ -2756,12 +2850,16 @@ exports.selectPhoneVerifyIsPending = selectPhoneVerifyIsPending;
|
|||
exports.selectReferralReward = selectReferralReward;
|
||||
exports.selectRewardContentClaimIds = selectRewardContentClaimIds;
|
||||
exports.selectSetSyncErrorMessage = selectSetSyncErrorMessage;
|
||||
exports.selectSetSyncIsPending = selectSetSyncIsPending;
|
||||
exports.selectShowSuggestedSubs = selectShowSuggestedSubs;
|
||||
exports.selectSubscriptionClaims = selectSubscriptionClaims;
|
||||
exports.selectSubscriptions = selectSubscriptions;
|
||||
exports.selectSubscriptionsBeingFetched = selectSubscriptionsBeingFetched;
|
||||
exports.selectSuggested = selectSuggested;
|
||||
exports.selectSuggestedChannels = selectSuggestedChannels;
|
||||
exports.selectSyncApplyErrorMessage = selectSyncApplyErrorMessage;
|
||||
exports.selectSyncApplyIsPending = selectSyncApplyIsPending;
|
||||
exports.selectSyncData = selectSyncData;
|
||||
exports.selectSyncHash = selectSyncHash;
|
||||
exports.selectTrendingUris = selectTrendingUris;
|
||||
exports.selectUnclaimedRewardValue = selectUnclaimedRewardValue;
|
||||
|
|
151
dist/bundle.js
vendored
151
dist/bundle.js
vendored
|
@ -208,12 +208,16 @@ __webpack_require__.r(__webpack_exports__);
|
|||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return redux_actions_stats__WEBPACK_IMPORTED_MODULE_11__["doFetchViewCount"]; });
|
||||
|
||||
/* harmony import */ var redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(25);
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doCheckSync"]; });
|
||||
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doGetSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doGetSync"]; });
|
||||
|
||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doSetSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doSetSync"]; });
|
||||
|
||||
/* 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 reexport (safe) */ __webpack_require__.d(__webpack_exports__, "authReducer", function() { return redux_reducers_auth__WEBPACK_IMPORTED_MODULE_13__["authReducer"]; });
|
||||
|
||||
|
@ -393,13 +397,19 @@ __webpack_require__.r(__webpack_exports__);
|
|||
/* 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__, "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__, "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"]; });
|
||||
|
||||
|
||||
|
||||
|
@ -510,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_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__, "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
|
||||
var GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE';
|
||||
var GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED';
|
||||
|
@ -581,6 +594,9 @@ var SET_SYNC_STARTED = 'SET_SYNC_STARTED';
|
|||
var SET_SYNC_FAILED = 'SET_SYNC_FAILED';
|
||||
var SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED';
|
||||
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 */
|
||||
|
@ -3401,6 +3417,8 @@ __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__, "doSetDefaultAccount", function() { return doSetDefaultAccount; });
|
||||
/* 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 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 lbry_redux__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
|
||||
|
@ -3452,7 +3470,7 @@ function doSetDefaultAccount() {
|
|||
var accounts = accountList.lbc_mainnet;
|
||||
var defaultId;
|
||||
|
||||
for (var i = 0; i < accounts.length; i++) {
|
||||
for (var i = 0; i < accounts.length; ++i) {
|
||||
if (accounts[i].satoshis > 0) {
|
||||
defaultId = accounts[i].id;
|
||||
break;
|
||||
|
@ -3491,6 +3509,7 @@ function doGetSync(password) {
|
|||
if (response.changed) {
|
||||
var syncHash = response.hash;
|
||||
data.syncHash = syncHash;
|
||||
data.syncData = response.data;
|
||||
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
|
||||
password: password,
|
||||
data: response.data
|
||||
|
@ -3534,6 +3553,69 @@ 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 () {
|
||||
dispatch({
|
||||
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_FAILED"],
|
||||
data: {
|
||||
error: 'Invalid password specified. Please enter the password for your previously synchronised wallet.'
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
function doCheckSync() {
|
||||
return function (dispatch) {
|
||||
dispatch({
|
||||
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_STARTED"]
|
||||
});
|
||||
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash().then(function (hash) {
|
||||
lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', {
|
||||
hash: hash
|
||||
}, 'post').then(function (response) {
|
||||
var data = {
|
||||
hasSyncedWallet: true,
|
||||
syncHash: response.hash,
|
||||
syncData: response.data
|
||||
};
|
||||
dispatch({
|
||||
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
|
||||
data: data
|
||||
});
|
||||
})["catch"](function () {
|
||||
// user doesn't have a synced wallet
|
||||
dispatch({
|
||||
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
|
||||
data: {
|
||||
hasSyncedWallet: false,
|
||||
syncHash: null
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
/* 26 */
|
||||
|
@ -4169,42 +4251,46 @@ var reducers = {};
|
|||
var defaultState = {
|
||||
hasSyncedWallet: false,
|
||||
syncHash: null,
|
||||
syncData: null,
|
||||
setSyncErrorMessage: null,
|
||||
retrievingSync: false,
|
||||
settingSync: false
|
||||
syncApplyErrorMessage: '',
|
||||
syncApplyIsPending: false,
|
||||
getSyncIsPending: false,
|
||||
setSyncIsPending: false
|
||||
};
|
||||
|
||||
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_STARTED"]] = function (state) {
|
||||
return Object.assign({}, state, {
|
||||
retrievingSync: true
|
||||
getSyncIsPending: true
|
||||
});
|
||||
};
|
||||
|
||||
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"]] = function (state, action) {
|
||||
return Object.assign({}, state, {
|
||||
syncHash: action.data.syncHash,
|
||||
syncData: action.data.syncData,
|
||||
hasSyncedWallet: action.data.hasSyncedWallet,
|
||||
retrievingSync: false
|
||||
getSyncIsPending: false
|
||||
});
|
||||
};
|
||||
|
||||
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_STARTED"]] = function (state) {
|
||||
return Object.assign({}, state, {
|
||||
settingSync: true,
|
||||
setSyncIsPending: true,
|
||||
setSyncErrorMessage: null
|
||||
});
|
||||
};
|
||||
|
||||
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_FAILED"]] = function (state, action) {
|
||||
return Object.assign({}, state, {
|
||||
settingSync: true,
|
||||
setSyncIsPending: false,
|
||||
setSyncErrorMessage: action.data.error
|
||||
});
|
||||
};
|
||||
|
||||
reducers[constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_COMPLETED"]] = function (state, action) {
|
||||
return Object.assign({}, state, {
|
||||
settingSync: false,
|
||||
setSyncIsPending: false,
|
||||
setSyncErrorMessage: null,
|
||||
hasSyncedWallet: true,
|
||||
// sync was successful, so the user has a synced wallet at this point
|
||||
|
@ -4212,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() {
|
||||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
|
||||
var action = arguments.length > 1 ? arguments[1] : undefined;
|
||||
|
@ -4362,9 +4469,12 @@ var makeSelectViewCountForUri = function makeSelectViewCountForUri(uri) {
|
|||
__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__, "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__, "selectIsRetrievingSync", function() { return selectIsRetrievingSync; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectIsSettingSync", function() { return selectIsSettingSync; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectGetSyncIsPending", function() { return selectGetSyncIsPending; });
|
||||
/* 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___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__);
|
||||
|
||||
|
@ -4379,14 +4489,23 @@ var selectHasSyncedWallet = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["create
|
|||
var selectSyncHash = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
|
||||
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) {
|
||||
return state.setSyncErrorMessage;
|
||||
});
|
||||
var selectIsRetrievingSync = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
|
||||
return state.retrievingSync;
|
||||
var selectGetSyncIsPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
|
||||
return state.getSyncIsPending;
|
||||
});
|
||||
var selectIsSettingSync = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
|
||||
return state.settingSync;
|
||||
var selectSetSyncIsPending = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
|
||||
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;
|
||||
});
|
||||
|
||||
/***/ })
|
||||
|
|
|
@ -77,3 +77,6 @@ export const SET_SYNC_STARTED = 'SET_SYNC_STARTED';
|
|||
export const SET_SYNC_FAILED = 'SET_SYNC_FAILED';
|
||||
export const SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED';
|
||||
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';
|
||||
|
|
15
src/index.js
15
src/index.js
|
@ -59,7 +59,13 @@ export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
|
|||
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
|
||||
export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage';
|
||||
export { doFetchViewCount } from 'redux/actions/stats';
|
||||
export { doGetSync, doSetSync, doSetDefaultAccount } from 'redux/actions/sync';
|
||||
export {
|
||||
doCheckSync,
|
||||
doGetSync,
|
||||
doSetSync,
|
||||
doSetDefaultAccount,
|
||||
doSyncApply,
|
||||
} from 'redux/actions/sync';
|
||||
|
||||
// reducers
|
||||
export { authReducer } from 'redux/reducers/auth';
|
||||
|
@ -156,8 +162,11 @@ export {
|
|||
export { makeSelectViewCountForUri } from 'redux/selectors/stats';
|
||||
export {
|
||||
selectHasSyncedWallet,
|
||||
selectSyncData,
|
||||
selectSyncHash,
|
||||
selectSetSyncErrorMessage,
|
||||
selectIsRetrievingSync,
|
||||
selectIsSettingSync,
|
||||
selectGetSyncIsPending,
|
||||
selectSetSyncIsPending,
|
||||
selectSyncApplyIsPending,
|
||||
selectSyncApplyErrorMessage,
|
||||
} from 'redux/selectors/sync';
|
||||
|
|
|
@ -74,6 +74,8 @@ export function doGetSync(password) {
|
|||
if (response.changed) {
|
||||
const syncHash = response.hash;
|
||||
data.syncHash = syncHash;
|
||||
data.syncData = response.data;
|
||||
|
||||
Lbry.sync_apply({ password, data: response.data }).then(
|
||||
({ hash: walletHash, data: walletData }) => {
|
||||
if (walletHash !== syncHash) {
|
||||
|
@ -105,3 +107,58 @@ 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() {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: ACTIONS.GET_SYNC_STARTED,
|
||||
});
|
||||
|
||||
Lbry.sync_hash().then(hash => {
|
||||
Lbryio.call('sync', 'get', { hash }, 'post')
|
||||
.then(response => {
|
||||
const data = { hasSyncedWallet: true, syncHash: response.hash, syncData: response.data };
|
||||
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
|
||||
})
|
||||
.catch(() => {
|
||||
// user doesn't have a synced wallet
|
||||
dispatch({
|
||||
type: ACTIONS.GET_SYNC_COMPLETED,
|
||||
data: { hasSyncedWallet: false, syncHash: null },
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,43 +4,65 @@ const reducers = {};
|
|||
const defaultState = {
|
||||
hasSyncedWallet: false,
|
||||
syncHash: null,
|
||||
syncData: null,
|
||||
setSyncErrorMessage: null,
|
||||
retrievingSync: false,
|
||||
settingSync: false,
|
||||
syncApplyErrorMessage: '',
|
||||
syncApplyIsPending: false,
|
||||
getSyncIsPending: false,
|
||||
setSyncIsPending: false,
|
||||
};
|
||||
|
||||
reducers[ACTIONS.GET_SYNC_STARTED] = state =>
|
||||
Object.assign({}, state, {
|
||||
retrievingSync: true,
|
||||
getSyncIsPending: true,
|
||||
});
|
||||
|
||||
reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) =>
|
||||
Object.assign({}, state, {
|
||||
syncHash: action.data.syncHash,
|
||||
syncData: action.data.syncData,
|
||||
hasSyncedWallet: action.data.hasSyncedWallet,
|
||||
retrievingSync: false,
|
||||
getSyncIsPending: false,
|
||||
});
|
||||
|
||||
reducers[ACTIONS.SET_SYNC_STARTED] = state =>
|
||||
Object.assign({}, state, {
|
||||
settingSync: true,
|
||||
setSyncIsPending: true,
|
||||
setSyncErrorMessage: null,
|
||||
});
|
||||
|
||||
reducers[ACTIONS.SET_SYNC_FAILED] = (state, action) =>
|
||||
Object.assign({}, state, {
|
||||
settingSync: true,
|
||||
setSyncIsPending: false,
|
||||
setSyncErrorMessage: action.data.error,
|
||||
});
|
||||
|
||||
reducers[ACTIONS.SET_SYNC_COMPLETED] = (state, action) =>
|
||||
Object.assign({}, state, {
|
||||
settingSync: false,
|
||||
setSyncIsPending: false,
|
||||
setSyncErrorMessage: null,
|
||||
hasSyncedWallet: true, // sync was successful, so the user has a synced wallet at this point
|
||||
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) {
|
||||
const handler = reducers[action.type];
|
||||
if (handler) return handler(state, action);
|
||||
|
|
|
@ -6,11 +6,23 @@ export const selectHasSyncedWallet = createSelector(selectState, state => state.
|
|||
|
||||
export const selectSyncHash = createSelector(selectState, state => state.syncHash);
|
||||
|
||||
export const selectSyncData = createSelector(selectState, state => state.syncData);
|
||||
|
||||
export const selectSetSyncErrorMessage = createSelector(
|
||||
selectState,
|
||||
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
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue