unlock wallet if needed before syncing

This commit is contained in:
Sean Yesmunt 2019-10-15 23:35:03 -04:00
parent aebad10a9c
commit fb2e73ab31
3 changed files with 203 additions and 171 deletions

41
dist/bundle.es.js vendored
View file

@ -2427,10 +2427,15 @@ function doGetSync(passedPassword, callback) {
type: GET_SYNC_STARTED type: GET_SYNC_STARTED
}); });
const data = {}; const data = {};
lbryRedux.Lbry.sync_hash().then(hash => { lbryRedux.Lbry.wallet_status().then(status => {
Lbryio.call('sync', 'get', { if (status.is_locked) {
return lbryRedux.Lbry.wallet_unlock({
password
});
}
}).then(() => lbryRedux.Lbry.sync_hash()).then(hash => Lbryio.call('sync', 'get', {
hash hash
}, 'post').then(response => { }, 'post')).then(response => {
const syncHash = response.hash; const syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data; data.syncData = response.data;
@ -2440,28 +2445,33 @@ function doGetSync(passedPassword, callback) {
return lbryRedux.Lbry.sync_apply({ return lbryRedux.Lbry.sync_apply({
password, password,
data: response.data data: response.data
}).then(({ });
}
}).then(response => {
if (!response) {
dispatch({
type: GET_SYNC_COMPLETED,
data
});
handleCallback();
return;
}
const {
hash: walletHash, hash: walletHash,
data: walletData data: walletData
}) => { } = response;
dispatch({
type: GET_SYNC_COMPLETED,
data
});
if (walletHash !== syncHash) { if (walletHash !== data.syncHash) {
// different local hash, need to synchronise // different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData)); dispatch(doSetSync(data.syncHash, walletHash, walletData));
handleCallback();
} }
});
} else {
dispatch({ dispatch({
type: GET_SYNC_COMPLETED, type: GET_SYNC_COMPLETED,
data data
}); });
handleCallback(); handleCallback();
}
}).catch(() => { }).catch(() => {
if (data.hasSyncedWallet) { if (data.hasSyncedWallet) {
const error = 'Error getting synced wallet'; const error = 'Error getting synced wallet';
@ -2494,7 +2504,6 @@ function doGetSync(passedPassword, callback) {
}); });
} }
}); });
});
}; };
} }
function doSyncApply(syncHash, syncData, password) { function doSyncApply(syncHash, syncData, password) {

50
dist/bundle.js vendored
View file

@ -3992,10 +3992,19 @@ function doGetSync(passedPassword, callback) {
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_STARTED"] type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_STARTED"]
}); });
var data = {}; var data = {};
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash().then(function (hash) { lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].wallet_status().then(function (status) {
lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', { if (status.is_locked) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].wallet_unlock({
password: password
});
}
}).then(function () {
return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash();
}).then(function (hash) {
return lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', {
hash: hash hash: hash
}, 'post').then(function (response) { }, 'post');
}).then(function (response) {
var syncHash = response.hash; var syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data; data.syncData = response.data;
@ -4005,27 +4014,31 @@ function doGetSync(passedPassword, callback) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({ return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password, password: password,
data: response.data data: response.data
}).then(function (_ref) { });
var walletHash = _ref.hash, }
walletData = _ref.data; }).then(function (response) {
if (!response) {
dispatch({ dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"], type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: data data: data
}); });
handleCallback();
return;
}
if (walletHash !== syncHash) { var walletHash = response.hash,
walletData = response.data;
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise // different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData)); dispatch(doSetSync(data.syncHash, walletHash, walletData));
handleCallback();
} }
});
} else {
dispatch({ dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"], type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: data data: data
}); });
handleCallback(); handleCallback();
}
})["catch"](function () { })["catch"](function () {
if (data.hasSyncedWallet) { if (data.hasSyncedWallet) {
var error = 'Error getting synced wallet'; var error = 'Error getting synced wallet';
@ -4049,15 +4062,14 @@ function doGetSync(passedPassword, callback) {
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({ lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password password: password
}).then(function (_ref2) { }).then(function (_ref) {
var walletHash = _ref2.hash, var walletHash = _ref.hash,
syncApplyData = _ref2.data; syncApplyData = _ref.data;
dispatch(doSetSync('', walletHash, syncApplyData, password)); dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback(); handleCallback();
}); });
} }
}); });
});
}; };
} }
function doSyncApply(syncHash, syncData, password) { function doSyncApply(syncHash, syncData, password) {
@ -4068,9 +4080,9 @@ function doSyncApply(syncHash, syncData, password) {
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({ lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password, password: password,
data: syncData data: syncData
}).then(function (_ref3) { }).then(function (_ref2) {
var walletHash = _ref3.hash, var walletHash = _ref2.hash,
walletData = _ref3.data; walletData = _ref2.data;
dispatch({ dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_COMPLETED"] type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_COMPLETED"]
}); });

View file

@ -96,26 +96,38 @@ export function doGetSync(passedPassword, callback) {
}); });
const data = {}; const data = {};
Lbry.sync_hash().then(hash => {
Lbryio.call('sync', 'get', { hash }, 'post') Lbry.wallet_status()
.then(status => {
if (status.is_locked) {
return Lbry.wallet_unlock({ password });
}
})
.then(() => Lbry.sync_hash())
.then(hash => Lbryio.call('sync', 'get', { hash }, 'post'))
.then(response => { .then(response => {
const syncHash = response.hash; const syncHash = response.hash;
data.syncHash = syncHash; data.syncHash = syncHash;
data.syncData = response.data; data.syncData = response.data;
data.hasSyncedWallet = true; data.hasSyncedWallet = true;
if (response.changed) {
return Lbry.sync_apply({ password, data: response.data }).then(
({ hash: walletHash, data: walletData }) => {
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
if (walletHash !== syncHash) { if (response.changed) {
// different local hash, need to synchronise return Lbry.sync_apply({ password, data: response.data });
dispatch(doSetSync(syncHash, walletHash, walletData)); }
})
.then(response => {
if (!response) {
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
handleCallback(); handleCallback();
return;
} }
const { hash: walletHash, data: walletData } = response;
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(data.syncHash, walletHash, walletData));
} }
);
}
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
handleCallback(); handleCallback();
}) })
@ -145,7 +157,6 @@ export function doGetSync(passedPassword, callback) {
}); });
} }
}); });
});
}; };
} }