From 27f05218224c5c808c555ea55ada405f0266fe97 Mon Sep 17 00:00:00 2001 From: pbca26 <pbca26@gmail.com> Date: Fri, 4 Aug 2017 00:00:54 +0300 Subject: [PATCH] skip tx history re-render if data is the same --- .../dashboard/coinTile/coinTileItem.js | 19 ++--------- .../dashboard/walletsData/walletsData.js | 34 +++++++++++++++---- .../walletsProgress/walletsProgress.js | 4 +-- .../walletsTxInfo/walletsTxInfo.render.js | 3 -- react/src/util/sort.js | 7 ++-- 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/react/src/components/dashboard/coinTile/coinTileItem.js b/react/src/components/dashboard/coinTile/coinTileItem.js index cbf910b..bbf6c0b 100644 --- a/react/src/components/dashboard/coinTile/coinTileItem.js +++ b/react/src/components/dashboard/coinTile/coinTileItem.js @@ -25,10 +25,9 @@ import Config from '../../../config'; import CoinTileItemRender from './coinTileItem.render'; const BASILISK_CACHE_UPDATE_TIMEOUT = 240000; -const IGUNA_ACTIVE_HANDLE_TIMEOUT = 30000; -const IGUNA_ACTIVE_HANDLE_TIMEOUT_KMD_NATIVE = 30000; +const IGUNA_ACTIVE_HANDLE_TIMEOUT = 3000; +const IGUNA_ACTIVE_HANDLE_TIMEOUT_KMD_NATIVE = 15000; const NATIVE_MIN_SYNC_PERCENTAGE_THRESHOLD = 90; -let coinInitDataFetchInterval; class CoinTileItem extends React.Component { constructor(props) { @@ -108,20 +107,6 @@ class CoinTileItem extends React.Component { dashboardChangeActiveCoin(coin, mode) { if (coin !== this.props.ActiveCoin.coin) { - if (!this.props.ActiveCoin.coins[this.props.ActiveCoin.coin]) { - coinInitDataFetchInterval = setInterval(() => { - this.dispatchCoinActions(coin, mode); - - if ((mode === 'native' || mode === 'full') && this.props.Dashboard.progress) { - clearInterval(coinInitDataFetchInterval); - } - - if (mode === 'basilisk' && (this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory !== 'loading') && this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin] && JSON.parse(sessionStorage.getItem('IguanaActiveAccount'))[this.props.ActiveCoin.coin]) { - clearInterval(coinInitDataFetchInterval); - } - }, 500); - } - Store.dispatch( stopInterval( 'sync', diff --git a/react/src/components/dashboard/walletsData/walletsData.js b/react/src/components/dashboard/walletsData/walletsData.js index 74bdbb4..6919c08 100644 --- a/react/src/components/dashboard/walletsData/walletsData.js +++ b/react/src/components/dashboard/walletsData/walletsData.js @@ -49,6 +49,7 @@ class WalletsData extends React.Component { currentStackLength: 0, totalStackLength: 0, useCache: true, + coin: null, }; this.updateInput = this.updateInput.bind(this); this.toggleBasiliskActionsMenu = this.toggleBasiliskActionsMenu.bind(this); @@ -278,9 +279,16 @@ class WalletsData extends React.Component { this.state.activePage * this.state.itemsPerPage ); - stateObj = Object.assign(stateObj, { - itemsList: historyToSplit, - }); + if (!this.state.itemsList || (this.state.coin && this.state.coin !== this.props.ActiveCoin.coin) || (historyToSplit && + historyToSplit.length && + this.state.itemsList && + this.state.itemsList.length && + historyToSplit[0].txid !== this.state.itemsList[0].txid && + historyToSplit[historyToSplit.length - 1].txid !== this.state.itemsList[this.state.itemsList.length - 1].txid)) { + stateObj = Object.assign(stateObj, { + itemsList: historyToSplit, + }); + } } } @@ -307,12 +315,24 @@ class WalletsData extends React.Component { this.state.activePage * this.state.itemsPerPage ); - stateObj = Object.assign(stateObj, { - itemsList: historyToSplit, - }); + if (!this.state.itemsList || (this.state.coin && this.state.coin !== this.props.ActiveCoin.coin) || (historyToSplit && + historyToSplit.length && + this.state.itemsList && + this.state.itemsList.length && + historyToSplit[0].txid !== this.state.itemsList[0].txid && + historyToSplit[historyToSplit.length - 1].txid !== this.state.itemsList[this.state.itemsList.length - 1].txid)) { + stateObj = Object.assign(stateObj, { + itemsList: historyToSplit, + }); + } } - this.setState(Object.assign({}, this.state, stateObj)); + stateObj = Object.assign(stateObj, { + coin: this.props.ActiveCoin.coin, + }); + if (Object.keys(stateObj).length) { + this.setState(Object.assign({}, this.state, stateObj)); + } } } diff --git a/react/src/components/dashboard/walletsProgress/walletsProgress.js b/react/src/components/dashboard/walletsProgress/walletsProgress.js index f6ea680..32134c2 100644 --- a/react/src/components/dashboard/walletsProgress/walletsProgress.js +++ b/react/src/components/dashboard/walletsProgress/walletsProgress.js @@ -93,7 +93,7 @@ class WalletsProgress extends React.Component { if (_progress && _progress[1]) { - return SyncPercentageRender.call(this, _progress[1].toFixed(2)); + return SyncPercentageRender.call(this, _progress[1] === 1000 ? 100 : _progress[1].toFixed(2)); } else { return LoadingBlocksRender.call(this); } @@ -113,7 +113,7 @@ class WalletsProgress extends React.Component { 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); - return SyncPercentageRender.call(this, syncPercentage); + return SyncPercentageRender.call(this, syncPercentage === 1000 ? 100 : syncPercentage); } return LoadingBlocksRender.call(this); diff --git a/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js b/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js index 96b142c..8afdd80 100644 --- a/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js +++ b/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.render.js @@ -20,7 +20,6 @@ const WalletsTxInfoRender = function(txInfo) { <i className="icon md-balance-wallet"></i>TxID Info </a> </li> - { this.isNativeMode() && <li className={ this.state.activeTab === 1 ? 'hide active' : 'hide' }> <a onClick={ () => this.openTab(1) }> @@ -28,7 +27,6 @@ const WalletsTxInfoRender = function(txInfo) { </a> </li> } - { this.isNativeMode() && <li className={ this.state.activeTab === 2 ? 'hide active' : 'hide' }> <a onClick={ () => this.openTab(2) }> @@ -36,7 +34,6 @@ const WalletsTxInfoRender = function(txInfo) { </a> </li> } - <li className={ this.state.activeTab === 3 ? 'active' : '' }> <a onClick={ () => this.openTab(3) }> <i className="icon wb-file"></i>Raw info diff --git a/react/src/util/sort.js b/react/src/util/sort.js index c559c4e..d7cf9d2 100644 --- a/react/src/util/sort.js +++ b/react/src/util/sort.js @@ -1,9 +1,10 @@ export function sortByDate(data) { return data.sort(function(a, b) { - if (a.txid === b.txid) { - return 1; - } else { + if (a.confirmations && + b.confirmations) { return a.confirmations - b.confirmations; + } else { + return 1; } }); } \ No newline at end of file