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) {
return dispatch => {
dispatch({
@ -993,17 +994,19 @@ function doGetSync(passedPassword, callback) {
}); // call sync_apply to get data to sync
// first time sync. use any string for old hash
lbryRedux.Lbry.sync_apply({
password
}).then(({
hash: walletHash,
data: syncApplyData
}) => {
dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback();
}).catch(syncApplyError => {
handleCallback(syncApplyError);
});
if (syncAttemptError.message === NO_WALLET_ERROR) {
lbryRedux.Lbry.sync_apply({
password
}).then(({
hash: walletHash,
data: syncApplyData
}) => {
dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback();
}).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) {
return function (dispatch) {
dispatch({
@ -3732,16 +3733,18 @@ function doGetSync(passedPassword, callback) {
}); // call sync_apply to get data to sync
// first time sync. use any string for old hash
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password
}).then(function (_ref) {
var walletHash = _ref.hash,
syncApplyData = _ref.data;
dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback();
})["catch"](function (syncApplyError) {
handleCallback(syncApplyError);
});
if (syncAttemptError.message === NO_WALLET_ERROR) {
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password
}).then(function (_ref) {
var walletHash = _ref.hash,
syncApplyData = _ref.data;
dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback();
})["catch"](function (syncApplyError) {
handleCallback(syncApplyError);
});
}
}
});
};

View file

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