diff --git a/dist/bundle.js b/dist/bundle.js index e5a6c1f..d5f52f4 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -9638,10 +9638,14 @@ function doSetSync(oldHash, newHash, data) { }); } - var syncHash = response.data.hash; - dispatch({ + return dispatch({ 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) { _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 }; if (response.changed) { - var syncHash = response.data.hash; + var syncHash = response.hash; data.syncHash = syncHash; - _lbryRedux.Lbry.sync_apply({ password: password, data: response.data.data }).then(function (_ref2) { - var walletHash = _ref2.hash, - data = _ref2.data; + _lbryRedux.Lbry.sync_apply({ password: password, data: response.data }).then(function (_ref) { + var walletHash = _ref.hash, + walletData = _ref.data; if (walletHash !== syncHash) { // 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 // first time sync. use any string for old hash - _lbryRedux.Lbry.sync_apply({ password: password }).then(function (_ref3) { - var walletHash = _ref3.hash, - data = _ref3.data; + _lbryRedux.Lbry.sync_apply({ password: password }).then(function (_ref2) { + var walletHash = _ref2.hash, + data = _ref2.data; return dispatch(doSetSync('null', walletHash, data)); }); }); diff --git a/src/redux/actions/sync.js b/src/redux/actions/sync.js index 6c61a62..3ee38bd 100644 --- a/src/redux/actions/sync.js +++ b/src/redux/actions/sync.js @@ -8,8 +8,8 @@ export function doSetSync(oldHash, newHash, data) { type: ACTIONS.SET_SYNC_STARTED, }); - Lbryio.call('sync', 'set', { old_hash: oldHash, new_hash: newHash, data }, 'post').then( - response => { + Lbryio.call('sync', 'set', { old_hash: oldHash, new_hash: newHash, data }, 'post') + .then(response => { if (!response.success) { return dispatch({ 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({ 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 => { Lbryio.call('sync', 'get', { hash }, 'post') .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 }; if (response.changed) { - const syncHash = response.data.hash; + const syncHash = response.hash; data.syncHash = syncHash; - Lbry.sync_apply({ password, data: response.data.data }).then( + Lbry.sync_apply({ password, data: response.data }).then( ({ hash: walletHash, data: walletData }) => { if (walletHash !== syncHash) { // different local hash, need to synchronise