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
});
const data = {};
lbryRedux.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;
lbryRedux.Lbry.wallet_status().then(status => {
if (status.is_locked) {
return lbryRedux.Lbry.wallet_unlock({
password
});
}
}).then(() => lbryRedux.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 lbryRedux.Lbry.sync_apply({
password,
data: response.data
}).then(({
hash: walletHash,
data: walletData
}) => {
dispatch({
type: GET_SYNC_COMPLETED,
data
});
if (response.changed) {
return lbryRedux.Lbry.sync_apply({
password,
data: response.data
});
}
}).then(response => {
if (!response) {
dispatch({
type: GET_SYNC_COMPLETED,
data
});
handleCallback();
return;
}
if (walletHash !== syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData));
handleCallback();
}
});
} 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
const {
hash: walletHash,
data: walletData
} = response;
lbryRedux.Lbry.sync_apply({
password
}).then(({
hash: walletHash,
data: syncApplyData
}) => {
dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback();
});
}
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(data.syncHash, walletHash, walletData));
}
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({
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"]
});
var data = {};
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash().then(function (hash) {
lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', {
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].wallet_status().then(function (status) {
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
}, 'post').then(function (response) {
var syncHash = response.hash;
data.syncHash = syncHash;
data.syncData = response.data;
data.hasSyncedWallet = true;
}, 'post');
}).then(function (response) {
var syncHash = response.hash;
data.syncHash = syncHash;
data.syncData = response.data;
data.hasSyncedWallet = true;
if (response.changed) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password,
data: response.data
}).then(function (_ref) {
var walletHash = _ref.hash,
walletData = _ref.data;
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: data
});
if (response.changed) {
return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password,
data: response.data
});
}
}).then(function (response) {
if (!response) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: data
});
handleCallback();
return;
}
if (walletHash !== syncHash) {
// different local hash, need to synchronise
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
var walletHash = response.hash,
walletData = response.data;
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
password: password
}).then(function (_ref2) {
var walletHash = _ref2.hash,
syncApplyData = _ref2.data;
dispatch(doSetSync('', walletHash, syncApplyData, password));
handleCallback();
});
}
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(data.syncHash, walletHash, walletData));
}
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({
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({
password: password,
data: syncData
}).then(function (_ref3) {
var walletHash = _ref3.hash,
walletData = _ref3.data;
}).then(function (_ref2) {
var walletHash = _ref2.hash,
walletData = _ref2.data;
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SYNC_APPLY_COMPLETED"]
});

View file

@ -96,56 +96,67 @@ export function doGetSync(passedPassword, callback) {
});
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) {
// different local hash, need to synchronise
dispatch(doSetSync(syncHash, walletHash, walletData));
handleCallback();
}
}
);
}
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 => {
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 });
handleCallback();
})
.catch(() => {
if (data.hasSyncedWallet) {
const error = 'Error getting synced wallet';
dispatch({
type: ACTIONS.GET_SYNC_FAILED,
data: {
error,
},
});
return;
}
handleCallback(error);
} else {
// user doesn't have a synced wallet
dispatch({
type: ACTIONS.GET_SYNC_COMPLETED,
data: { hasSyncedWallet: false, syncHash: null },
});
const { hash: walletHash, data: walletData } = response;
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise
dispatch(doSetSync(data.syncHash, walletHash, walletData));
}
// 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();
});
}
});
});
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
handleCallback();
})
.catch(() => {
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();
});
}
});
};
}