From: Zhiting Lin Date: Wed, 11 Apr 2018 11:58:27 +0000 (+0800) Subject: add the mining option for dashboard X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=acf8502b78b71076f6c1ea80131cae0357b5dc50;p=bytom%2Fbytom-electron.git add the mining option for dashboard --- diff --git a/src/features/core/actions.js b/src/features/core/actions.js index cd9c85c..0afc8e9 100644 --- a/src/features/core/actions.js +++ b/src/features/core/actions.js @@ -7,6 +7,20 @@ const updateBTMAmountUnit = (param) => ({type: 'UPDATE_BTM_AMOUNT_UNIT', param}) const updateConfiguredStatus = ({ type: 'SET_CONFIGURED' }) const updateLang = (param) => ({type: 'UPDATE_CORE_LANGUAGE', lang:param}) +const updateMiningState = (param) => { + return (dispatch) => { + return chainClient().config.mining(param) + .then(() => { + dispatch({type: 'UPDATE_MINING_STATE', param}) + }) + .catch((err) => { + if (!err.status) { + throw err + } + }) + } +} + const fetchCoreInfo = (options = {}) => { return (dispatch) => { return chainClient().config.info() @@ -33,6 +47,7 @@ let actions = { updateBTMAmountUnit, updateLang, updateConfiguredStatus, + updateMiningState, fetchCoreInfo, clearSession, logIn: (token) => (dispatch) => { diff --git a/src/features/core/components/CoreIndex/CoreIndex.jsx b/src/features/core/components/CoreIndex/CoreIndex.jsx index 45cce39..d985967 100644 --- a/src/features/core/components/CoreIndex/CoreIndex.jsx +++ b/src/features/core/components/CoreIndex/CoreIndex.jsx @@ -15,22 +15,12 @@ class CoreIndex extends React.Component { this.state = { btmAmountUnit: 'BTM' } - this.deleteClick = this.deleteClick.bind(this) + this.handleMiningState = this.handleMiningState.bind(this) this.handleAdvancedOptionChange = this.handleAdvancedOptionChange.bind(this) this.changeBTMamount = this.changeBTMamount.bind(this) } componentDidMount() { - const fetchInfo = () => { - if(this.refs.requestComponent) { - chainClient().config.info().then(resp => { - this.setState({requestStatus: resp.data}) - }) - } - } - setInterval(fetchInfo.bind(this), 2 * 1000) - - if(window.ipcRenderer){ window.ipcRenderer.on('btmAmountUnitState', (event, arg) => { this.props.uptdateBtmAmountUnit(arg) @@ -38,28 +28,6 @@ class CoreIndex extends React.Component { } } - deleteClick() { - if (!window.confirm('Are you sure you want to delete all data on this core?')) { - return - } - - this.setState({deleteDisabled: true}) - - chainClient().config.reset(true).then(() => { - // TODO: Use Redux state reset and nav action instead of window.location. - // Also, move confirmation message to a bonafide flash div. alert() in a - // browser microtask is going away. cf https://www.chromestatus.com/features/5647113010544640 - setTimeout(function(){ - window.location.href = '/' - }, 500) - }).catch((err) => { - this.setState({ - deleteError: err, - deleteDisabled: false, - }) - }) - } - changeBTMamount(value) { this.setState({ btmAmountUnit: value }) this.props.uptdateBtmAmountUnit(value) @@ -74,28 +42,18 @@ class CoreIndex extends React.Component { } } - render() { - const { - onTestnet, - testnetBlockchainMismatch, - testnetNetworkMismatch, - testnetNextReset, - } = this.props - - let generatorUrl - if (this.props.core.generator) { - generatorUrl = window.location.origin - } else if (onTestnet) { - generatorUrl = - {this.props.core.generatorUrl} -   - Chain Testnet - - } else { - generatorUrl = this.props.core.generatorUrl + handleMiningState(event){ + const target = event.target + if( target.checked ){ + this.props.updateMiningState(true) + }else{ + this.props.updateMiningState(false) } + } + render() { let navState = this.props.navAdvancedState === 'advance' + let miningState = this.props.core.mingStatus let configBlock = (
@@ -103,59 +61,10 @@ class CoreIndex extends React.Component {

Configuration

- {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/*{onTestnet && !!testnetNextReset &&*/} - {/**/} - {/**/} - {/**/} - {/*}*/} - {/*{!this.props.core.generator &&*/} - {/**/} - {/**/} - {/**/} - {/*}*/} - {/**/} - {/**/} - {/**/} - {/**/} @@ -173,6 +82,19 @@ class CoreIndex extends React.Component { + + + +
Core type:{this.props.core.coreType}
Setup time:{this.props.core.configuredAt}
Version:{this.props.core.version}
Language: {this.props.core.lang === 'zh' ? '中文' : 'English'}
MockHSM enabled:{this.props.core.mockhsm.toString()}
Localhost auth:{this.props.core.localhostAuth.toString()}
Reset enabled:{this.props.core.reset.toString()}
Non-TLS HTTP requests enabled:{this.props.core.httpOk.toString()}

Generator URL:{generatorUrl}
Next Chain Testnet data reset:{testnetNextReset.toString()}
Generator Access Token:{this.props.core.generatorAccessToken}
Blockchain ID:{this.props.core.blockchainId}

Mining: + +
Unit to show amount in ) - let testnetErr - if (onTestnet) { - if (testnetBlockchainMismatch) { - testnetErr = 'Chain Testnet has been reset. Please reset your core below.' - } else if (testnetNetworkMismatch) { - testnetErr = {message: This core is no longer compatible with Chain Testnet. Please upgrade Chain Core.} - } - } - - let requestStatusBlock = - this.state.requestStatus && (
+ let coreData = this.props.core.coreData + let requestStatusBlock =( +

Network status

- {Object.keys(this.state.requestStatus).map(key => ( + {Object.keys(coreData).map(key => ( - + ))}
{key}: { String(this.state.requestStatus[key])}{ String(coreData[key])}
@@ -220,63 +134,8 @@ class CoreIndex extends React.Component { let networkStatusBlock = (
- {/*
*/} - {/*

Network status

*/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/**/} - {/*
Generator block:{this.props.core.generatorBlockHeight}
Local block:{this.props.core.blockHeight}
Replication lag:*/} - {/*{this.props.core.replicationLag === null ? '???' : this.props.core.replicationLag}*/} - {/*
*/} - {/*
*/} {requestStatusBlock}
- {testnetErr && } -
- ) - - let resetDataBlock = ( -
-
-

Reset data

- - {this.props.core.reset ? -
-

- This will permanently delete all data stored in this core, - including blockchain data, accounts, assets, indexes, - and MockHSM keys. -

- - {this.state.deleteError && } - - -
: -

- This core is not configured with reset capabilities. -

} -
) @@ -289,7 +148,6 @@ class CoreIndex extends React.Component { {configBlock} {networkStatusBlock}
- {/*{resetDataBlock}*/}
) @@ -299,16 +157,13 @@ class CoreIndex extends React.Component { const mapStateToProps = (state) => ({ core: state.core, navAdvancedState: state.app.navAdvancedState, - onTestnet: state.core.onTestnet, - testnetBlockchainMismatch: testnetUtils.isBlockchainMismatch(state), - testnetNetworkMismatch: testnetUtils.isCrosscoreRpcMismatch(state), - testnetNextReset: state.testnet.nextReset, }) const mapDispatchToProps = (dispatch) => ({ showNavAdvanced: () => dispatch(actions.app.showNavAdvanced), hideNavAdvanced: () => dispatch(actions.app.hideNavAdvanced), - uptdateBtmAmountUnit: (param) => dispatch(actions.core.updateBTMAmountUnit(param)) + uptdateBtmAmountUnit: (param) => dispatch(actions.core.updateBTMAmountUnit(param)), + updateMiningState: (param) => dispatch(actions.core.updateMiningState(param)) }) export default connect( diff --git a/src/features/core/components/CoreIndex/CoreIndex.scss b/src/features/core/components/CoreIndex/CoreIndex.scss index 901b1fb..8cb0bc3 100644 --- a/src/features/core/components/CoreIndex/CoreIndex.scss +++ b/src/features/core/components/CoreIndex/CoreIndex.scss @@ -12,6 +12,7 @@ .row_label { padding-right: $grid-gutter-width; + text-transform: capitalize; font-weight: bold; white-space: pre; } diff --git a/src/features/core/reducers.js b/src/features/core/reducers.js index fac2ef2..f7df2c8 100644 --- a/src/features/core/reducers.js +++ b/src/features/core/reducers.js @@ -229,6 +229,20 @@ const lang = (state = defaultLang, action) => { return state } +const mingStatus = (state = false, action) => { + if (action.type == 'UPDATE_CORE_INFO') { + return action.param.data.mining + } + return state +} + +const coreData = (state = null, action) => { + if (action.type == 'UPDATE_CORE_INFO') { + return action.param.data || null + } + return state +} + const snapshot = (state = null, action) => { if (action.type == 'UPDATE_CORE_INFO') { return action.param.snapshot || null // snapshot may be undefined, which Redux doesn't like. @@ -248,12 +262,14 @@ export default combineReducers({ configured, configuredAt, coreType, + coreData, generator, generatorAccessToken, generatorBlockHeight, generatorUrl, localhostAuth, mockhsm, + mingStatus, crosscoreRpcVersion, onTestnet, httpOk, diff --git a/src/sdk/api/config.js b/src/sdk/api/config.js index d35a95b..40d948f 100644 --- a/src/sdk/api/config.js +++ b/src/sdk/api/config.js @@ -12,6 +12,11 @@ const configAPI = (client) => { cb ), + mining: (miningState = false, cb) => shared.tryCallback( + client.request('/set-mining', {is_mining: miningState}), + cb + ), + info: (cb) => shared.tryCallback( client.request('/net-info'), cb