only call sync_apply if sync_get fails with 'no wallet found for this user'

This commit is contained in:
Sean Yesmunt 2020-10-23 21:15:58 -04:00
parent d91b971bfe
commit 517c28a183
3 changed files with 39 additions and 29 deletions

25
dist/bundle.es.js vendored
View file

@ -794,6 +794,7 @@ const doFetchSubCount = claimId => dispatch => {
}); });
}; };
const NO_WALLET_ERROR = 'no wallet found for this user';
function doSetDefaultAccount(success, failure) { function doSetDefaultAccount(success, failure) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
@ -993,17 +994,19 @@ function doGetSync(passedPassword, callback) {
}); // 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
lbryRedux.Lbry.sync_apply({ if (syncAttemptError.message === NO_WALLET_ERROR) {
password lbryRedux.Lbry.sync_apply({
}).then(({ password
hash: walletHash, }).then(({
data: syncApplyData hash: walletHash,
}) => { data: syncApplyData
dispatch(doSetSync('', walletHash, syncApplyData, password)); }) => {
handleCallback(); dispatch(doSetSync('', walletHash, syncApplyData, password));
}).catch(syncApplyError => { handleCallback();
handleCallback(syncApplyError); }).catch(syncApplyError => {
}); handleCallback(syncApplyError);
});
}
} }
}); });
}; };

23
dist/bundle.js vendored
View file

@ -3535,6 +3535,7 @@ __webpack_require__.r(__webpack_exports__);
var NO_WALLET_ERROR = 'no wallet found for this user';
function doSetDefaultAccount(success, failure) { function doSetDefaultAccount(success, failure) {
return function (dispatch) { return function (dispatch) {
dispatch({ dispatch({
@ -3732,16 +3733,18 @@ function doGetSync(passedPassword, callback) {
}); // 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_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({ if (syncAttemptError.message === NO_WALLET_ERROR) {
password: password lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
}).then(function (_ref) { password: password
var walletHash = _ref.hash, }).then(function (_ref) {
syncApplyData = _ref.data; var walletHash = _ref.hash,
dispatch(doSetSync('', walletHash, syncApplyData, password)); syncApplyData = _ref.data;
handleCallback(); dispatch(doSetSync('', walletHash, syncApplyData, password));
})["catch"](function (syncApplyError) { handleCallback();
handleCallback(syncApplyError); })["catch"](function (syncApplyError) {
}); handleCallback(syncApplyError);
});
}
} }
}); });
}; };

View file

@ -2,6 +2,8 @@ import * as ACTIONS from 'constants/action_types';
import Lbryio from 'lbryio'; import Lbryio from 'lbryio';
import { Lbry, doWalletEncrypt, doWalletDecrypt } from 'lbry-redux'; import { Lbry, doWalletEncrypt, doWalletDecrypt } from 'lbry-redux';
const NO_WALLET_ERROR = 'no wallet found for this user';
export function doSetDefaultAccount(success, failure) { export function doSetDefaultAccount(success, failure) {
return dispatch => { return dispatch => {
dispatch({ dispatch({
@ -178,14 +180,16 @@ export function doGetSync(passedPassword, callback) {
// 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 }) if (syncAttemptError.message === NO_WALLET_ERROR) {
.then(({ hash: walletHash, data: syncApplyData }) => { Lbry.sync_apply({ password })
dispatch(doSetSync('', walletHash, syncApplyData, password)); .then(({ hash: walletHash, data: syncApplyData }) => {
handleCallback(); dispatch(doSetSync('', walletHash, syncApplyData, password));
}) handleCallback();
.catch(syncApplyError => { })
handleCallback(syncApplyError); .catch(syncApplyError => {
}); handleCallback(syncApplyError);
});
}
} }
}); });
}; };