From dbd327a4d860a3f39b58496d74b4fbaafdea8c22 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 13 Jul 2017 12:23:57 -0700 Subject: [PATCH] txinfo modal bugfix --- .../dashboard/walletsData/walletsData.js | 48 ++++++++++++------- .../walletsData/walletsData.render.js | 2 +- .../dashboard/walletsTxInfo/walletsTxInfo.js | 3 +- react/src/util/sort.js | 9 +++- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/react/src/components/dashboard/walletsData/walletsData.js b/react/src/components/dashboard/walletsData/walletsData.js index 12d4909..72400e9 100644 --- a/react/src/components/dashboard/walletsData/walletsData.js +++ b/react/src/components/dashboard/walletsData/walletsData.js @@ -32,7 +32,7 @@ import { import { SocketProvider } from 'socket.io-react'; import io from 'socket.io-client'; -const socket = io.connect('http://127.0.0.1:' + Config.agamaPort); +const socket = io.connect(`http://127.0.0.1:${Config.agamaPort}`); class WalletsData extends React.Component { constructor(props) { @@ -401,22 +401,30 @@ class WalletsData extends React.Component { } renderAddressByType(type) { - if (this.props.ActiveCoin.addresses && - this.props.ActiveCoin.addresses[type] && - this.props.ActiveCoin.addresses[type].length) { + const _addresses = this.props.ActiveCoin.addresses; + + if (_addresses && + _addresses[type] && + _addresses[type].length) { let items = []; + const _cache = this.props.ActiveCoin.cache; + const _coin = this.props.ActiveCoin.coin; - for (let i = 0; i < this.props.ActiveCoin.addresses[type].length; i++) { - const address = this.props.ActiveCoin.addresses[type][i]; + for (let i = 0; i < _addresses[type].length; i++) { + const address = _addresses[type][i].address; let _amount = address.amount; if (this.props.ActiveCoin.mode === 'basilisk') { - _amount = this.props.ActiveCoin.cache && this.props.ActiveCoin.cache[this.props.ActiveCoin.coin] && this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address.address] && this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address.address].getbalance.data && this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address.address].getbalance.data.balance ? this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address.address].getbalance.data.balance : 'N/A'; + _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'; } items.push( -
  • - this.updateAddressSelection(address.address, type, _amount) }> [ { _amount } { this.props.ActiveCoin.coin } ]  { address.address } +
  • + this.updateAddressSelection(address, type, _amount) }> +    + [ { _amount } { _coin } ]  { address } + +
  • ); } @@ -435,14 +443,19 @@ class WalletsData extends React.Component { renderAddressAmount() { if (this.hasPublicAdresses()) { - for (let i = 0; i < this.props.ActiveCoin.addresses.public.length; i++) { - if (this.props.ActiveCoin.addresses.public[i].address === this.state.currentAddress) { - if (this.props.ActiveCoin.addresses.public[i].amount && - this.props.ActiveCoin.addresses.public[i].amount !== 'N/A') { - return this.props.ActiveCoin.addresses.public[i].amount; + const _addresses = this.props.ActiveCoin.addresses; + const _cache = this.props.ActiveCoin.cache; + const _coin = this.props.ActiveCoin.coin; + + for (let i = 0; i < _addresses.public.length; i++) { + if (_addresses.public[i].address === this.state.currentAddress) { + if (_addresses.public[i].amount && + _addresses.public[i].amount !== 'N/A') { + return _addresses.public[i].amount; } else { - const address = this.props.ActiveCoin.addresses.public[i].address; - const _amount = this.props.ActiveCoin.cache[this.props.ActiveCoin.coin] && this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address] && this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address].getbalance.data && this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address].getbalance.data.balance ? this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][address].getbalance.data.balance : 'N/A'; + const address = _addresses.public[i].address; + const _amount = _cache[_coin] && _cache[_coin][address] && _cache[_coin][address].getbalance.data && _cache[_coin][address].getbalance.data.balance ? _cache[_coin][address].getbalance.data.balance : 'N/A'; + return _amount; } } @@ -456,7 +469,8 @@ class WalletsData extends React.Component { if (this.state.currentAddress) { return ( - [ { this.renderAddressAmount() } { this.props.ActiveCoin.coin } ]  { this.state.currentAddress } +    + [ { this.renderAddressAmount() } { this.props.ActiveCoin.coin } ]  { this.state.currentAddress } ); } else { diff --git a/react/src/components/dashboard/walletsData/walletsData.render.js b/react/src/components/dashboard/walletsData/walletsData.render.js index 000f0d7..2e1432f 100644 --- a/react/src/components/dashboard/walletsData/walletsData.render.js +++ b/react/src/components/dashboard/walletsData/walletsData.render.js @@ -83,7 +83,7 @@ export const TxHistoryListRender = function(tx, index) { diff --git a/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.js b/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.js index 309e054..3055c67 100644 --- a/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.js +++ b/react/src/components/dashboard/walletsTxInfo/walletsTxInfo.js @@ -1,4 +1,5 @@ import React from 'react'; +import { sortByDate } from '../../../util/sort'; import { toggleDashboardTxInfoModal } from '../../../actions/actionCreators'; import Store from '../../../store'; import WalletsTxInfoRender from './walletsTxInfo.render'; @@ -39,7 +40,7 @@ class WalletsTxInfo extends React.Component { // into the rest of the components (!this.isNativeMode() || (this.isNativeMode() && this.props.ActiveCoin.nativeActiveSection === 'default'))) { - const txInfo = this.props.ActiveCoin.txhistory[this.props.ActiveCoin.showTransactionInfoTxIndex]; + const txInfo = sortByDate(this.props.ActiveCoin.txhistory)[this.props.ActiveCoin.showTransactionInfoTxIndex]; return WalletsTxInfoRender.call(this, txInfo); } diff --git a/react/src/util/sort.js b/react/src/util/sort.js index dd0fff5..3ae1063 100644 --- a/react/src/util/sort.js +++ b/react/src/util/sort.js @@ -1,5 +1,10 @@ export function sortByDate(data) { - return data.sort(function(a, b){ - return new Date(b.blocktime || b.timestamp) - new Date(a.blocktime || a.timestamp); + return data.sort(function(a, b) { + if (a.timestamp && + b.timestamp) { + return b.timestamp - a.timestamp; + } else { + return b.blocktime - a.blocktime; + } }); } \ No newline at end of file