trigger sync error correctly with locked wallets

This commit is contained in:
Sean Yesmunt 2020-01-23 17:11:07 -05:00
parent 138a053754
commit 6a59102c52
3 changed files with 83 additions and 16 deletions

36
dist/bundle.es.js vendored
View file

@ -2628,8 +2628,18 @@ function doGetSync(passedPassword, callback) {
return lbryRedux.Lbry.wallet_unlock({ return lbryRedux.Lbry.wallet_unlock({
password password
}); });
} // Wallet is already unlocked
return true;
}).then(isUnlocked => {
if (isUnlocked) {
return lbryRedux.Lbry.sync_hash();
} }
}).then(() => lbryRedux.Lbry.sync_hash()).then(hash => Lbryio.call('sync', 'get', {
data.unlockFailed = true;
throw new Error();
}).then(hash => Lbryio.call('sync', 'get', {
hash hash
}, 'post')).then(response => { }, 'post')).then(response => {
const syncHash = response.hash; const syncHash = response.hash;
@ -2669,8 +2679,24 @@ function doGetSync(passedPassword, callback) {
data data
}); });
handleCallback(); handleCallback();
}).catch(() => { }).catch(syncAttemptError => {
if (data.hasSyncedWallet) { if (data.unlockFailed) {
dispatch({
type: GET_SYNC_FAILED,
data: {
error: syncAttemptError
}
});
if (password !== '') {
dispatch({
type: SYNC_APPLY_BAD_PASSWORD
});
}
handleCallback(syncAttemptError);
return;
} else if (data.hasSyncedWallet) {
const error = 'Error getting synced wallet'; const error = 'Error getting synced wallet';
dispatch({ dispatch({
type: GET_SYNC_FAILED, type: GET_SYNC_FAILED,
@ -2707,8 +2733,8 @@ function doGetSync(passedPassword, callback) {
}) => { }) => {
dispatch(doSetSync('', walletHash, syncApplyData, password)); dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback(); handleCallback();
}).catch(error => { }).catch(syncApplyError => {
handleCallback(error); handleCallback(syncApplyError);
}); });
} }
}); });

36
dist/bundle.js vendored
View file

@ -6396,9 +6396,17 @@ function doGetSync(passedPassword, callback) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].wallet_unlock({ return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].wallet_unlock({
password: password password: password
}); });
} } // Wallet is already unlocked
}).then(function () {
return true;
}).then(function (isUnlocked) {
if (isUnlocked) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash(); return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash();
}
data.unlockFailed = true;
throw new Error();
}).then(function (hash) { }).then(function (hash) {
return lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', { return lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', {
hash: hash hash: hash
@ -6439,8 +6447,24 @@ function doGetSync(passedPassword, callback) {
data: data data: data
}); });
handleCallback(); handleCallback();
})["catch"](function () { })["catch"](function (syncAttemptError) {
if (data.hasSyncedWallet) { if (data.unlockFailed) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_FAILED"],
data: {
error: syncAttemptError
}
});
if (password !== '') {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_BAD_PASSWORD"]
});
}
handleCallback(syncAttemptError);
return;
} else if (data.hasSyncedWallet) {
var error = 'Error getting synced wallet'; var error = 'Error getting synced wallet';
dispatch({ dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_FAILED"], type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_FAILED"],
@ -6476,8 +6500,8 @@ function doGetSync(passedPassword, callback) {
syncApplyData = _ref.data; syncApplyData = _ref.data;
dispatch(doSetSync('', walletHash, syncApplyData, password)); dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback(); handleCallback();
})["catch"](function (error) { })["catch"](function (syncApplyError) {
handleCallback(error); handleCallback(syncApplyError);
}); });
} }
}); });

View file

@ -102,8 +102,17 @@ export function doGetSync(passedPassword, callback) {
if (status.is_locked) { if (status.is_locked) {
return Lbry.wallet_unlock({ password }); return Lbry.wallet_unlock({ password });
} }
// Wallet is already unlocked
return true;
})
.then(isUnlocked => {
if (isUnlocked) {
return Lbry.sync_hash();
}
data.unlockFailed = true;
throw new Error();
}) })
.then(() => Lbry.sync_hash())
.then(hash => Lbryio.call('sync', 'get', { hash }, 'post')) .then(hash => Lbryio.call('sync', 'get', { hash }, 'post'))
.then(response => { .then(response => {
const syncHash = response.hash; const syncHash = response.hash;
@ -132,8 +141,16 @@ export function doGetSync(passedPassword, callback) {
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
handleCallback(); handleCallback();
}) })
.catch(() => { .catch(syncAttemptError => {
if (data.hasSyncedWallet) { if (data.unlockFailed) {
dispatch({ type: ACTIONS.GET_SYNC_FAILED, data: { error: syncAttemptError } });
if (password !== '') {
dispatch({ type: ACTIONS.SYNC_APPLY_BAD_PASSWORD });
}
handleCallback(syncAttemptError);
} else if (data.hasSyncedWallet) {
const error = 'Error getting synced wallet'; const error = 'Error getting synced wallet';
dispatch({ dispatch({
type: ACTIONS.GET_SYNC_FAILED, type: ACTIONS.GET_SYNC_FAILED,
@ -164,8 +181,8 @@ export function doGetSync(passedPassword, callback) {
dispatch(doSetSync('', walletHash, syncApplyData, password)); dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback(); handleCallback();
}) })
.catch(error => { .catch(syncApplyError => {
handleCallback(error); handleCallback(syncApplyError);
}); });
} }
}); });