Browse Source

fixed tx history timestamp sorting

all-modes
pbca26 8 years ago
parent
commit
097cff60bb
  1. 20
      react/src/actions/actionCreators.js
  2. 39
      react/src/components/dashboard/walletsData/walletsData.js
  3. 5
      react/src/components/dashboard/walletsData/walletsData.render.js

20
react/src/actions/actionCreators.js

@ -193,7 +193,7 @@ export function triggerToaster(message, title, _type, autoClose = true) {
message, message,
title, title,
_type, _type,
autoClose autoClose,
} }
} }
@ -201,7 +201,7 @@ export function triggerToaster(message, title, _type, autoClose = true) {
export function dismissToaster(toastId) { export function dismissToaster(toastId) {
return { return {
type: REMOVE_TOASTER_MESSAGE, type: REMOVE_TOASTER_MESSAGE,
toastId: toastId toastId: toastId,
} }
} }
@ -217,7 +217,7 @@ export function dashboardCoinsState(json) {
return { return {
type: GET_ACTIVE_COINS, type: GET_ACTIVE_COINS,
coins: json, coins: json,
activeCoins: Object.keys(json.native).length || Object.keys(json.basilisk).length || Object.keys(json.full).length ? true : false activeCoins: Object.keys(json.native).length || Object.keys(json.basilisk).length || Object.keys(json.full).length ? true : false,
} }
} }
@ -291,7 +291,13 @@ export function rpcErrorHandler(json, dispatch) {
if (json && if (json &&
json.error) { json.error) {
if (json.error === 'bitcoinrpc needs coin that is active') { if (json.error === 'bitcoinrpc needs coin that is active') {
dispatch(triggerToaster(translate('API.NO_ACTIVE_COIN'), translate('TOASTR.SERVICE_NOTIFICATION'), 'error')); dispatch(
triggerToaster(
translate('API.NO_ACTIVE_COIN'),
translate('TOASTR.SERVICE_NOTIFICATION'),
'error'
)
);
} }
} }
} }
@ -302,8 +308,8 @@ export function setBasiliskMainAddress(json, coin, mode) {
for (let i = 0; i < json.result.length; i++) { for (let i = 0; i < json.result.length; i++) {
publicAddressArray.push({ publicAddressArray.push({
'address': json.result[i], address: json.result[i],
'amount': 'N/A' amount: 'N/A',
}); });
} }
@ -320,7 +326,7 @@ export function setBasiliskMainAddress(json, coin, mode) {
return { return {
type: ACTIVE_COIN_GET_ADDRESSES, type: ACTIVE_COIN_GET_ADDRESSES,
addresses: { 'public': [] }, addresses: { public: [] },
} }
} }

39
react/src/components/dashboard/walletsData/walletsData.js

@ -102,6 +102,31 @@ class WalletsData extends React.Component {
socket.removeAllListeners('messages'); socket.removeAllListeners('messages');
} }
// https://react-table.js.org/#/custom-sorting
tableSorting(a, b) { // ugly workaround, override default sort
if (Date.parse(a)) { // convert date to timestamp
a = Date.parse(a);
}
if (Date.parse(b)) {
b = Date.parse(b);
}
// force null and undefined to the bottom
a = (a === null || a === undefined) ? -Infinity : a;
b = (b === null || b === undefined) ? -Infinity : b;
// force any string values to lowercase
a = typeof a === 'string' ? a.toLowerCase() : a;
b = typeof b === 'string' ? b.toLowerCase() : b;
// Return either 1 or -1 to indicate a sort priority
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
// returning 0 or undefined will use any subsequent column sorting methods or the row index as a tiebreaker
return 0;
}
generateItemsListColumns() { generateItemsListColumns() {
let columns = []; let columns = [];
@ -356,11 +381,9 @@ class WalletsData extends React.Component {
if (!this.state.itemsList || if (!this.state.itemsList ||
(this.state.coin && this.state.coin !== this.props.ActiveCoin.coin) || (this.state.coin && this.state.coin !== this.props.ActiveCoin.coin) ||
(JSON.stringify(this.props.ActiveCoin.txhistory) !== JSON.stringify(this.state.txhistory))) { (JSON.stringify(this.props.ActiveCoin.txhistory) !== JSON.stringify(this.state.txhistory))) {
const sortedItemsList = this.indexTxHistory(sortByDate(this.props.ActiveCoin.txhistory, this.props.ActiveCoin.mode === 'basilisk' ? 'index' : 'confirmations'));
this.setState(Object.assign({}, this.state, { this.setState(Object.assign({}, this.state, {
itemsList: sortedItemsList, itemsList: this.props.ActiveCoin.txhistory,
filteredItemsList: this.filterTransactions(sortedItemsList, this.state.searchTerm), filteredItemsList: this.filterTransactions(this.props.ActiveCoin.txhistory, this.state.searchTerm),
txhistory: this.props.ActiveCoin.txhistory, txhistory: this.props.ActiveCoin.txhistory,
showPagination: this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory.length >= this.state.defaultPageSize showPagination: this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory.length >= this.state.defaultPageSize
})); }));
@ -428,7 +451,7 @@ class WalletsData extends React.Component {
onPageSizeChange(pageSize, pageIndex) { onPageSizeChange(pageSize, pageIndex) {
this.setState(Object.assign({}, this.state, { this.setState(Object.assign({}, this.state, {
pageSize: pageSize, pageSize: pageSize,
showPagination: this.state.itemsList && this.state.itemsList.length >= defaultPageSize, showPagination: this.state.itemsList && this.state.itemsList.length >= this.state.defaultPageSize,
})) }))
} }
@ -551,13 +574,15 @@ class WalletsData extends React.Component {
} }
renderSelectorCurrentLabel() { renderSelectorCurrentLabel() {
if (this.state.currentAddress) { const _currentAddress = this.state.currentAddress;
if (_currentAddress) {
return ( return (
<span> <span>
<i className={ 'icon fa-eye' + (this.state.addressType === 'public' ? '' : '-slash') }></i>&nbsp;&nbsp; <i className={ 'icon fa-eye' + (this.state.addressType === 'public' ? '' : '-slash') }></i>&nbsp;&nbsp;
<span className="text"> <span className="text">
[ { this.renderAddressAmount() } { this.props.ActiveCoin.coin } ]&nbsp;&nbsp; [ { this.renderAddressAmount() } { this.props.ActiveCoin.coin } ]&nbsp;&nbsp;
{ this.state.currentAddress } { _currentAddress }
</span> </span>
</span> </span>
); );

5
react/src/components/dashboard/walletsData/walletsData.render.js

@ -177,6 +177,11 @@ export const TxHistoryListRender = function() {
previousText={ translate('INDEX.PREVIOUS_PAGE') } previousText={ translate('INDEX.PREVIOUS_PAGE') }
showPaginationBottom={ this.state.showPagination } showPaginationBottom={ this.state.showPagination }
pageSize={ this.pageSize } pageSize={ this.pageSize }
defaultSortMethod={ this.tableSorting }
defaultSorted={[{ // default sort
id: 'timestamp',
desc: true,
}]}
onPageSizeChange={ (pageSize, pageIndex) => this.onPageSizeChange(pageSize, pageIndex) } /> onPageSizeChange={ (pageSize, pageIndex) => this.onPageSizeChange(pageSize, pageIndex) } />
); );
}; };

Loading…
Cancel
Save