From 167572feb8a8b19f929d3452388a8282b3a3e4d3 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 30 Apr 2017 12:43:51 +0300 Subject: [PATCH] sort desc tx history --- react/src/components/dashboard/walletsData.js | 7 ++++--- react/src/components/dashboard/walletsNativeTxHistory.js | 7 ++++--- react/src/util/sort.js | 5 +++++ 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 react/src/util/sort.js diff --git a/react/src/components/dashboard/walletsData.js b/react/src/components/dashboard/walletsData.js index 463201b..e8f51cf 100644 --- a/react/src/components/dashboard/walletsData.js +++ b/react/src/components/dashboard/walletsData.js @@ -2,6 +2,7 @@ import React from 'react'; import Config from '../../config'; import { translate } from '../../translate/translate'; import { secondsToString } from '../../util/time'; +import { sortByDate } from '../../util/sort'; import { basiliskRefresh, basiliskConnection, @@ -156,7 +157,7 @@ class WalletsData extends React.Component { this.setState({ [e.target.name]: e.target.value, activePage: 1, - itemsList: historyToSplit, + itemsList: sortByDate(historyToSplit), }); } @@ -171,7 +172,7 @@ class WalletsData extends React.Component { historyToSplit = historyToSplit.slice((this.state.activePage - 1) * this.state.itemsPerPage, this.state.activePage * this.state.itemsPerPage); this.setState(Object.assign({}, this.state, { - itemsList: historyToSplit, + itemsList: sortByDate(historyToSplit), })); } } @@ -189,7 +190,7 @@ class WalletsData extends React.Component { this.setState(Object.assign({}, this.state, { activePage: page, - itemsList: historyToSplit, + itemsList: sortByDate(historyToSplit), })); } diff --git a/react/src/components/dashboard/walletsNativeTxHistory.js b/react/src/components/dashboard/walletsNativeTxHistory.js index f90e2a6..b867dd8 100644 --- a/react/src/components/dashboard/walletsNativeTxHistory.js +++ b/react/src/components/dashboard/walletsNativeTxHistory.js @@ -1,6 +1,7 @@ import React from 'react'; import { translate } from '../../translate/translate'; import { secondsToString } from '../../util/time'; +import { sortByDate } from '../../util/sort'; import { toggleDashboardTxInfoModal } from '../../actions/actionCreators'; import Store from '../../store'; @@ -31,7 +32,7 @@ class WalletsNativeTxHistory extends React.Component { this.setState({ [e.target.name]: e.target.value, activePage: 1, - itemsList: historyToSplit, + itemsList: sortByDate(historyToSplit), }); } @@ -85,7 +86,7 @@ class WalletsNativeTxHistory extends React.Component { historyToSplit = historyToSplit.slice((this.state.activePage - 1) * this.state.itemsPerPage, this.state.activePage * this.state.itemsPerPage); this.setState(Object.assign({}, this.state, { - itemsList: historyToSplit, + itemsList: sortByDate(historyToSplit), })); } } @@ -97,7 +98,7 @@ class WalletsNativeTxHistory extends React.Component { this.setState(Object.assign({}, this.state, { activePage: page, - itemsList: historyToSplit, + itemsList: sortByDate(historyToSplit), })); } diff --git a/react/src/util/sort.js b/react/src/util/sort.js new file mode 100644 index 0000000..dd0fff5 --- /dev/null +++ b/react/src/util/sort.js @@ -0,0 +1,5 @@ +export function sortByDate(data) { + return data.sort(function(a, b){ + return new Date(b.blocktime || b.timestamp) - new Date(a.blocktime || a.timestamp); + }); +} \ No newline at end of file