update sync actions
This commit is contained in:
parent
07a4f13d96
commit
67788d8ca3
2 changed files with 27 additions and 49 deletions
42
dist/bundle.js
vendored
42
dist/bundle.js
vendored
|
@ -9638,10 +9638,14 @@ function doSetSync(oldHash, newHash, data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var syncHash = response.data.hash;
|
return dispatch({
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.SET_SYNC_COMPLETED,
|
type: ACTIONS.SET_SYNC_COMPLETED,
|
||||||
data: { syncHash: syncHash }
|
data: { syncHash: response.hash }
|
||||||
|
});
|
||||||
|
}).catch(function (error) {
|
||||||
|
return dispatch({
|
||||||
|
type: ACTIONS.SET_SYNC_FAILED,
|
||||||
|
data: { error: error }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -9655,33 +9659,17 @@ function doGetSync(password) {
|
||||||
|
|
||||||
_lbryRedux.Lbry.sync_hash().then(function (hash) {
|
_lbryRedux.Lbry.sync_hash().then(function (hash) {
|
||||||
_lbryio2.default.call('sync', 'get', { hash: hash }, 'post').then(function (response) {
|
_lbryio2.default.call('sync', 'get', { hash: hash }, 'post').then(function (response) {
|
||||||
if (!response.success) {
|
|
||||||
// user doesn't have a synced wallet
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.GET_SYNC_COMPLETED,
|
|
||||||
data: { hasWallet: false, syncHash: null }
|
|
||||||
});
|
|
||||||
|
|
||||||
// call sync_apply to get data to sync (first time sync)
|
|
||||||
_lbryRedux.Lbry.sync_apply({ password: password }).then(function (_ref) {
|
|
||||||
var walletHash = _ref.hash,
|
|
||||||
data = _ref.data;
|
|
||||||
return dispatch(doSetSync('null', walletHash, data));
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var data = { hasWallet: true };
|
var data = { hasWallet: true };
|
||||||
if (response.changed) {
|
if (response.changed) {
|
||||||
var syncHash = response.data.hash;
|
var syncHash = response.hash;
|
||||||
data.syncHash = syncHash;
|
data.syncHash = syncHash;
|
||||||
_lbryRedux.Lbry.sync_apply({ password: password, data: response.data.data }).then(function (_ref2) {
|
_lbryRedux.Lbry.sync_apply({ password: password, data: response.data }).then(function (_ref) {
|
||||||
var walletHash = _ref2.hash,
|
var walletHash = _ref.hash,
|
||||||
data = _ref2.data;
|
walletData = _ref.data;
|
||||||
|
|
||||||
if (walletHash !== syncHash) {
|
if (walletHash !== syncHash) {
|
||||||
// different local hash, need to synchronise
|
// different local hash, need to synchronise
|
||||||
dispatch(doSetSync(syncHash, walletHash, data));
|
dispatch(doSetSync(syncHash, walletHash, walletData));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9696,9 +9684,9 @@ function doGetSync(password) {
|
||||||
|
|
||||||
// call sync_apply to get data to sync
|
// call sync_apply to get data to sync
|
||||||
// first time sync. use any string for old hash
|
// first time sync. use any string for old hash
|
||||||
_lbryRedux.Lbry.sync_apply({ password: password }).then(function (_ref3) {
|
_lbryRedux.Lbry.sync_apply({ password: password }).then(function (_ref2) {
|
||||||
var walletHash = _ref3.hash,
|
var walletHash = _ref2.hash,
|
||||||
data = _ref3.data;
|
data = _ref2.data;
|
||||||
return dispatch(doSetSync('null', walletHash, data));
|
return dispatch(doSetSync('null', walletHash, data));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,8 +8,8 @@ export function doSetSync(oldHash, newHash, data) {
|
||||||
type: ACTIONS.SET_SYNC_STARTED,
|
type: ACTIONS.SET_SYNC_STARTED,
|
||||||
});
|
});
|
||||||
|
|
||||||
Lbryio.call('sync', 'set', { old_hash: oldHash, new_hash: newHash, data }, 'post').then(
|
Lbryio.call('sync', 'set', { old_hash: oldHash, new_hash: newHash, data }, 'post')
|
||||||
response => {
|
.then(response => {
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
return dispatch({
|
return dispatch({
|
||||||
type: ACTIONS.SET_SYNC_FAILED,
|
type: ACTIONS.SET_SYNC_FAILED,
|
||||||
|
@ -17,13 +17,17 @@ export function doSetSync(oldHash, newHash, data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncHash = response.data ? response.data.hash : newHash;
|
|
||||||
return dispatch({
|
return dispatch({
|
||||||
type: ACTIONS.SET_SYNC_COMPLETED,
|
type: ACTIONS.SET_SYNC_COMPLETED,
|
||||||
data: { syncHash },
|
data: { syncHash: response.hash },
|
||||||
});
|
});
|
||||||
}
|
})
|
||||||
);
|
.catch(error =>
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.SET_SYNC_FAILED,
|
||||||
|
data: { error },
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,25 +40,11 @@ export function doGetSync(password) {
|
||||||
Lbry.sync_hash().then(hash => {
|
Lbry.sync_hash().then(hash => {
|
||||||
Lbryio.call('sync', 'get', { hash }, 'post')
|
Lbryio.call('sync', 'get', { hash }, 'post')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.success) {
|
|
||||||
// user doesn't have a synced wallet
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.GET_SYNC_COMPLETED,
|
|
||||||
data: { hasWallet: false, syncHash: null },
|
|
||||||
});
|
|
||||||
|
|
||||||
// call sync_apply to get data to sync (first time sync)
|
|
||||||
Lbry.sync_apply({ password }).then(({ hash: walletHash, data }) =>
|
|
||||||
dispatch(doSetSync('null', walletHash, data))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = { hasWallet: true };
|
const data = { hasWallet: true };
|
||||||
if (response.changed) {
|
if (response.changed) {
|
||||||
const syncHash = response.data.hash;
|
const syncHash = response.hash;
|
||||||
data.syncHash = syncHash;
|
data.syncHash = syncHash;
|
||||||
Lbry.sync_apply({ password, data: response.data.data }).then(
|
Lbry.sync_apply({ password, data: response.data }).then(
|
||||||
({ hash: walletHash, data: walletData }) => {
|
({ hash: walletHash, data: walletData }) => {
|
||||||
if (walletHash !== syncHash) {
|
if (walletHash !== syncHash) {
|
||||||
// different local hash, need to synchronise
|
// different local hash, need to synchronise
|
||||||
|
|
Loading…
Add table
Reference in a new issue