unlock wallet if needed before syncing
This commit is contained in:
parent
aebad10a9c
commit
fb2e73ab31
3 changed files with 203 additions and 171 deletions
41
dist/bundle.es.js
vendored
41
dist/bundle.es.js
vendored
|
@ -2427,10 +2427,15 @@ function doGetSync(passedPassword, callback) {
|
|||
type: GET_SYNC_STARTED
|
||||
});
|
||||
const data = {};
|
||||
lbryRedux.Lbry.sync_hash().then(hash => {
|
||||
Lbryio.call('sync', 'get', {
|
||||
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 => {
|
||||
}, 'post')).then(response => {
|
||||
const syncHash = response.hash;
|
||||
data.syncHash = syncHash;
|
||||
data.syncData = response.data;
|
||||
|
@ -2440,28 +2445,33 @@ function doGetSync(passedPassword, callback) {
|
|||
return lbryRedux.Lbry.sync_apply({
|
||||
password,
|
||||
data: response.data
|
||||
}).then(({
|
||||
});
|
||||
}
|
||||
}).then(response => {
|
||||
if (!response) {
|
||||
dispatch({
|
||||
type: GET_SYNC_COMPLETED,
|
||||
data
|
||||
});
|
||||
handleCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
hash: walletHash,
|
||||
data: walletData
|
||||
}) => {
|
||||
dispatch({
|
||||
type: GET_SYNC_COMPLETED,
|
||||
data
|
||||
});
|
||||
} = response;
|
||||
|
||||
if (walletHash !== syncHash) {
|
||||
if (walletHash !== data.syncHash) {
|
||||
// different local hash, need to synchronise
|
||||
dispatch(doSetSync(syncHash, walletHash, walletData));
|
||||
handleCallback();
|
||||
dispatch(doSetSync(data.syncHash, walletHash, walletData));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
dispatch({
|
||||
type: GET_SYNC_COMPLETED,
|
||||
data
|
||||
});
|
||||
handleCallback();
|
||||
}
|
||||
}).catch(() => {
|
||||
if (data.hasSyncedWallet) {
|
||||
const error = 'Error getting synced wallet';
|
||||
|
@ -2494,7 +2504,6 @@ function doGetSync(passedPassword, callback) {
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
function doSyncApply(syncHash, syncData, password) {
|
||||
|
|
50
dist/bundle.js
vendored
50
dist/bundle.js
vendored
|
@ -3992,10 +3992,19 @@ 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) {
|
||||
}, 'post');
|
||||
}).then(function (response) {
|
||||
var syncHash = response.hash;
|
||||
data.syncHash = syncHash;
|
||||
data.syncData = response.data;
|
||||
|
@ -4005,27 +4014,31 @@ function doGetSync(passedPassword, callback) {
|
|||
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;
|
||||
});
|
||||
}
|
||||
}).then(function (response) {
|
||||
if (!response) {
|
||||
dispatch({
|
||||
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
|
||||
data: data
|
||||
});
|
||||
handleCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (walletHash !== syncHash) {
|
||||
var walletHash = response.hash,
|
||||
walletData = response.data;
|
||||
|
||||
if (walletHash !== data.syncHash) {
|
||||
// different local hash, need to synchronise
|
||||
dispatch(doSetSync(syncHash, walletHash, walletData));
|
||||
handleCallback();
|
||||
dispatch(doSetSync(data.syncHash, walletHash, walletData));
|
||||
}
|
||||
});
|
||||
} 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';
|
||||
|
@ -4049,15 +4062,14 @@ function doGetSync(passedPassword, callback) {
|
|||
|
||||
lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({
|
||||
password: password
|
||||
}).then(function (_ref2) {
|
||||
var walletHash = _ref2.hash,
|
||||
syncApplyData = _ref2.data;
|
||||
}).then(function (_ref) {
|
||||
var walletHash = _ref.hash,
|
||||
syncApplyData = _ref.data;
|
||||
dispatch(doSetSync('', walletHash, syncApplyData, password));
|
||||
handleCallback();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
function doSyncApply(syncHash, syncData, password) {
|
||||
|
@ -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"]
|
||||
});
|
||||
|
|
|
@ -96,26 +96,38 @@ export function doGetSync(passedPassword, callback) {
|
|||
});
|
||||
|
||||
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 => {
|
||||
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));
|
||||
if (response.changed) {
|
||||
return Lbry.sync_apply({ password, data: response.data });
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (!response) {
|
||||
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
|
||||
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 });
|
||||
handleCallback();
|
||||
})
|
||||
|
@ -145,7 +157,6 @@ export function doGetSync(passedPassword, callback) {
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue