From 9298698468a3663e152edbbefba7f0a2b12da710 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 31 Jul 2017 18:51:14 +0300 Subject: [PATCH] added activeCoin check to walletsData tx history render --- .../dashboard/walletsData/walletsData.js | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/react/src/components/dashboard/walletsData/walletsData.js b/react/src/components/dashboard/walletsData/walletsData.js index bd2c5cb..f98e184 100644 --- a/react/src/components/dashboard/walletsData/walletsData.js +++ b/react/src/components/dashboard/walletsData/walletsData.js @@ -248,21 +248,55 @@ class WalletsData extends React.Component { } componentWillReceiveProps(props) { - if (!this.state.currentAddress && - this.props.ActiveCoin.activeAddress) { - this.setState(Object.assign({}, this.state, { - currentAddress: this.props.ActiveCoin.activeAddress, - })); - } + let historyToSplit; - if (this.props.ActiveCoin.txhistory && + if (this.props && + this.props.ActiveCoin && + this.props.ActiveCoin.coin) { + if (!this.state.currentAddress && + this.props.ActiveCoin.activeAddress) { + this.setState(Object.assign({}, this.state, { + currentAddress: this.props.ActiveCoin.activeAddress, + })); + } + + if (this.props.ActiveCoin.txhistory && + this.props.ActiveCoin.txhistory !== 'loading' && + this.props.ActiveCoin.txhistory !== 'no data' && + this.props.ActiveCoin.txhistory.length) { + if (!this.state.itemsList || + (this.state.itemsList && !this.state.itemsList.length) || + (props.ActiveCoin.txhistory !== this.props.ActiveCoin.txhistory)) { + historyToSplit = sortByDate(this.props.ActiveCoin.txhistory); + historyToSplit = historyToSplit.slice( + (this.state.activePage - 1) * this.state.itemsPerPage, + this.state.activePage * this.state.itemsPerPage + ); + + this.setState(Object.assign({}, this.state, { + itemsList: historyToSplit, + })); + } + } + + if (!historyToSplit && + this.props.ActiveCoin.txhistory && + this.props.ActiveCoin.txhistory === 'no data') { + this.setState(Object.assign({}, this.state, { + itemsList: 'no data', + })); + } else if (!historyToSplit && this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'loading') { + this.setState(Object.assign({}, this.state, { + itemsList: 'loading', + })); + } else if ( // dirty first txhistory load workaround + !historyToSplit && + this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory !== 'loading' && this.props.ActiveCoin.txhistory !== 'no data' && - this.props.ActiveCoin.txhistory.length) { - if (!this.state.itemsList || - (this.state.itemsList && !this.state.itemsList.length) || - (props.ActiveCoin.txhistory !== this.props.ActiveCoin.txhistory)) { - let historyToSplit = sortByDate(this.props.ActiveCoin.txhistory); + this.props.ActiveCoin.txhistory.length + ) { + historyToSplit = sortByDate(this.props.ActiveCoin.txhistory); historyToSplit = historyToSplit.slice( (this.state.activePage - 1) * this.state.itemsPerPage, this.state.activePage * this.state.itemsPerPage @@ -273,17 +307,6 @@ class WalletsData extends React.Component { })); } } - - if (this.props.ActiveCoin.txhistory && - this.props.ActiveCoin.txhistory === 'no data') { - this.setState(Object.assign({}, this.state, { - itemsList: 'no data', - })); - } else if (this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'loading') { - this.setState(Object.assign({}, this.state, { - itemsList: 'loading', - })); - } } updateCurrentPage(page) { @@ -395,15 +418,15 @@ class WalletsData extends React.Component { if (this.state.itemsList === 'loading') { if (!this.isNativeMode() || this.isFullySynced()) { return ( - - { translate('INDEX.LOADING_HISTORY') }... + + { translate('INDEX.LOADING_HISTORY') }... ); } } else if (this.state.itemsList === 'no data') { return ( - - { translate('INDEX.NO_DATA') } + + { translate('INDEX.NO_DATA') } ); } else { @@ -484,7 +507,7 @@ class WalletsData extends React.Component { let _amount = address.amount; if (this.props.ActiveCoin.mode === 'basilisk') { - _amount = _cache && _cache[_coin] && _cache[_coin][address] && _cache[_coin][address].getbalance.data && _cache[_coin][address].getbalance.data.balance ? _cache[_coin][address].getbalance.data.balance : 'N/A'; + _amount = _cache && _cache[_coin] && _cache[_coin][address] && _cache[_coin][address].getbalance && _cache[_coin][address].getbalance.data && _cache[_coin][address].getbalance.data.balance ? _cache[_coin][address].getbalance.data.balance : 'N/A'; } if (_amount !== 'N/A') {