add doCheckSync action to check if user has a synced wallet

This commit is contained in:
Akinwale Ariwodola 2019-05-17 16:41:37 +01:00
parent 7ba14f1d88
commit 54ef55d430
4 changed files with 88 additions and 3 deletions

32
dist/bundle.es.js vendored
View file

@ -2024,7 +2024,7 @@ function doSetDefaultAccount() {
} = accountList; } = accountList;
let defaultId; let defaultId;
for (let i = 0; i < accounts.length; i++) { for (let i = 0; i < accounts.length; ++i) {
if (accounts[i].satoshis > 0) { if (accounts[i].satoshis > 0) {
defaultId = accounts[i].id; defaultId = accounts[i].id;
break; 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 reducers = {};
const defaultState$1 = { const defaultState$1 = {
@ -2668,6 +2697,7 @@ exports.doChannelUnsubscribe = doChannelUnsubscribe;
exports.doCheckSubscription = doCheckSubscription; exports.doCheckSubscription = doCheckSubscription;
exports.doCheckSubscriptions = doCheckSubscriptions; exports.doCheckSubscriptions = doCheckSubscriptions;
exports.doCheckSubscriptionsInit = doCheckSubscriptionsInit; exports.doCheckSubscriptionsInit = doCheckSubscriptionsInit;
exports.doCheckSync = doCheckSync;
exports.doClaimEligiblePurchaseRewards = doClaimEligiblePurchaseRewards; exports.doClaimEligiblePurchaseRewards = doClaimEligiblePurchaseRewards;
exports.doClaimRewardClearError = doClaimRewardClearError; exports.doClaimRewardClearError = doClaimRewardClearError;
exports.doClaimRewardType = doClaimRewardType; exports.doClaimRewardType = doClaimRewardType;

34
dist/bundle.js vendored
View file

@ -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 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 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__, "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"]; }); /* 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__, "doSetSync", function() { return doSetSync; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSetDefaultAccount", function() { return doSetDefaultAccount; }); /* 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__, "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 constants_action_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
/* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); /* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
/* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3); /* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
@ -3452,7 +3455,7 @@ function doSetDefaultAccount() {
var accounts = accountList.lbc_mainnet; var accounts = accountList.lbc_mainnet;
var defaultId; var defaultId;
for (var i = 0; i < accounts.length; i++) { for (var i = 0; i < accounts.length; ++i) {
if (accounts[i].satoshis > 0) { if (accounts[i].satoshis > 0) {
defaultId = accounts[i].id; defaultId = accounts[i].id;
break; 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 */ /* 26 */

View file

@ -59,7 +59,7 @@ export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist'; export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage'; export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage';
export { doFetchViewCount } from 'redux/actions/stats'; export { doFetchViewCount } from 'redux/actions/stats';
export { doGetSync, doSetSync, doSetDefaultAccount } from 'redux/actions/sync'; export { doCheckSync, doGetSync, doSetSync, doSetDefaultAccount } from 'redux/actions/sync';
// reducers // reducers
export { authReducer } from 'redux/reducers/auth'; export { authReducer } from 'redux/reducers/auth';

View file

@ -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 },
});
});
});
};
}