From 317840d299c4041cb7d1c49f1d7d62209fb40a78 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 15 Oct 2017 01:40:56 +0300 Subject: [PATCH] kmd main win maxconnections workaround --- .../dashboard/settings/settings.panelUtils.js | 8 +- .../dashboard/walletsData/walletsData.js | 2 + .../walletsProgress/walletsProgress.js | 121 ++++++++++++++++-- .../walletsProgress/walletsProgress.render.js | 32 ++++- react/src/components/overrides.scss | 4 + 5 files changed, 148 insertions(+), 19 deletions(-) diff --git a/react/src/components/dashboard/settings/settings.panelUtils.js b/react/src/components/dashboard/settings/settings.panelUtils.js index e07614f..325bfb8 100644 --- a/react/src/components/dashboard/settings/settings.panelUtils.js +++ b/react/src/components/dashboard/settings/settings.panelUtils.js @@ -33,10 +33,14 @@ export function setupAccordion(info) { if (!singleChild) { info.kids.forEach((child, i) => { const { openByDefault } = child ? child.props : false; - if (singleOpen && activeSections.length === 0 && openByDefault) { + + if (singleOpen && + activeSections.length === 0 && + openByDefault) { activeSections.push(`panel-sec-${i}`); } - if (!singleOpen && openByDefault) { + if (!singleOpen && + openByDefault) { activeSections.push(`panel-sec-${i}`); } }); diff --git a/react/src/components/dashboard/walletsData/walletsData.js b/react/src/components/dashboard/walletsData/walletsData.js index 1bb942e..036daaf 100644 --- a/react/src/components/dashboard/walletsData/walletsData.js +++ b/react/src/components/dashboard/walletsData/walletsData.js @@ -85,6 +85,8 @@ class WalletsData extends React.Component { displayClaimInterestUI() { if (this.props.ActiveCoin && + this.props.ActiveCoin.coin === 'KMD' && + this.props.ActiveCoin.mode === 'native' && this.props.ActiveCoin.balance && this.props.ActiveCoin.balance.interest && this.props.ActiveCoin.balance.interest > 0) { diff --git a/react/src/components/dashboard/walletsProgress/walletsProgress.js b/react/src/components/dashboard/walletsProgress/walletsProgress.js index ccbbe82..dcee90f 100644 --- a/react/src/components/dashboard/walletsProgress/walletsProgress.js +++ b/react/src/components/dashboard/walletsProgress/walletsProgress.js @@ -1,6 +1,10 @@ import React from 'react'; import { connect } from 'react-redux'; import { translate } from '../../../translate/translate'; +import { + triggerToaster, +} from '../../../actions/actionCreators'; +import Store from '../../../store'; import { SyncErrorBlocksRender, SyncPercentageRender, @@ -8,7 +12,7 @@ import { TranslationComponentsRender, ChainActivationNotificationRender, VerifyingBlocksRender, - WalletsProgressRender + WalletsProgressRender, } from './walletsProgress.render'; class WalletsProgress extends React.Component { @@ -16,8 +20,71 @@ class WalletsProgress extends React.Component { super(); this.state = { prevProgress: {}, + isWindows: false, + isWindowsWorkaroundEnabled: false, }; - this.isFullySynced = this.isFullySynced.bind(this); + this.isWinSyncPercBelowThreshold = this.isWinSyncPercBelowThreshold.bind(this); + this.applyWindowsSyncWorkaround = this.applyWindowsSyncWorkaround.bind(this); + } + + componentWillMount() { + const _mainWindow = window.require('electron').remote.getCurrentWindow(); + let _isWindows; + + try { + _isWindows = _mainWindow.isWindows; + } catch (e) {} + + if (_isWindows) { + _mainWindow.getMaxconKMDConf() + .then((res) => { + if (!res || + Number(res) !== 1) { + this.setState({ + isWindowsWorkaroundEnabled: false, + isWindows: _isWindows, + }); + } else { + this.setState({ + isWindowsWorkaroundEnabled: true, + isWindows: _isWindows, + }); + } + }); + } + } + + applyWindowsSyncWorkaround() { + const _mainWindow = window.require('electron').remote.getCurrentWindow(); + + _mainWindow.setMaxconKMDConf(1) + .then((res) => { + if (res) { + this.setState({ + isWindowsWorkaroundEnabled: true, + }); + + Store.dispatch( + triggerToaster( + 'Windows sync workaround is applied. Closing the app...', + translate('TOASTR.WALLET_NOTIFICATION'), + 'success' + ) + ); + + setTimeout(() => { + _mainWindow.appExit(); + }, 2000); + } else { + Store.dispatch( + triggerToaster( + 'Unable to apply Windows sync workaround', + translate('TOASTR.WALLET_NOTIFICATION'), + 'error' + ) + ); + } + }); } componentWillReceiveProps(props) { @@ -31,6 +98,7 @@ class WalletsProgress extends React.Component { Number(this.state.prevProgress.longestchain) > 0) { _progress.longestchain = this.state.prevProgress.longestchain; } + this.setState(Object.assign({}, this.state, { prevProgress: _progress, })); @@ -39,18 +107,49 @@ class WalletsProgress extends React.Component { prevProgress: props.ActiveCoin.progress, })); } - } - isFullySynced() { - const _progress = this.props.ActiveCoin.progress; + if (this.isWinSyncPercBelowThreshold() !== -777 && + this.state.isWindowsWorkaroundEnabled && + !this.isWinSyncPercBelowThreshold()) { + const _mainWindow = window.require('electron').remote.getCurrentWindow(); + + _mainWindow.setMaxconKMDConf() + .then((res) => { + if (res) { + this.setState({ + isWindowsWorkaroundEnabled: false, + }); + + Store.dispatch( + triggerToaster( + 'Current sync state reached 80% level. Windows sync workaround is disabled. Changes will be applied next time you start the app.', + translate('TOASTR.WALLET_NOTIFICATION'), + 'info', + false + ) + ); + } else { + Store.dispatch( + triggerToaster( + 'Unable to apply Windows sync workaround', + translate('TOASTR.WALLET_NOTIFICATION'), + 'error' + ) + ); + } + }); + } + } - if ((Number(_progress.balances) + - Number(_progress.validated) + - Number(_progress.bundles) + - Number(_progress.utxo)) / 4 === 100) { - return true; + isWinSyncPercBelowThreshold() { + if (this.state.prevProgress && + this.state.prevProgress.longestchain && + this.state.prevProgress.blocks) { + if (Number(this.state.prevProgress.blocks) * 100 / Number(this.state.prevProgress.longestchain) < 80) { + return true; + } } else { - return false; + return -777; } } diff --git a/react/src/components/dashboard/walletsProgress/walletsProgress.render.js b/react/src/components/dashboard/walletsProgress/walletsProgress.render.js index 0b46f5d..ae34f8e 100644 --- a/react/src/components/dashboard/walletsProgress/walletsProgress.render.js +++ b/react/src/components/dashboard/walletsProgress/walletsProgress.render.js @@ -98,12 +98,32 @@ export const TranslationComponentsRender = function(translationID) { export const ChainActivationNotificationRender = function() { if (this.props.ActiveCoin.coin !== 'CHIPS') { return ( -
-

- { translate('INDEX.ACTIVATING_CHAIN') }  - { this.props.ActiveCoin.rescanInProgress ? (this.renderRescanProgress() ? `: ${this.renderRescanProgress().toFixed(2)}% ${translate('INDEX.PROGRESS_RESCANNING_BLOCKS')}` : translate('INDEX.PROGRESS_RESCANNING_BLOCKS')) : this.renderActivatingBestChainProgress() } -

-

{ this.renderLB('INDEX.KMD_STARTED') }

+
+
+

+ { translate('INDEX.ACTIVATING_CHAIN') }  + { this.props.ActiveCoin.rescanInProgress ? (this.renderRescanProgress() ? `: ${this.renderRescanProgress().toFixed(2)}% ${translate('INDEX.PROGRESS_RESCANNING_BLOCKS')}` : translate('INDEX.PROGRESS_RESCANNING_BLOCKS')) : this.renderActivatingBestChainProgress() } +

+

{ this.renderLB('INDEX.KMD_STARTED') }

+
+ { this.state.isWindows && + !this.state.isWindowsWorkaroundEnabled && + this.isWinSyncPercBelowThreshold() && + this.props.ActiveCoin && + this.props.ActiveCoin.mode === 'native' && + this.props.ActiveCoin.coin === 'KMD' && +
+

Slow sync speed on Windows? Try this workaround.

+

It will add maxconnections=1 in komodo.conf file and force close the app.

+

Please run the app again after that.

+ +
+ }
); } else { diff --git a/react/src/components/overrides.scss b/react/src/components/overrides.scss index bdccfc5..29f52e9 100644 --- a/react/src/components/overrides.scss +++ b/react/src/components/overrides.scss @@ -468,4 +468,8 @@ select{ .dashboard-claim-interest-btn { padding: 4px 14px 4px 7px; margin-left: 20px; +} + +.win-sync-workaround-btn { + padding: 4px 7px; } \ No newline at end of file