fix: transactions list sort by date

This commit is contained in:
George Lima 2019-01-08 13:01:20 -03:00
parent d7056f1b03
commit fe74b461ca
6 changed files with 39 additions and 32 deletions

View File

@ -32,7 +32,7 @@ describe('WalletSummary Actions', () => {
transparent: 5000,
shielded: 5000,
addresses: [],
transactions: {},
transactions: [],
zecPrice: 50,
};

View File

@ -14,6 +14,8 @@ import {
import rpc from '../../services/api';
import store from '../../config/electron-store';
import sortBy from '../utils/sortBy';
import type { AppState } from '../types/app-state';
import type { Dispatch } from '../types/redux';
@ -38,18 +40,25 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
);
}
const formattedTransactions = flow([
arr => arr.map(transaction => ({
transactionId: transaction.txid,
type: transaction.category,
date: new Date(transaction.time * 1000).toISOString(),
address: transaction.address,
amount: Math.abs(transaction.amount),
})),
arr => groupBy(arr, obj => dateFns.format(obj.date, 'MMM DD, YYYY')),
obj => Object.keys(obj).map(day => ({
day,
list: sortBy('date')(obj[day]),
})),
sortBy('day'),
])(transactions);
dispatch(
loadTransactionsSuccess({
list: flow([
arr => arr.map(transaction => ({
transactionId: transaction.txid,
type: transaction.category,
date: new Date(transaction.time * 1000).toISOString(),
address: transaction.address,
amount: Math.abs(transaction.amount),
})),
arr => groupBy(arr, obj => dateFns.format(obj.date, 'MMM DD, YYYY')),
])(transactions),
list: formattedTransactions,
zecPrice: store.get('ZEC_DOLLAR_PRICE'),
}),
);

View File

@ -7,6 +7,8 @@ export const LOAD_TRANSACTIONS = 'LOAD_TRANSACTIONS';
export const LOAD_TRANSACTIONS_SUCCESS = 'LOAD_TRANSACTIONS_SUCCESS';
export const LOAD_TRANSACTIONS_ERROR = 'LOAD_TRANSACTIONS_ERROR';
export type TransactionsList = { day: string, list: Transaction[] }[];
export const loadTransactions = () => ({
type: LOAD_TRANSACTIONS,
payload: {},
@ -16,7 +18,7 @@ export const loadTransactionsSuccess = ({
list,
zecPrice,
}: {
list: { [day: string]: Transaction[] },
list: TransactionsList,
zecPrice: number,
}) => ({
type: LOAD_TRANSACTIONS_SUCCESS,
@ -34,13 +36,13 @@ export const loadTransactionsError = ({ error }: { error: string }) => ({
export type State = {
isLoading: boolean,
error: string | null,
list: { [day: string]: Transaction[] },
list: TransactionsList,
zecPrice: number,
};
const initialState = {
zecPrice: 0,
list: {},
list: [],
error: null,
isLoading: false,
};

View File

@ -1,6 +1,6 @@
// @flow
import type { Action } from '../../types/redux';
import type { Transaction } from '../../components/transaction-item';
import type { TransactionsList } from './transactions';
// Actions
export const LOAD_WALLET_SUMMARY = 'LOAD_WALLET_SUMMARY';
@ -25,7 +25,7 @@ export const loadWalletSummarySuccess = ({
shielded: number,
transparent: number,
addresses: string[],
transactions: { [day: string]: Transaction[] },
transactions: TransactionsList,
zecPrice: number,
}) => ({
type: LOAD_WALLET_SUMMARY_SUCCESS,
@ -52,7 +52,7 @@ export type State = {
isLoading: boolean,
zecPrice: number,
addresses: [],
transactions: { [day: string]: Transaction[] },
transactions: TransactionsList,
};
const initialState = {
@ -63,7 +63,7 @@ const initialState = {
isLoading: false,
zecPrice: 0,
addresses: [],
transactions: {},
transactions: [],
};
export default (state: State = initialState, action: Action) => {

View File

@ -7,7 +7,7 @@ import { TransactionDailyComponent } from '../components/transaction-daily';
import { TextComponent } from '../components/text';
import { EmptyTransactionsComponent } from '../components/empty-transactions';
import type { Transaction } from '../components/transaction-item';
import type { TransactionsList } from '../redux/modules/transactions';
type Props = {
getSummary: () => void,
@ -17,7 +17,7 @@ type Props = {
error: string | null,
zecPrice: number,
addresses: string[],
transactions: { [day: string]: Transaction[] },
transactions: TransactionsList,
};
export class DashboardView extends PureComponent<Props> {
@ -37,8 +37,6 @@ export class DashboardView extends PureComponent<Props> {
transactions,
} = this.props;
const days = Object.keys(transactions);
if (error) {
return <TextComponent value={error} />;
}
@ -52,13 +50,13 @@ export class DashboardView extends PureComponent<Props> {
zecPrice={zecPrice}
addresses={addresses}
/>
{days.length === 0 ? (
{transactions.length === 0 ? (
<EmptyTransactionsComponent />
) : (
days.map(day => (
transactions.map(({ day, list }) => (
<TransactionDailyComponent
transactionsDate={day}
transactions={transactions[day]}
transactions={list}
zecPrice={zecPrice}
key={day}
/>

View File

@ -5,11 +5,11 @@ import { TransactionDailyComponent } from '../components/transaction-daily';
import { TextComponent } from '../components/text';
import { EmptyTransactionsComponent } from '../components/empty-transactions';
import type { Transaction } from '../components/transaction-item';
import type { TransactionsList } from '../redux/modules/transactions';
type Props = {
error: string | null,
transactions: { [day: string]: Transaction[] },
transactions: TransactionsList,
zecPrice: number,
getTransactions: () => void,
};
@ -27,17 +27,15 @@ export class TransactionsView extends PureComponent<Props> {
return <TextComponent value={error} />;
}
const days = Object.keys(transactions);
return (
<Fragment>
{days.length === 0 ? (
{transactions.length === 0 ? (
<EmptyTransactionsComponent />
) : (
days.map(day => (
transactions.map(({ day, list }) => (
<TransactionDailyComponent
transactionsDate={day}
transactions={transactions[day]}
transactions={list}
zecPrice={zecPrice}
/>
))