Browse Source

fix(syncing): move syncing logic out of application component

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
32d0134623
  1. 32
      app/containers/Root.js
  2. 2
      app/routes.js
  3. 12
      app/routes/app/components/App.js

32
app/containers/Root.js

@ -1,15 +1,39 @@
// @flow // @flow
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider, connect } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux' import { ConnectedRouter } from 'react-router-redux'
import { fetchBlockHeight, lndSelectors } from 'reducers/lnd'
import LndSyncing from 'components/LndSyncing'
import Routes from '../routes' import Routes from '../routes'
const mapDispatchToProps = {
fetchBlockHeight
}
const mapStateToProps = state => ({
syncPercentage: lndSelectors.syncPercentage(state)
})
type RootType = { type RootType = {
store: {}, store: {},
history: {} history: {}
}; };
export default function Root({ store, history }: RootType) { class Root extends React.Component {
render() {
const { store, history, fetchBlockHeight, syncPercentage } = this.props
const { lnd } = store.getState()
if (lnd.syncing) {
return (
<LndSyncing
fetchBlockHeight={fetchBlockHeight}
fetchingBlockHeight={lnd.fetchingBlockHeight}
syncPercentage={syncPercentage}
/>
)
}
return ( return (
<Provider store={store}> <Provider store={store}>
<ConnectedRouter history={history}> <ConnectedRouter history={history}>
@ -17,4 +41,8 @@ export default function Root({ store, history }: RootType) {
</ConnectedRouter> </ConnectedRouter>
</Provider> </Provider>
) )
}
} }
export default connect(mapStateToProps, mapDispatchToProps)(Root)

2
app/routes.js

@ -14,4 +14,4 @@ export default () => (
<Route path='/' component={Activity} /> <Route path='/' component={Activity} />
</Switch> </Switch>
</App> </App>
); )

12
app/routes/app/components/App.js

@ -13,13 +13,11 @@ class App extends Component {
componentWillMount() { componentWillMount() {
const { fetchTicker, fetchBalance, fetchInfo, newAddress, lnd: { syncing } } = this.props const { fetchTicker, fetchBalance, fetchInfo, newAddress, lnd: { syncing } } = this.props
if (!syncing) {
fetchTicker() fetchTicker()
fetchBalance() fetchBalance()
fetchInfo() fetchInfo()
newAddress('p2pkh') newAddress('p2pkh')
} }
}
render() { render() {
const { const {
@ -47,16 +45,6 @@ class App extends Component {
children children
} = this.props } = this.props
if (lnd.syncing) {
return (
<LndSyncing
fetchBlockHeight={fetchBlockHeight}
fetchingBlockHeight={lnd.fetchingBlockHeight}
syncPercentage={syncPercentage}
/>
)
}
if (!currentTicker || balance.balanceLoading) { return <LoadingBolt /> } if (!currentTicker || balance.balanceLoading) { return <LoadingBolt /> }
return ( return (

Loading…
Cancel
Save