From 517c28a183d6ab69a357227809bc7c3c12d8411e Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 23 Oct 2020 21:15:58 -0400 Subject: [PATCH] only call sync_apply if sync_get fails with 'no wallet found for this user' --- dist/bundle.es.js | 25 ++++++++++++++----------- dist/bundle.js | 23 +++++++++++++---------- src/redux/actions/sync.js | 20 ++++++++++++-------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index aff6e48..688b660 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -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); + }); + } } }); }; diff --git a/dist/bundle.js b/dist/bundle.js index 3a2b37a..52b42bc 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -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); + }); + } } }); }; diff --git a/src/redux/actions/sync.js b/src/redux/actions/sync.js index 22144dd..2e8b056 100644 --- a/src/redux/actions/sync.js +++ b/src/redux/actions/sync.js @@ -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); + }); + } } }); };