From 65cf4fb781cb62ade1cb1a99c0fa4be62f1df226 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 2 Sep 2017 23:15:28 +0300 Subject: [PATCH] moved coin progress prop from dashboard to activeCoin reducer --- .../components/addcoin/addcoinOptionsAC.js | 1 + .../coindDownModal/coindDownModal.js | 4 + .../coindDownModal/coindDownModal.render.js | 2 +- .../dashboard/loginModal/loginModal.render.js | 2 +- .../dashboard/syncOnly/syncOnly.render.js | 4 +- .../walletsBalance/walletsBalance.js | 22 ++--- .../dashboard/walletsData/walletsData.js | 16 ++-- .../dashboard/walletsInfo/walletsInfo.js | 8 +- .../walletsInfo/walletsInfo.render.js | 38 ++++----- .../walletsProgress/walletsProgress.js | 81 ++++++++++--------- .../walletsProgress/walletsProgress.render.js | 26 +++--- .../components/login/swall-modal.render.js | 2 +- react/src/reducers/activeCoin.js | 24 ++++++ 13 files changed, 135 insertions(+), 95 deletions(-) diff --git a/react/src/components/addcoin/addcoinOptionsAC.js b/react/src/components/addcoin/addcoinOptionsAC.js index e5bd59a..81377db 100644 --- a/react/src/components/addcoin/addcoinOptionsAC.js +++ b/react/src/components/addcoin/addcoinOptionsAC.js @@ -19,6 +19,7 @@ class AddCoinOptionsAC extends React.Component { 'revs', 'shark', 'supernet', + 'wlc' ]; let _items = []; diff --git a/react/src/components/dashboard/coindDownModal/coindDownModal.js b/react/src/components/dashboard/coindDownModal/coindDownModal.js index a605a06..f468156 100644 --- a/react/src/components/dashboard/coindDownModal/coindDownModal.js +++ b/react/src/components/dashboard/coindDownModal/coindDownModal.js @@ -37,6 +37,10 @@ class CoindDownModal extends React.Component { } const mapStateToProps = (state) => { return { + ActiveCoin: { + mode: state.ActiveCoin.mode, + coin: state.ActiveCoin.coin, + }, displayCoindDownModal: state.Dashboard.displayCoindDownModal, debugLog: state.Settings.debugLog, }; diff --git a/react/src/components/dashboard/coindDownModal/coindDownModal.render.js b/react/src/components/dashboard/coindDownModal/coindDownModal.render.js index 7aad606..4b22596 100644 --- a/react/src/components/dashboard/coindDownModal/coindDownModal.render.js +++ b/react/src/components/dashboard/coindDownModal/coindDownModal.render.js @@ -1,7 +1,7 @@ import React from 'react'; import { translate } from '../../../translate/translate'; -const CoindDownModalRender = function () { +const CoindDownModalRender = function() { return (
@@ -46,7 +46,7 @@ export const ProgressRender = function (fork) { ); }; -export const ForkItemRender = function (forkInfo, port) { +export const ForkItemRender = function(forkInfo, port) { return (
{ balance: state.ActiveCoin.balance, cache: state.ActiveCoin.cache, activeSection: state.ActiveCoin.activeSection, - activeAddress: state.ActiveCoin.activeAddress + activeAddress: state.ActiveCoin.activeAddress, + progress: state.ActiveCoin.progress, }, Dashboard: { - progress: state.Dashboard.progress, activeHandle: state.Dashboard.activeHandle, }, }; diff --git a/react/src/components/dashboard/walletsData/walletsData.js b/react/src/components/dashboard/walletsData/walletsData.js index 34c0b53..56463f3 100644 --- a/react/src/components/dashboard/walletsData/walletsData.js +++ b/react/src/components/dashboard/walletsData/walletsData.js @@ -365,11 +365,13 @@ class WalletsData extends React.Component { } isFullySynced() { - if (this.props.Dashboard.progress && - (Number(this.props.Dashboard.progress.balances) + - Number(this.props.Dashboard.progress.validated) + - Number(this.props.Dashboard.progress.bundles) + - Number(this.props.Dashboard.progress.utxo)) / 4 === 100) { + const _progress = this.props.ActiveCoin.progress; + + if (_progress && + (Number(_progress.balances) + + Number(_progress.validated) + + Number(_progress.bundles) + + Number(_progress.utxo)) / 4 === 100) { return true; } else { return false; @@ -644,15 +646,15 @@ const mapStateToProps = (state) => { addresses: state.ActiveCoin.addresses, txhistory: state.ActiveCoin.txhistory, showTransactionInfo: state.ActiveCoin.showTransactionInfo, + progress: state.ActiveCoin.progress, }, Dashboard: { activeHandle: state.Dashboard.activeHandle, displayViewCacheModal: state.Dashboard.displayViewCacheModal, - progress: state.Dashboard.progress, }, Main: { coins: state.Main.coins, - } + }, }; }; diff --git a/react/src/components/dashboard/walletsInfo/walletsInfo.js b/react/src/components/dashboard/walletsInfo/walletsInfo.js index 3f4444c..1b43678 100644 --- a/react/src/components/dashboard/walletsInfo/walletsInfo.js +++ b/react/src/components/dashboard/walletsInfo/walletsInfo.js @@ -16,8 +16,8 @@ class WalletsInfo extends React.Component { render() { if (this.props && - this.props.Dashboard && - this.props.Dashboard.progress && + this.props.ActiveCoin && + this.props.ActiveCoin.progress && this.props.ActiveCoin.activeSection === 'settings') { return WalletsNativeInfoRender.call(this); } @@ -31,9 +31,7 @@ const mapStateToProps = (state) => { ActiveCoin: { coin: state.ActiveCoin.coin, activeSection: state.ActiveCoin.activeSection, - }, - Dashboard: { - progress: state.Dashboard.progress, + progress: state.ActiveCoin.progress, }, }; }; diff --git a/react/src/components/dashboard/walletsInfo/walletsInfo.render.js b/react/src/components/dashboard/walletsInfo/walletsInfo.render.js index 972da9d..9ba0cb4 100644 --- a/react/src/components/dashboard/walletsInfo/walletsInfo.render.js +++ b/react/src/components/dashboard/walletsInfo/walletsInfo.render.js @@ -3,6 +3,8 @@ import { translate } from '../../../translate/translate'; import ClaimInterestModal from '../claimInterestModal/claimInterestModal'; const WalletsInfoRender = function() { + const _progress = this.props.ActiveCoin.progress; + return (
@@ -16,13 +18,13 @@ const WalletsInfoRender = function() { { translate('INDEX.WALLET_VERSION') } - { this.props.Dashboard.progress.walletversion } + { _progress.walletversion } { translate('INDEX.BALANCE') } - { this.props.Dashboard.progress.balance } + { _progress.balance } @@ -65,19 +67,19 @@ const WalletsInfoRender = function() { { translate('INDEX.VERSION') } - { this.props.Dashboard.progress.KMDversion } + { _progress.KMDversion } { translate('INDEX.PROTOCOL_VERSION') } - { this.props.Dashboard.progress.protocolversion } + { _progress.protocolversion } { translate('INDEX.NOTARIZED') } - { this.props.Dashboard.progress.notarized } + { _progress.notarized } @@ -85,15 +87,15 @@ const WalletsInfoRender = function() { { translate('INDEX.NOTARIZED') } { translate('INDEX.HASH') } - { this.props.Dashboard.progress.notarizedhash ? - this.props.Dashboard.progress.notarizedhash.substring( + { _progress.notarizedhash ? + _progress.notarizedhash.substring( 0, - Math.floor(this.props.Dashboard.progress.notarizedhash.length / 2) + Math.floor(_progress.notarizedhash.length / 2) ) + '\t' + - this.props.Dashboard.progress.notarizedhash.substring( - Math.floor(this.props.Dashboard.progress.notarizedhash.length / 2), - this.props.Dashboard.progress.notarizedhash.length + _progress.notarizedhash.substring( + Math.floor(_progress.notarizedhash.length / 2), + _progress.notarizedhash.length ) : '' } @@ -108,43 +110,43 @@ const WalletsInfoRender = function() { { translate('INDEX.BLOCKS') } - { this.props.Dashboard.progress.blocks } + { _progress.blocks } { translate('INDEX.CONNECTIONS') } - { this.props.Dashboard.progress.connections } + { _progress.connections } { translate('INDEX.DIFFICULTY') } - { this.props.Dashboard.progress.difficulty } + { _progress.difficulty } Testnet - { this.props.Dashboard.progress.testnet } + { _progress.testnet } { translate('INDEX.PAY_TX_FEE') } - { this.props.Dashboard.progress.paytxfee } + { _progress.paytxfee } { translate('INDEX.RELAY_FEE') } - { this.props.Dashboard.progress.relayfee } + { _progress.relayfee } { translate('INDEX.ERRORS') } - { this.props.Dashboard.progress.errors } + { _progress.errors } diff --git a/react/src/components/dashboard/walletsProgress/walletsProgress.js b/react/src/components/dashboard/walletsProgress/walletsProgress.js index fbdbc60..b70c776 100644 --- a/react/src/components/dashboard/walletsProgress/walletsProgress.js +++ b/react/src/components/dashboard/walletsProgress/walletsProgress.js @@ -19,10 +19,12 @@ class WalletsProgress extends React.Component { } isFullySynced() { - if ((Number(this.props.Dashboard.progress.balances) + - Number(this.props.Dashboard.progress.validated) + - Number(this.props.Dashboard.progress.bundles) + - Number(this.props.Dashboard.progress.utxo)) / 4 === 100) { + const _progress = this.props.ActiveCoin.progress; + + if ((Number(_progress.balances) + + Number(_progress.validated) + + Number(_progress.bundles) + + Number(_progress.utxo)) / 4 === 100) { return true; } else { return false; @@ -38,9 +40,11 @@ class WalletsProgress extends React.Component { } renderChainActivationNotification() { - if (this.props.Dashboard.progress) { - if ((!this.props.Dashboard.progress.blocks && !this.props.Dashboard.progress.longestchain) || - (this.props.Dashboard.progress.blocks < this.props.Dashboard.progress.longestchain)) { + const _progress = this.props.ActiveCoin.progress; + + if (_progress) { + if ((!_progress.blocks && !_progress.longestchain) || + (_progress.blocks < _progress.longestchain)) { return ChainActivationNotificationRender.call(this); } } else { @@ -86,35 +90,37 @@ class WalletsProgress extends React.Component { } renderSyncPercentagePlaceholder() { + const _progress = this.props.ActiveCoin.progress; + // activating best chain - if (this.props.Dashboard.progress && - this.props.Dashboard.progress.code && - this.props.Dashboard.progress.code === -28 && + if (_progress && + _progress.code && + _progress.code === -28 && this.props.Settings.debugLog) { - const _progress = this.parseActivatingBestChainProgress(); + const _parseProgress = this.parseActivatingBestChainProgress(); - if (_progress && - _progress[1]) { - return SyncPercentageRender.call(this, _progress[1] === 1000 ? 100 : _progress[1].toFixed(2)); + if (_parseProgress && + _parseProgress[1]) { + return SyncPercentageRender.call(this, _parseProgress[1] === 1000 ? 100 : _parseProgress[1].toFixed(2)); } else { return LoadingBlocksRender.call(this); } } - if (this.props.Dashboard.progress && - this.props.Dashboard.progress.blocks > 0 && - this.props.Dashboard.progress.longestchain === 0) { + if (_progress && + _progress.blocks > 0 && + _progress.longestchain === 0) { return SyncErrorLongestChainRender.call(this); } - if (this.props.Dashboard.progress && - this.props.Dashboard.progress.blocks === 0) { + if (_progress && + _progress.blocks === 0) { return SyncErrorBlocksRender.call(this); } - if (this.props.Dashboard.progress && - this.props.Dashboard.progress.blocks) { - const syncPercentage = (parseFloat(parseInt(this.props.Dashboard.progress.blocks, 10) * 100 / parseInt(this.props.Dashboard.progress.longestchain, 10)).toFixed(2) + '%').replace('NaN', 0); + if (_progress && + _progress.blocks) { + const syncPercentage = (parseFloat(parseInt(_progress.blocks, 10) * 100 / parseInt(_progress.longestchain, 10)).toFixed(2) + '%').replace('NaN', 0); return SyncPercentageRender.call(this, syncPercentage === 1000 ? 100 : syncPercentage); } @@ -129,8 +135,8 @@ class WalletsProgress extends React.Component { if (this.props.Settings && this.props.Settings.debugLog) { if (this.props.Settings.debugLog.indexOf('UpdateTip') > -1 && - !this.props.Dashboard.progress && - !this.props.Dashboard.progress.blocks) { + !this.props.ActiveCoin.progress && + !this.props.ActiveCoin.progress.blocks) { const temp = this.props.Settings.debugLog.split(' '); let currentBestChain; let currentProgress; @@ -145,23 +151,23 @@ class WalletsProgress extends React.Component { } // fallback to local data if remote node is inaccessible - if (this.props.Dashboard.progress.remoteKMDNode && - !this.props.Dashboard.progress.remoteKMDNode.blocks) { + if (this.props.ActiveCoin.progress.remoteKMDNode && + !this.props.ActiveCoin.progress.remoteKMDNode.blocks) { return ( `: ${currentProgress}% (${ translate('INDEX.ACTIVATING_SM') })` ); } else { - if (this.props.Dashboard.progress.remoteKMDNode && - this.props.Dashboard.progress.remoteKMDNode.blocks) { + if (this.props.ActiveCoin.progress.remoteKMDNode && + this.props.ActiveCoin.progress.remoteKMDNode.blocks) { return( - `: ${Math.floor(currentBestChain * 100 / this.props.Dashboard.progress.remoteKMDNode.blocks)}% (${ translate('INDEX.BLOCKS_SM') } ${currentBestChain} / ${this.props.Dashboard.progress.remoteKMDNode.blocks})` + `: ${Math.floor(currentBestChain * 100 / this.props.ActiveCoin.progress.remoteKMDNode.blocks)}% (${ translate('INDEX.BLOCKS_SM') } ${currentBestChain} / ${this.props.ActiveCoin.progress.remoteKMDNode.blocks})` ); } } } else if ( this.props.Settings.debugLog.indexOf('Still rescanning') > -1 && - !this.props.Dashboard.progress || - !this.props.Dashboard.progress.blocks + !this.props.ActiveCoin.progress || + !this.props.ActiveCoin.progress.blocks ) { const temp = this.props.Settings.debugLog.split(' '); let currentProgress; @@ -173,9 +179,9 @@ class WalletsProgress extends React.Component { } // activating best chain - if (this.props.Dashboard.progress && - this.props.Dashboard.progress.code && - this.props.Dashboard.progress.code === -28 && + if (this.props.ActiveCoin.progress && + this.props.ActiveCoin.progress.code && + this.props.ActiveCoin.progress.code === -28 && this.props.Settings.debugLog) { const _blocks = this.parseActivatingBestChainProgress(); @@ -219,8 +225,8 @@ class WalletsProgress extends React.Component { if (this.props && this.props.ActiveCoin && (this.isFullMode() || this.isNativeMode())) { - if (this.props.Dashboard.progress && - this.props.Dashboard.progress.error) { + if (this.props.ActiveCoin.progress && + this.props.ActiveCoin.progress.error) { return CoinIsBusyRender.call(this); } @@ -238,7 +244,8 @@ const mapStateToProps = (state) => { }, ActiveCoin: { mode: state.ActiveCoin.mode, - coin: state.coin, + coin: state.ActiveCoin.coin, + progress: state.ActiveCoin.progress, }, }; }; diff --git a/react/src/components/dashboard/walletsProgress/walletsProgress.render.js b/react/src/components/dashboard/walletsProgress/walletsProgress.render.js index 0305aa1..d1b19cc 100644 --- a/react/src/components/dashboard/walletsProgress/walletsProgress.render.js +++ b/react/src/components/dashboard/walletsProgress/walletsProgress.render.js @@ -22,7 +22,7 @@ export const SyncPercentageRender = function(syncPercentage) {
- { syncPercentage } | { this.props.Dashboard.progress.blocks } / { this.props.Dashboard.progress.longestchain } | { translate('INDEX.CONNECTIONS') }: { this.props.Dashboard.progress.connections } + { syncPercentage } | { this.props.ActiveCoin.progress.blocks } / { this.props.ActiveCoin.progress.longestchain } | { translate('INDEX.CONNECTIONS') }: { this.props.ActiveCoin.progress.connections }
); }; @@ -77,22 +77,22 @@ export const WalletsProgressRender = function() { id="edex-footer" className="margin-bottom-20"> { !this.isNativeMode() && - this.props.Dashboard.progress && + this.props.ActiveCoin.progress &&
{ translate('INDEX.BUNDLES') }  - ({ this.props.ActiveCoin.coin }) 100.00% - ( { this.props.Dashboard.progress.blocks } - / { this.props.Dashboard.progress.blocks } ) ==>> - RT{ this.props.Dashboard.progress.RTheight } + ({ this.props.ActiveCoin.coin }) 100.00% - ( { this.props.ActiveCoin.progress.blocks } + / { this.props.ActiveCoin.progress.blocks } ) ==>> + RT{ this.props.ActiveCoin.progress.RTheight }
- { translate('INDEX.BUNDLES') } { this.props.Dashboard.progress.bundles }% + style={{ width: `${this.props.ActiveCoin.progress.bundles}%` }}> + { translate('INDEX.BUNDLES') } { this.props.ActiveCoin.progress.bundles }%
@@ -100,22 +100,22 @@ export const WalletsProgressRender = function() {
- utxo { this.props.Dashboard.progress.utxo }% + style={{ width: `${this.props.ActiveCoin.progress.utxo}%` }}> + utxo { this.props.ActiveCoin.progress.utxo }%
- { translate('INDEX.BALANCES') } { this.props.Dashboard.progress.balances }% + style={{ width: `${this.props.ActiveCoin.progress.balances}%` }}> + { translate('INDEX.BALANCES') } { this.props.ActiveCoin.progress.balances }%
- { translate('INDEX.VALIDATED') } { this.props.Dashboard.progress.validated }% + style={{ width: `${this.props.ActiveCoin.progress.validated}%` }}> + { translate('INDEX.VALIDATED') } { this.props.ActiveCoin.progress.validated }%
diff --git a/react/src/components/login/swall-modal.render.js b/react/src/components/login/swall-modal.render.js index 9f5a7b1..27e47b8 100644 --- a/react/src/components/login/swall-modal.render.js +++ b/react/src/components/login/swall-modal.render.js @@ -1,7 +1,7 @@ import React from 'react'; import { translate } from '../../translate/translate'; -const SwallModalRender = function () { +const SwallModalRender = function() { return (
diff --git a/react/src/reducers/activeCoin.js b/react/src/reducers/activeCoin.js index e4914d4..2ae0551 100644 --- a/react/src/reducers/activeCoin.js +++ b/react/src/reducers/activeCoin.js @@ -14,6 +14,9 @@ import { DASHBOARD_ACTIVE_COIN_GET_CACHE, DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR, DASHBOARD_ACTIVE_ADDRESS, + SYNCING_FULL_MODE, + SYNCING_NATIVE_MODE, + DASHBOARD_UPDATE, } from '../actions/storeType'; // TODO: refactor @@ -34,6 +37,7 @@ export function ActiveCoin(state = { cache: null, mainBasiliskAddress: null, activeAddress: null, + progress: null, }, action) { switch (action.type) { case DASHBOARD_ACTIVE_COIN_CHANGE: @@ -54,6 +58,7 @@ export function ActiveCoin(state = { mainBasiliskAddress: state.mainBasiliskAddress, opids: state.opids, activeBasiliskAddress: state.activeBasiliskAddress, + progress: state.progress, }; let _coins = state.coins; _coins[state.coin] = _coinDataToStore; @@ -74,6 +79,7 @@ export function ActiveCoin(state = { mainBasiliskAddress: _coinData.mainBasiliskAddress, opids: _coinData.opids, activeBasiliskAddress: _coinData.activeBasiliskAddress, + progress: _coinData.progress, }); } else { if (state.coin) { @@ -92,6 +98,7 @@ export function ActiveCoin(state = { mainBasiliskAddress: state.mainBasiliskAddress, opids: state.opids, activeBasiliskAddress: state.activeBasiliskAddress, + progress: state.progress, }; let _coins = state.coins; _coins[state.coin] = _coinData; @@ -107,6 +114,7 @@ export function ActiveCoin(state = { showTransactionInfo: false, showTransactionInfoTxIndex: null, activeSection: 'default', + progress: null, }); } else { return Object.assign({}, state, { @@ -119,6 +127,7 @@ export function ActiveCoin(state = { showTransactionInfo: false, showTransactionInfoTxIndex: null, activeSection: 'default', + progress: null, }); } } @@ -182,6 +191,21 @@ export function ActiveCoin(state = { return Object.assign({}, state, { activeAddress: action.address, }); + case SYNCING_FULL_MODE: + return Object.assign({}, state, { + progress: action.progress, + }); + case SYNCING_NATIVE_MODE: + return Object.assign({}, state, { + progress: action.progress, + }); + case DASHBOARD_UPDATE: + return Object.assign({}, state, { + progress: action.progress, + opids: action.opids, + txhistory: action.txhistory, + balance: action.balance, + }); default: return state; }