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

135
dist/bundle.es.js vendored
View file

@ -2427,73 +2427,82 @@ 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) {
hash return lbryRedux.Lbry.wallet_unlock({
}, 'post').then(response => { password
const syncHash = response.hash; });
data.syncHash = syncHash; }
data.syncData = response.data; }).then(() => lbryRedux.Lbry.sync_hash()).then(hash => Lbryio.call('sync', 'get', {
data.hasSyncedWallet = true; hash
}, 'post')).then(response => {
const syncHash = response.hash;
data.syncHash = syncHash;
data.syncData = response.data;
data.hasSyncedWallet = true;
if (response.changed) { if (response.changed) {
return lbryRedux.Lbry.sync_apply({ return lbryRedux.Lbry.sync_apply({
password, password,
data: response.data data: response.data
}).then(({ });
hash: walletHash, }
data: walletData }).then(response => {
}) => { if (!response) {
dispatch({ dispatch({
type: GET_SYNC_COMPLETED, type: GET_SYNC_COMPLETED,
data data
}); });
handleCallback();
return;
}
if (walletHash !== syncHash) { const {
// different local hash, need to synchronise hash: walletHash,
dispatch(doSetSync(syncHash, walletHash, walletData)); data: walletData
handleCallback(); } = response;
}
});
} else {
dispatch({
type: GET_SYNC_COMPLETED,
data
});
handleCallback();
}
}).catch(() => {
if (data.hasSyncedWallet) {
const error = 'Error getting synced wallet';
dispatch({
type: GET_SYNC_FAILED,
data: {
error
}
});
handleCallback(error);
} else {
// user doesn't have a synced wallet
dispatch({
type: GET_SYNC_COMPLETED,
data: {
hasSyncedWallet: false,
syncHash: null
}
}); // call sync_apply to get data to sync
// first time sync. use any string for old hash
lbryRedux.Lbry.sync_apply({ if (walletHash !== data.syncHash) {
password // different local hash, need to synchronise
}).then(({ dispatch(doSetSync(data.syncHash, walletHash, walletData));
hash: walletHash, }
data: syncApplyData
}) => { dispatch({
dispatch(doSetSync('', walletHash, syncApplyData, password)); type: GET_SYNC_COMPLETED,
handleCallback(); data
});
}
}); });
handleCallback();
}).catch(() => {
if (data.hasSyncedWallet) {
const error = 'Error getting synced wallet';
dispatch({
type: GET_SYNC_FAILED,
data: {
error
}
});
handleCallback(error);
} else {
// user doesn't have a synced wallet
dispatch({
type: GET_SYNC_COMPLETED,
data: {
hasSyncedWallet: false,
syncHash: null
}
}); // 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();
});
}
}); });
}; };
} }

138
dist/bundle.js vendored
View file

@ -3992,71 +3992,83 @@ 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');
var syncHash = response.hash; }).then(function (response) {
data.syncHash = syncHash; var syncHash = response.hash;
data.syncData = response.data; data.syncHash = syncHash;
data.hasSyncedWallet = true; data.syncData = response.data;
data.hasSyncedWallet = true;
if (response.changed) { if (response.changed) {
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) {
dispatch({ if (!response) {
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"], dispatch({
data: data type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
}); data: data
});
handleCallback();
return;
}
if (walletHash !== syncHash) { var walletHash = response.hash,
// different local hash, need to synchronise walletData = response.data;
dispatch(doSetSync(syncHash, walletHash, walletData));
handleCallback();
}
});
} else {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: data
});
handleCallback();
}
})["catch"](function () {
if (data.hasSyncedWallet) {
var error = 'Error getting synced wallet';
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_FAILED"],
data: {
error: error
}
});
handleCallback(error);
} else {
// user doesn't have a synced wallet
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: {
hasSyncedWallet: false,
syncHash: null
}
}); // 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({ if (walletHash !== data.syncHash) {
password: password // different local hash, need to synchronise
}).then(function (_ref2) { dispatch(doSetSync(data.syncHash, walletHash, walletData));
var walletHash = _ref2.hash, }
syncApplyData = _ref2.data;
dispatch(doSetSync('', walletHash, syncApplyData, password)); dispatch({
handleCallback(); type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
}); data: data
}
}); });
handleCallback();
})["catch"](function () {
if (data.hasSyncedWallet) {
var error = 'Error getting synced wallet';
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_FAILED"],
data: {
error: error
}
});
handleCallback(error);
} else {
// user doesn't have a synced wallet
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: {
hasSyncedWallet: false,
syncHash: null
}
}); // 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();
});
}
}); });
}; };
} }
@ -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,56 +96,67 @@ export function doGetSync(passedPassword, callback) {
}); });
const data = {}; const data = {};
Lbry.sync_hash().then(hash => {
Lbryio.call('sync', 'get', { hash }, 'post')
.then(response => {
const syncHash = response.hash;
data.syncHash = syncHash;
data.syncData = response.data;
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) { Lbry.wallet_status()
// different local hash, need to synchronise .then(status => {
dispatch(doSetSync(syncHash, walletHash, walletData)); if (status.is_locked) {
handleCallback(); return Lbry.wallet_unlock({ password });
} }
} })
); .then(() => Lbry.sync_hash())
} .then(hash => Lbryio.call('sync', 'get', { hash }, 'post'))
.then(response => {
const syncHash = response.hash;
data.syncHash = syncHash;
data.syncData = response.data;
data.hasSyncedWallet = true;
if (response.changed) {
return Lbry.sync_apply({ password, data: response.data });
}
})
.then(response => {
if (!response) {
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
handleCallback(); handleCallback();
}) return;
.catch(() => { }
if (data.hasSyncedWallet) {
const error = 'Error getting synced wallet';
dispatch({
type: ACTIONS.GET_SYNC_FAILED,
data: {
error,
},
});
handleCallback(error); const { hash: walletHash, data: walletData } = response;
} else { if (walletHash !== data.syncHash) {
// user doesn't have a synced wallet // different local hash, need to synchronise
dispatch({ dispatch(doSetSync(data.syncHash, walletHash, walletData));
type: ACTIONS.GET_SYNC_COMPLETED, }
data: { hasSyncedWallet: false, syncHash: null },
});
// call sync_apply to get data to sync dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
// first time sync. use any string for old hash handleCallback();
Lbry.sync_apply({ password }).then(({ hash: walletHash, data: syncApplyData }) => { })
dispatch(doSetSync('', walletHash, syncApplyData, password)); .catch(() => {
handleCallback(); if (data.hasSyncedWallet) {
}); const error = 'Error getting synced wallet';
} dispatch({
}); type: ACTIONS.GET_SYNC_FAILED,
}); data: {
error,
},
});
handleCallback(error);
} else {
// user doesn't have a synced wallet
dispatch({
type: ACTIONS.GET_SYNC_COMPLETED,
data: { hasSyncedWallet: false, syncHash: null },
});
// 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();
});
}
});
}; };
} }