Skip to content

Commit

Permalink
Merge pull request #908 from LiskHQ/879-delegate-statistics-sends-req…
Browse files Browse the repository at this point in the history
…uest-transactionFilterSet

Dont allow to call API when going on Delegate statistics page - Closes #879
  • Loading branch information
michaeltomasik committed Jun 14, 2018
2 parents 939d8f9 + b5f40ce commit 2c679a1
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 27 deletions.
11 changes: 10 additions & 1 deletion src/actions/search.js
Expand Up @@ -70,11 +70,20 @@ export const searchTransactions = ({
data: {
address,
transactions: transactionsResponse.transactions,
count: parseInt(transactionsResponse.count, 10),
count: parseInt(transactionsResponse.count, 10) || 0,
filter,
},
type: actionTypes.searchTransactions,
});
if (filter !== undefined) {
dispatch({
data: {
filterName: 'transactions',
value: filter,
},
type: actionTypes.addFilter,
});
}
if (showLoading) loadingFinished(actionTypes.searchTransactions);
});
};
Expand Down
27 changes: 19 additions & 8 deletions src/actions/transactions.js
Expand Up @@ -15,14 +15,25 @@ export const transactionsFilterSet = ({
address,
limit,
filter,
}).then(response => dispatch({
data: {
confirmed: response.transactions,
count: parseInt(response.count, 10),
filter,
},
type: actionTypes.transactionsFiltered,
}));
}).then((response) => {
dispatch({
data: {
confirmed: response.transactions,
count: parseInt(response.count, 10),
filter,
},
type: actionTypes.transactionsFiltered,
});
if (filter !== undefined) {
dispatch({
data: {
filterName: 'wallet',
value: filter,
},
type: actionTypes.addFilter,
});
}
});
};

export const transactionsUpdateUnconfirmed = ({ activePeer, address, pendingTransactions }) =>
Expand Down
2 changes: 2 additions & 0 deletions src/components/accountTransactions/index.test.js
Expand Up @@ -11,6 +11,7 @@ import peersReducer from '../../store/reducers/peers';
import accountReducer from '../../store/reducers/account';
import searchReducer from '../../store/reducers/search';
import loadingReducer from '../../store/reducers/loading';
import filtersReducer from '../../store/reducers/filters';

import AccountTransactions from './index';
import i18n from '../../i18n';
Expand All @@ -27,6 +28,7 @@ describe('AccountTransaction Component', () => {
account: accountReducer,
search: searchReducer,
loading: loadingReducer,
filters: filtersReducer,
}, [thunk]);

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/fontIcon/fontIcon.css
Expand Up @@ -38,7 +38,7 @@
content: "\f102";
}

