simplify balance check now that we are in redux land
This commit is contained in:
parent
f7aec65912
commit
31cc95cf0e
5 changed files with 19 additions and 53 deletions
|
@ -1,5 +1,4 @@
|
|||
import * as types from "constants/action_types";
|
||||
import * as settings from "constants/settings";
|
||||
import lbry from "lbry";
|
||||
import {
|
||||
selectUpdateUrl,
|
||||
|
@ -8,6 +7,7 @@ import {
|
|||
selectUpgradeFilename,
|
||||
} from "selectors/app";
|
||||
import { doFetchDaemonSettings } from "actions/settings";
|
||||
import { doBalanceSubscribe } from "actions/wallet";
|
||||
import { doAuthenticate } from "actions/user";
|
||||
import { doFetchFileInfosAndPublishedClaims } from "actions/file_info";
|
||||
|
||||
|
@ -178,6 +178,7 @@ export function doDaemonReady() {
|
|||
dispatch(doAuthenticate());
|
||||
dispatch({ type: types.DAEMON_READY });
|
||||
dispatch(doFetchDaemonSettings());
|
||||
dispatch(doBalanceSubscribe());
|
||||
dispatch(doFetchFileInfosAndPublishedClaims());
|
||||
};
|
||||
}
|
||||
|
|
|
@ -9,12 +9,23 @@ import { doOpenModal, doShowSnackBar } from "actions/app";
|
|||
import { doNavigate } from "actions/navigation";
|
||||
import * as modals from "constants/modal_types";
|
||||
|
||||
export function doUpdateBalance(balance) {
|
||||
return {
|
||||
type: types.UPDATE_BALANCE,
|
||||
data: {
|
||||
balance: balance,
|
||||
},
|
||||
export function doUpdateBalance() {
|
||||
return function(dispatch, getState) {
|
||||
lbry.wallet_balance().then(balance => {
|
||||
return dispatch({
|
||||
type: types.UPDATE_BALANCE,
|
||||
data: {
|
||||
balance: balance,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function doBalanceSubscribe() {
|
||||
return function(dispatch, getState) {
|
||||
dispatch(doUpdateBalance());
|
||||
setInterval(() => dispatch(doUpdateBalance()), 5000);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import { selectUser } from "selectors/user";
|
|||
import { doCheckUpgradeAvailable, doAlertError } from "actions/app";
|
||||
import { doRecordScroll } from "actions/navigation";
|
||||
import { doFetchRewardedContent } from "actions/content";
|
||||
import { doUpdateBalance } from "actions/wallet";
|
||||
import App from "./view";
|
||||
|
||||
const select = (state, props) => ({
|
||||
|
@ -16,7 +15,6 @@ const select = (state, props) => ({
|
|||
const perform = dispatch => ({
|
||||
alertError: errorList => dispatch(doAlertError(errorList)),
|
||||
checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()),
|
||||
updateBalance: balance => dispatch(doUpdateBalance(balance)),
|
||||
fetchRewardedContent: () => dispatch(doFetchRewardedContent()),
|
||||
recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)),
|
||||
});
|
||||
|
|
|
@ -10,7 +10,6 @@ class App extends React.PureComponent {
|
|||
const {
|
||||
alertError,
|
||||
checkUpgradeAvailable,
|
||||
updateBalance,
|
||||
fetchRewardedContent,
|
||||
} = this.props;
|
||||
|
||||
|
@ -22,10 +21,6 @@ class App extends React.PureComponent {
|
|||
checkUpgradeAvailable();
|
||||
}
|
||||
|
||||
lbry.balanceSubscribe(balance => {
|
||||
updateBalance(balance);
|
||||
});
|
||||
|
||||
fetchRewardedContent();
|
||||
|
||||
this.scrollListener = () => this.props.recordScroll(window.scrollY);
|
||||
|
|
|
@ -279,45 +279,6 @@ lbry.getMediaType = function(contentType, fileName) {
|
|||
}
|
||||
};
|
||||
|
||||
lbry._subscribeIdCount = 0;
|
||||
lbry._balanceSubscribeCallbacks = {};
|
||||
lbry._balanceSubscribeInterval = 5000;
|
||||
|
||||
lbry._balanceUpdateInterval = null;
|
||||
lbry._updateBalanceSubscribers = function() {
|
||||
lbry.wallet_balance().then(function(balance) {
|
||||
for (let callback of Object.values(lbry._balanceSubscribeCallbacks)) {
|
||||
callback(balance);
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
!lbry._balanceUpdateInterval &&
|
||||
Object.keys(lbry._balanceSubscribeCallbacks).length
|
||||
) {
|
||||
lbry._balanceUpdateInterval = setInterval(() => {
|
||||
lbry._updateBalanceSubscribers();
|
||||
}, lbry._balanceSubscribeInterval);
|
||||
}
|
||||
};
|
||||
|
||||
lbry.balanceSubscribe = function(callback) {
|
||||
const subscribeId = ++lbry._subscribeIdCount;
|
||||
lbry._balanceSubscribeCallbacks[subscribeId] = callback;
|
||||
lbry._updateBalanceSubscribers();
|
||||
return subscribeId;
|
||||
};
|
||||
|
||||
lbry.balanceUnsubscribe = function(subscribeId) {
|
||||
delete lbry._balanceSubscribeCallbacks[subscribeId];
|
||||
if (
|
||||
lbry._balanceUpdateInterval &&
|
||||
!Object.keys(lbry._balanceSubscribeCallbacks).length
|
||||
) {
|
||||
clearInterval(lbry._balanceUpdateInterval);
|
||||
}
|
||||
};
|
||||
|
||||
lbry.showMenuIfNeeded = function() {
|
||||
const showingMenu = sessionStorage.getItem("menuShown") || null;
|
||||
const chosenMenu = lbry.getClientSetting("showDeveloperMenu")
|
||||
|
|
Loading…
Add table
Reference in a new issue