1 import React from 'react'
2 import { connect } from 'react-redux'
3 import actions from 'actions'
4 import { Main, Config, Login, Loading, Modal } from './'
6 const CORE_POLLING_TIME = 2 * 1000
7 const TESTNET_INFO_POLLING_TIME = 30 * 1000
9 class Container extends React.Component {
12 this.redirectRoot = this.redirectRoot.bind(this)
23 if (!authOk || !configKnown) {
28 if (location.pathname === '/' ||
29 location.pathname.indexOf('configuration') >= 0) {
33 this.props.showConfiguration()
37 componentWillMount() {
38 const checkTestnet = () => {
39 if (this.props.onTestnet) this.props.fetchTestnetInfo()
42 this.props.fetchInfo().then(() => {
44 this.redirectRoot(this.props)
47 setInterval(() => this.props.fetchInfo(), CORE_POLLING_TIME)
48 setInterval(() => checkTestnet(), TESTNET_INFO_POLLING_TIME)
51 componentWillReceiveProps(nextProps) {
52 if (nextProps.authOk != this.props.authOk ||
53 nextProps.configKnown != this.props.configKnown ||
54 nextProps.configured != this.props.configured ||
55 nextProps.location.pathname != this.props.location.pathname) {
56 this.redirectRoot(nextProps)
63 if (!this.props.authOk) {
65 } else if (!this.props.configKnown) {
66 return <Loading>Connecting to Chain Core...</Loading>
67 } else if (!this.props.configured) {
68 layout = <Config>{this.props.children}</Config>
70 layout = <Main>{this.props.children}</Main>
77 {/* For copyToClipboard(). TODO: move this some place cleaner. */}
80 onChange={() => 'do nothing'}
82 style={{display: 'none'}}
88 export default connect(
90 authOk: !state.core.requireClientToken || state.core.validToken,
91 configKnown: state.core.configKnown,
92 configured: state.core.configured,
93 onTestnet: state.core.onTestnet,
96 fetchInfo: options => dispatch(actions.core.fetchCoreInfo(options)),
97 fetchTestnetInfo: () => dispatch(actions.testnet.fetchTestnetInfo()),
98 showRoot: () => dispatch(actions.app.showRoot),
99 showConfiguration: () => dispatch(actions.app.showConfiguration()),