1 import { chainClient } from 'utility/environment'
2 import { connect } from 'react-redux'
3 import componentClassNames from 'utility/componentClassNames'
4 import { PageContent, ErrorBanner, PageTitle } from 'features/shared/components'
5 import React from 'react'
6 import styles from './CoreIndex.scss'
7 import testnetUtils from 'features/testnet/utils'
8 import { docsRoot } from 'utility/environment'
10 class CoreIndex extends React.Component {
14 this.deleteClick = this.deleteClick.bind(this)
18 if (!window.confirm('Are you sure you want to delete all data on this core?')) {
22 this.setState({deleteDisabled: true})
24 chainClient().config.reset(true).then(() => {
25 // TODO: Use Redux state reset and nav action instead of window.location.
26 // Also, move confirmation message to a bonafide flash div. alert() in a
27 // browser microtask is going away. cf https://www.chromestatus.com/features/5647113010544640
28 setTimeout(function(){
29 window.location.href = '/'
34 deleteDisabled: false,
42 testnetBlockchainMismatch,
43 testnetNetworkMismatch,
48 if (this.props.core.generator) {
49 generatorUrl = window.location.origin
50 } else if (onTestnet) {
52 {this.props.core.generatorUrl}
54 <span className='label label-primary'>Chain Testnet</span>
57 generatorUrl = this.props.core.generatorUrl
61 <div className={[styles.left, styles.col].join(' ')}>
63 <h4>Configuration</h4>
64 <table className={styles.table}>
67 <td className={styles.row_label}>Core type:</td>
68 <td>{this.props.core.coreType}</td>
71 <td className={styles.row_label}>Setup time:</td>
72 <td>{this.props.core.configuredAt}</td>
75 <td className={styles.row_label}>Version:</td>
76 <td><code>{this.props.core.version}</code></td>
79 <td className={styles.row_label}>MockHSM enabled:</td>
80 <td><code>{this.props.core.mockhsm.toString()}</code></td>
83 <td className={styles.row_label}>Localhost auth:</td>
84 <td><code>{this.props.core.localhostAuth.toString()}</code></td>
87 <td className={styles.row_label}>Reset enabled:</td>
88 <td><code>{this.props.core.reset.toString()}</code></td>
91 <td className={styles.row_label}>Non-TLS HTTP requests enabled:</td>
92 <td><code>{this.props.core.httpOk.toString()}</code></td>
95 <td colSpan={2}><hr /></td>
98 <td className={styles.row_label}>Generator URL:</td>
99 <td>{generatorUrl}</td>
101 {onTestnet && !!testnetNextReset &&
103 <td className={styles.row_label}>Next Chain Testnet data reset:</td>
104 <td>{testnetNextReset.toString()}</td>
106 {!this.props.core.generator &&
108 <td className={styles.row_label}>Generator Access Token:</td>
109 <td><code>{this.props.core.generatorAccessToken}</code></td>
112 <td className={styles.row_label}>Blockchain ID:</td>
113 <td><code className={styles.block_hash}>{this.props.core.blockchainId}</code></td>
123 if (testnetBlockchainMismatch) {
124 testnetErr = 'Chain Testnet has been reset. Please reset your core below.'
125 } else if (testnetNetworkMismatch) {
126 testnetErr = {message: <span>This core is no longer compatible with Chain Testnet. <a href={`${docsRoot}/core/get-started/install`} target='_blank'>Please upgrade Chain Core</a>.</span>}
130 let networkStatusBlock = (
131 <div className={[styles.right, styles.col].join(' ')}>
133 <h4>Network status</h4>
135 <table className={styles.table}>
138 <td className={styles.row_label}>Generator block:</td>
139 <td className={styles.row_value}>{this.props.core.generatorBlockHeight}</td>
142 <td className={styles.row_label}>Local block:</td>
143 <td className={styles.row_value}>{this.props.core.blockHeight}</td>
146 <td className={styles.row_label}>Replication lag:</td>
147 <td className={`${styles.replication_lag} ${styles[this.props.core.replicationLagClass]}`}>
148 {this.props.core.replicationLag === null ? '???' : this.props.core.replicationLag}
154 {testnetErr && <ErrorBanner title='Chain Testnet error' error={testnetErr} />}
159 let resetDataBlock = (
160 <div className='row'>
161 <div className='col-sm-6'>
164 {this.props.core.reset ?
167 This will permanently delete all data stored in this core,
168 including blockchain data, accounts, assets, indexes,
172 {this.state.deleteError && <ErrorBanner
173 title='Error resetting data'
174 message={this.state.deleteError.toString()}
178 className='btn btn-danger'
179 onClick={this.deleteClick}
180 disabled={this.state.deleteDisabled}
186 This core is not configured with reset capabilities.
193 <div className={componentClassNames(this, 'flex-container', styles.mainContainer)}>
194 <PageTitle title='Core' />
197 <div className={`${styles.top} ${styles.flex}`}>
209 const mapStateToProps = (state) => ({
211 onTestnet: state.core.onTestnet,
212 testnetBlockchainMismatch: testnetUtils.isBlockchainMismatch(state),
213 testnetNetworkMismatch: testnetUtils.isCrosscoreRpcMismatch(state),
214 testnetNextReset: state.testnet.nextReset,
217 const mapDispatchToProps = () => ({})
219 export default connect(