.angle-down::before {
.arrow-down::before {
content: "\f103";
}

Expand Down
Expand Up @@ -5,7 +5,6 @@ import TransactionOverview from './../transactionOverview';
import TransactionDetailView from './../transactionDetailView';
import Box from './../../box';
import txFilters from './../../../constants/transactionFilters';

import routes from './../../../constants/routes';

class ExplorerTransactions extends React.Component {
Expand All @@ -20,6 +19,11 @@ class ExplorerTransactions extends React.Component {
limit: 25,
filter: txFilters.all,
});

this.props.addFilter({
filterName: 'transactions',
value: txFilters.all,
});
}
onLoadMore() {
this.props.searchMoreTransactions({
Expand All @@ -30,14 +34,26 @@ class ExplorerTransactions extends React.Component {
filter: this.props.activeFilter,
});
}
/*
Transactions from tabs are filtered based on filter number
It applys to All, Incoming and Outgoing
for other tabs that are not using transactions there is no need to call API
*/
onFilterSet(filter) {
this.props.searchTransactions({
activePeer: this.props.activePeer,
address: this.props.address,
limit: 25,
filter,
showLoading: false,
});
if (filter <= 2) {
this.props.searchTransactions({
activePeer: this.props.activePeer,
address: this.props.address,
limit: 25,
filter,
showLoading: false,
});
} else {
this.props.addFilter({
filterName: 'transactions',
value: filter,
});
}
}

onTransactionRowClick(props) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/transactions/explorerTransactions/index.js
Expand Up @@ -15,8 +15,7 @@ const mapStateToProps = (state, ownProps) => ({
count: state.search.transactions[state.search.lastSearch] &&
(state.search.transactions[state.search.lastSearch].count || null),
offset: state.search.searchResults.length,
activeFilter: state.search.transactions[state.search.lastSearch] &&
(state.search.transactions[state.search.lastSearch].filter || txFilters.all),
activeFilter: state.filters.transactions || txFilters.all,
isSearchInStore: state.search.transactions[ownProps.address] !== undefined,
loading: state.loading,
});
Expand All @@ -25,6 +24,7 @@ const mapDispatchToProps = dispatch => ({
searchAccount: data => dispatch(searchAccount(data)),
searchTransactions: data => dispatch(searchTransactions(data)),
searchMoreTransactions: data => dispatch(searchMoreTransactions(data)),
addFilter: data => dispatch({ type: actionTypes.addFilter, data }),
searchUpdateLast: data =>
dispatch({ data, type: actionTypes.searchUpdateLast }),
});
Expand Down
Expand Up @@ -14,6 +14,7 @@ import transactionReducer from '../../../store/reducers/transaction';
import transactionsReducer from '../../../store/reducers/transactions';
import searchReducer from '../../../store/reducers/search';
import loadingReducer from '../../../store/reducers/loading';
import filtersReducer from '../../../store/reducers/filters';
import { activePeerSet } from '../../../../src/actions/peers';
import networks from './../../../../src/constants/networks';
import getNetwork from './../../../../src/utils/getNetwork';
Expand Down Expand Up @@ -41,6 +42,7 @@ describe('ExplorerTransactions Component', () => {
transactions: transactionsReducer,
search: searchReducer,
loading: loadingReducer,
filters: filtersReducer,
}, [thunk]);

beforeEach(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/transactions/walletTransactions/index.js
Expand Up @@ -4,6 +4,8 @@ import { withRouter } from 'react-router-dom';
import { transactionsRequested, transactionsFilterSet } from '../../../actions/transactions';
import { accountVotersFetched, accountVotesFetched } from '../../../actions/account';
import WalletTransactions from './walletTransactions';
import actionTypes from '../../../constants/actions';
import txFilters from './../../../constants/transactionFilters';

/* istanbul ignore next */
const mapStateToProps = state => ({
Expand All @@ -15,7 +17,7 @@ const mapStateToProps = state => ({
voters: state.account.voters,
count: state.transactions.count,
delegate: state.account && (state.account.delegate || null),
activeFilter: state.transactions.filter,
activeFilter: state.filters.wallet || txFilters.all,
loading: state.loading,
});

Expand All @@ -24,6 +26,7 @@ const mapDispatchToProps = dispatch => ({
transactionsFilterSet: data => dispatch(transactionsFilterSet(data)),
accountVotersFetched: data => dispatch(accountVotersFetched(data)),
accountVotesFetched: data => dispatch(accountVotesFetched(data)),
addFilter: data => dispatch({ type: actionTypes.addFilter, data }),
});

export default withRouter(connect(
Expand Down
2 changes: 2 additions & 0 deletions src/components/transactions/walletTransactions/index.test.js
Expand Up @@ -13,6 +13,7 @@ import accountReducer from '../../../store/reducers/account';
import transactionsReducer from '../../../store/reducers/transactions';
import searchReducer from '../../../store/reducers/search';
import loadingReducer from '../../../store/reducers/loading';
import filtersReducer from '../../../store/reducers/filters';

import { accountLoggedIn } from '../../../../src/actions/account';
import { activePeerSet } from '../../../../src/actions/peers';
Expand All @@ -37,6 +38,7 @@ describe('WalletTransactions Component', () => {
transactions: transactionsReducer,
search: searchReducer,
loading: loadingReducer,
filters: filtersReducer,
}, [thunk]);

beforeEach(() => {
Expand Down
Expand Up @@ -29,6 +29,11 @@ class WalletTransactions extends React.Component {
address: this.props.address,
});
}

this.props.addFilter({
filterName: 'wallet',
value: txFilters.all,
});
}
onLoadMore() {
this.props.transactionsRequested({
Expand All @@ -39,13 +44,25 @@ class WalletTransactions extends React.Component {
filter: this.props.activeFilter,
});
}
/*
Transactions from tabs are filtered based on filter number
It applys to All, Incoming and Outgoing
for other tabs that are not using transactions there is no need to call API
*/
onFilterSet(filter) {
this.props.transactionsFilterSet({
activePeer: this.props.activePeer,
address: this.props.address,
limit: 25,
filter,
});
if (filter <= 2) {
this.props.transactionsFilterSet({
activePeer: this.props.activePeer,
address: this.props.address,
limit: 25,
filter,
});
} else {
this.props.addFilter({
filterName: 'wallet',
value: filter,
});
}
}
onTransactionRowClick(props) {
this.props.history.push(`${routes.wallet.path}?id=${props.value.id}`);
Expand Down
1 change: 1 addition & 0 deletions src/constants/actions.js
Expand Up @@ -70,6 +70,7 @@ const actionTypes = {
settingsUpdated: 'SETTINGS_UPDATED',
settingsReset: 'SETTINGS_RESET',
removeSavedAccountPassphrase: 'REMOVE_SAVED_ACCOUNT_PASSPHRASE',
addFilter: 'ADD_FILTER',
};

export default actionTypes;
15 changes: 15 additions & 0 deletions src/store/reducers/filters.js
@@ -0,0 +1,15 @@
import actionTypes from '../../constants/actions';

const filters = (state = { transactions: 0, wallet: 0 }, action) => {
switch (action.type) {
case actionTypes.addFilter:
return {
...state,
[action.data.filterName]: action.data.value,
};
default:
return state;
}
};

export default filters;
1 change: 1 addition & 0 deletions src/store/reducers/index.js
Expand Up @@ -12,3 +12,4 @@ export { default as search } from './search';
export { default as settings } from './settings';
export { default as delegate } from './delegate';
export { default as liskService } from './liskService';
export { default as filters } from './filters';
2 changes: 2 additions & 0 deletions test/integration/accountTransactions.test.js
Expand Up @@ -15,6 +15,7 @@ import loadingReducer from '../../src/store/reducers/loading';
import votingReducer from '../../src/store/reducers/voting';
import transactionReducer from '../../src/store/reducers/transaction';
import searchReducer from '../../src/store/reducers/search';
import filtersReducer from '../../src/store/reducers/filters';
import loginMiddleware from '../../src/store/middlewares/login';
import accountMiddleware from '../../src/store/middlewares/account';
import votingMiddleware from '../../src/store/middlewares/voting';
Expand Down Expand Up @@ -181,6 +182,7 @@ describe('@integration: Account Transactions', () => {
peers: peersReducer,
loading: loadingReducer,
search: searchReducer,
filters: filtersReducer,
}, [
thunk,
accountMiddleware,
Expand Down
2 changes: 2 additions & 0 deletions test/integration/wallet.test.js
Expand Up @@ -16,6 +16,7 @@ import settingsReducer from '../../src/store/reducers/settings';
import peersReducer from '../../src/store/reducers/peers';
import loadingReducer from '../../src/store/reducers/loading';
import searchReducer from '../../src/store/reducers/search';
import filtersReducer from '../../src/store/reducers/filters';
import loginMiddleware from '../../src/store/middlewares/login';
import accountMiddleware from '../../src/store/middlewares/account';
import peerMiddleware from '../../src/store/middlewares/peers';
Expand Down Expand Up @@ -92,6 +93,7 @@ describe('@integration: Wallet', () => {
loading: loadingReducer,
search: searchReducer,
settings: settingsReducer,
filters: filtersReducer,
}, [
thunk,
accountMiddleware,
Expand Down

0 comments on commit 2c679a1

Please sign in to comment.