import React from 'react'; import { translate } from '../../../translate/translate'; import { connect } from 'react-redux'; import Config from '../../../config'; import { getPeersList, checkForUpdateUIPromise, updateUIPromise, } from '../../../actions/actionCreators'; import { SocketProvider } from 'socket.io-react'; import io from 'socket.io-client'; const socket = io.connect(`http://127.0.0.1:${Config.agamaPort}`); let updateProgressBar = { patch: -1, }; class AppUpdatePanel extends React.Component { constructor() { super(); this.state = { updatePatch: null, updateLog: [], updateProgressPatch: null, updatePatch: null, updateBins: null, }; this._checkForUpdateUIPromise = this._checkForUpdateUIPromise.bind(this); this._updateUIPromise = this._updateUIPromise.bind(this); this.checkNodes = this.checkNodes.bind(this); } componentWillMount() { socket.on('patch', msg => this.updateSocketsData = (msg) => {}); } componentWillUnmount() { socket.removeAllListeners('patch', msg => this.updateSocketsData(msg)); } checkNodes() { if (this.state.getPeersCoin) { Store.dispatch(getPeersList(this.state.getPeersCoin.split('|')[0])); } } _updateUIPromise() { updateProgressBar.patch = 0; let _updateLog = []; _updateLog.push(`${translate('INDEX.DOWNLOADING_UI_UPDATE')}...`); this.setState(Object.assign({}, this.state, { updateLog: _updateLog, })); updateUIPromise(); } _checkForUpdateUIPromise() { let _updateLog = []; _updateLog.push(translate('INDEX.CHECKING_UI_UPDATE')); this.setState(Object.assign({}, this.state, { updateLog: _updateLog, })); checkForUpdateUIPromise() .then((res) => { let _updateLog = this.state.updateLog; _updateLog.push(res.result === 'update' ? (`${translate('INDEX.NEW_UI_UPDATE')} ${res.version.remote}`) : translate('INDEX.YOU_HAVE_LATEST_UI')); this.setState(Object.assign({}, this.state, { updatePatch: res.result === 'update' ? true : false, updateLog: _updateLog, })); }); } renderUpdateStatus() { let items = []; let patchProgressBar = null; const _updateLogLength = this.state.updateLog.length; for (let i = 0; i < _updateLogLength; i++) { items.push(
{ this.state.updateLog[i] }
); } if (_updateLogLength) { return (

{ translate('SETTINGS.PROGRESS') }:
{ items }
-1 ? 'progress progress-sm' : 'hide' }>
); } else { return null; } } render() { return (
{ translate('INDEX.UI_UPDATE') }
{ translate('INDEX.BINS_UPDATE') }
{ this.renderUpdateStatus() }
); }; } const mapStateToProps = (state) => { return { Settings: state.Settings, }; }; export default connect(mapStateToProps)(AppUpdatePanel);