redirectRoot(props) {
const {
authOk,
- configKnown,
configured,
- location
+ location,
+ accountInit
} = props
- if (!authOk || !configKnown) {
+ if (!authOk) {
return
}
- location.pathname.indexOf('configuration') >= 0 || location.pathname.includes('index.html')) {
+ if (configured) {
+ if (location.pathname === '/' ||
++ location.pathname.indexOf('configuration') >= 0 || location.pathname.includes('index.html')) {
++ this.props.showRoot()
++ }
++ } else {
++ this.props.showInitialization()
++ }
++
+ if (accountInit || !this.state.noAccountItem) {
+ if (location.pathname === '/'|| location.pathname.indexOf('initialization') >= 0) {
this.props.showRoot()
}
} else {
- this.props.showConfiguration()
+ this.props.showInitialization()
}
++
}
+
componentDidMount() {
+ if(window.ipcRenderer){
+ window.ipcRenderer.on('redirect', (event, arg) => {
+ this.props.history.push(arg)
+ })
+ window.ipcRenderer.on('btmAmountUnitState', (event, arg) => {
+ this.props.uptdateBtmAmountUnit(arg)
+ })
+ window.ipcRenderer.on('lang', (event, arg) => {
+ this.props.uptdateLang(arg)
+ })
+ window.ipcRenderer.on('ConfiguredNetwork', (event, arg) => {
+ if(arg === 'startNode'){
+ this.props.fetchInfo().then(() => {
+ this.props.fetchAccountItem().then(resp => {
+ if (resp.data.length == 0) {
+ this.setState({noAccountItem: true})
+ }
+ })
+ this.props.showRoot()
+ })
+ setInterval(() => this.props.fetchInfo(), CORE_POLLING_TIME)
+ }
+ if(arg === 'init'){
+ this.props.updateConfiguredStatus()
+ }
+ })
+ window.ipcRenderer.on('mining', (event, arg) => {
+ let isMining = (arg == 'true')
+ this.props.updateMiningState(isMining)
+ })
+ }
+ this.props.fetchKeyItem().then(resp => {
+ if (resp.data.length == 0) {
+ this.setState({noAccountItem: true})
+ this.redirectRoot(this.props)
+ }
+ })
if(this.props.lng === 'zh'){
moment.locale('zh-cn')
}else{
}
}
- componentWillMount() {
- this.props.fetchInfo().then(() => {
- this.redirectRoot(this.props)
- })
-
- setInterval(() => this.props.fetchInfo(), CORE_POLLING_TIME)
- }
-
componentWillReceiveProps(nextProps) {
- if (nextProps.authOk != this.props.authOk ||
- nextProps.configKnown != this.props.configKnown ||
+ if (nextProps.accountInit != this.props.accountInit ||
nextProps.configured != this.props.configured ||
nextProps.location.pathname != this.props.location.pathname) {
this.redirectRoot(nextProps)
if (!this.props.authOk) {
layout = <Login/>
- } else if (!this.props.configKnown) {
- return <Loading>Connecting to Bytom Core...</Loading>
} else if (!this.props.configured) {
layout = <Config>{this.props.children}</Config>
+ } else if (!this.props.configKnown) {
+ return <Loading>{lang === 'zh'? '正在连接到Bytom Core...' : 'Connecting to Bytom Core...'}</Loading>
} else if (!this.props.accountInit && this.state.noAccountItem){
- layout = <Register>{this.props.children}</Register>
+ layout = <Config>{this.props.children}</Config>
} else{
layout = <Main>{this.props.children}</Main>
}
}),
(dispatch) => ({
fetchInfo: options => dispatch(actions.core.fetchCoreInfo(options)),
+ updateMiningState: param => dispatch(actions.core.updateMiningState(param)),
showRoot: () => dispatch(actions.app.showRoot),
- uptdateLang: (param) => dispatch(actions.core.updateLang(param)),
+ showConfiguration: () => dispatch(actions.app.showConfiguration()),
+ uptdateBtmAmountUnit: (param) => dispatch(actions.core.updateBTMAmountUnit(param)),
- fetchAccountItem: () => dispatch(actions.account.fetchItems())
+ updateConfiguredStatus: () => dispatch(actions.core.updateConfiguredStatus),
+ markFlashDisplayed: (key) => dispatch(actions.app.displayedFlash(key)),
++ fetchAccountItem: () => dispatch(actions.account.fetchItems()),
+ showInitialization: () => dispatch(actions.app.showInitialization()),
+ fetchKeyItem: () => dispatch(actions.key.fetchItems())
})
)( withI18n() (Container) )