From 54ef55d430db13ecd77699d23974cf871445ebd7 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 17 May 2019 16:41:37 +0100 Subject: [PATCH] add doCheckSync action to check if user has a synced wallet --- dist/bundle.es.js | 32 +++++++++++++++++++++++++++++++- dist/bundle.js | 34 +++++++++++++++++++++++++++++++++- src/index.js | 2 +- src/redux/actions/sync.js | 23 +++++++++++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 70ad297..dd28f8b 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2024,7 +2024,7 @@ function doSetDefaultAccount() { } = accountList; let defaultId; - for (let i = 0; i < accounts.length; i++) { + for (let i = 0; i < accounts.length; ++i) { if (accounts[i].satoshis > 0) { defaultId = accounts[i].id; break; @@ -2105,6 +2105,35 @@ function doGetSync(password) { }); }; } +function doCheckSync() { + return dispatch => { + dispatch({ + type: GET_SYNC_STARTED + }); + lbryRedux.Lbry.sync_hash().then(hash => { + Lbryio.call('sync', 'get', { + hash + }, 'post').then(response => { + const data = { + hasSyncedWallet: true + }; + dispatch({ + type: GET_SYNC_COMPLETED, + data + }); + }).catch(() => { + // user doesn't have a synced wallet + dispatch({ + type: GET_SYNC_COMPLETED, + data: { + hasSyncedWallet: false, + syncHash: null + } + }); + }); + }); + }; +} const reducers = {}; const defaultState$1 = { @@ -2668,6 +2697,7 @@ exports.doChannelUnsubscribe = doChannelUnsubscribe; exports.doCheckSubscription = doCheckSubscription; exports.doCheckSubscriptions = doCheckSubscriptions; exports.doCheckSubscriptionsInit = doCheckSubscriptionsInit; +exports.doCheckSync = doCheckSync; exports.doClaimEligiblePurchaseRewards = doClaimEligiblePurchaseRewards; exports.doClaimRewardClearError = doClaimRewardClearError; exports.doClaimRewardType = doClaimRewardType; diff --git a/dist/bundle.js b/dist/bundle.js index cfaa8ba..79a3a3f 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -208,6 +208,8 @@ __webpack_require__.r(__webpack_exports__); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return redux_actions_stats__WEBPACK_IMPORTED_MODULE_11__["doFetchViewCount"]; }); /* harmony import */ var redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(25); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doCheckSync"]; }); + /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doGetSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doGetSync"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doSetSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_12__["doSetSync"]; }); @@ -3401,6 +3403,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSetSync", function() { return doSetSync; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSetDefaultAccount", function() { return doSetDefaultAccount; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doGetSync", function() { return doGetSync; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return doCheckSync; }); /* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); /* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); /* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3); @@ -3452,7 +3455,7 @@ function doSetDefaultAccount() { var accounts = accountList.lbc_mainnet; var defaultId; - for (var i = 0; i < accounts.length; i++) { + for (var i = 0; i < accounts.length; ++i) { if (accounts[i].satoshis > 0) { defaultId = accounts[i].id; break; @@ -3534,6 +3537,35 @@ function doGetSync(password) { }); }; } +function doCheckSync() { + return function (dispatch) { + dispatch({ + type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_STARTED"] + }); + lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash().then(function (hash) { + lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', { + hash: hash + }, 'post').then(function (response) { + var data = { + hasSyncedWallet: true + }; + dispatch({ + type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"], + data: data + }); + })["catch"](function () { + // user doesn't have a synced wallet + dispatch({ + type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"], + data: { + hasSyncedWallet: false, + syncHash: null + } + }); + }); + }); + }; +} /***/ }), /* 26 */ diff --git a/src/index.js b/src/index.js index da1bcb9..38b0a4c 100644 --- a/src/index.js +++ b/src/index.js @@ -59,7 +59,7 @@ export { doFetchCostInfoForUri } from 'redux/actions/cost_info'; export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist'; export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage'; export { doFetchViewCount } from 'redux/actions/stats'; -export { doGetSync, doSetSync, doSetDefaultAccount } from 'redux/actions/sync'; +export { doCheckSync, doGetSync, doSetSync, doSetDefaultAccount } from 'redux/actions/sync'; // reducers export { authReducer } from 'redux/reducers/auth'; diff --git a/src/redux/actions/sync.js b/src/redux/actions/sync.js index fa8ecac..96ef3dd 100644 --- a/src/redux/actions/sync.js +++ b/src/redux/actions/sync.js @@ -105,3 +105,26 @@ export function doGetSync(password) { }); }; } + +export function doCheckSync() { + return dispatch => { + dispatch({ + type: ACTIONS.GET_SYNC_STARTED, + }); + + Lbry.sync_hash().then(hash => { + Lbryio.call('sync', 'get', { hash }, 'post') + .then(() => { + const data = { hasSyncedWallet: true }; + dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); + }) + .catch(() => { + // user doesn't have a synced wallet + dispatch({ + type: ACTIONS.GET_SYNC_COMPLETED, + data: { hasSyncedWallet: false, syncHash: null }, + }); + }); + }); + }; +}