Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Block polling on demand #346

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/hoc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as withAccountTransactions } from './withAccountTransactions';
export { default as withActionSheetManager } from './withActionSheetManager';
export { default as withAppState } from './withAppState';
export { default as withBlockedHorizontalSwipe } from './withBlockedHorizontalSwipe';
export { default as withBlockPolling } from './withBlockPolling';
export { default as withContacts } from './withContacts';
export { default as withDataInit } from './withDataInit';
export { default as withDeepLink } from './withDeepLink';
Expand Down
8 changes: 8 additions & 0 deletions src/hoc/withBlockPolling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { connect } from 'react-redux';
import { web3ListenerInit, web3ListenerStop } from '../redux/web3listener';

export default Component =>
connect(null, {
web3ListenerInit,
web3ListenerStop,
})(Component);
8 changes: 1 addition & 7 deletions src/hoc/withDataInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ import {
walletConnectLoadState,
walletConnectClearState,
} from '../redux/walletconnect';
import {
web3ListenerClearState,
web3ListenerInit,
} from '../redux/web3listener';

import { promiseUtils, sentryUtils } from '../utils';
import withHideSplashScreen from './withHideSplashScreen';

Expand Down Expand Up @@ -77,7 +74,6 @@ export default Component =>
uniswapUpdateState,
walletConnectClearState,
walletConnectLoadState,
web3ListenerInit,
}),
withHideSplashScreen,
withHandlers({
Expand All @@ -90,7 +86,6 @@ export default Component =>
}
},
clearAccountData: ownProps => async () => {
web3ListenerClearState();
const p0 = ownProps.explorerClearState();
const p1 = ownProps.dataClearState();
const p2 = ownProps.clearIsWalletEmpty();
Expand Down Expand Up @@ -118,7 +113,6 @@ export default Component =>
sentryUtils.addInfoBreadcrumb('Initialize account data');
ownProps.explorerInit();
ownProps.uniswapPairsInit();
ownProps.web3ListenerInit();
await ownProps.uniqueTokensRefreshState();
} catch (error) {
// TODO error state
Expand Down
3 changes: 2 additions & 1 deletion src/redux/web3listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const web3UpdateReserves = () => async (dispatch, getState) => {
};

export const web3ListenerInit = () => dispatch => {
web3Provider.pollingInterval = 8000;
web3Provider.on('block', () => dispatch(web3UpdateReserves()));
};

export const web3ListenerClearState = () => {
export const web3ListenerStop = () => () => {
web3Provider.removeAllListeners('block');
};
6 changes: 6 additions & 0 deletions src/screens/ExchangeModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
withAccountData,
withAccountSettings,
withBlockedHorizontalSwipe,
withBlockPolling,
withGas,
withTransactionConfirmationScreen,
withTransitionProps,
Expand Down Expand Up @@ -106,6 +107,8 @@ class ExchangeModal extends Component {
uniswapAddPendingApproval: PropTypes.func,
uniswapAssetsInWallet: PropTypes.arrayOf(PropTypes.object),
uniswapUpdateAllowances: PropTypes.func,
web3ListenerInit: PropTypes.func,
web3ListenerStop: PropTypes.func,
};

state = {
Expand Down Expand Up @@ -133,6 +136,7 @@ class ExchangeModal extends Component {
this.props.gasUpdateDefaultGasLimit(ethUnits.basic_swap);
InteractionManager.runAfterInteractions(() => {
this.props.gasPricesStartPolling();
this.props.web3ListenerInit();
});
}

Expand Down Expand Up @@ -242,6 +246,7 @@ class ExchangeModal extends Component {
}
this.props.uniswapClearCurrenciesAndReserves();
this.props.gasPricesStopPolling();
this.props.web3ListenerStop();
};

lastFocusedInput = null;
Expand Down Expand Up @@ -904,6 +909,7 @@ export default compose(
withAccountSettings,
withBlockedHorizontalSwipe,
withGas,
withBlockPolling,
withNavigationFocus,
withTransactionConfirmationScreen,
withTransitionProps,
Expand Down