Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused voters - Closes #1911 #2007

Merged
merged 11 commits into from May 15, 2019
1 change: 0 additions & 1 deletion docs/EXTENSIONS_GUIDE.md
Expand Up @@ -37,7 +37,6 @@ actions={
transactionsFilterSet,
searchDelegate,
searchVotes,
searchVoters,
searchAccount,
searchTransactions,
}
Expand Down
8 changes: 0 additions & 8 deletions i18n/locales/en/common.json
Expand Up @@ -64,7 +64,6 @@
"Before you continue using Lisk Hub, please read and accept the": "Before you continue using Lisk Hub, please read and accept the",
"Beta: in order to see changes fully please reload the app when removing extension": "Beta: in order to see changes fully please reload the app when removing extension",
"Blockchain Application Registration": "Blockchain Application Registration",
"Blocks": "Blocks",
"Blocks forged": "Blocks forged",
"Bookmark account": "Bookmark account",
"Bookmarks": "Bookmarks",
Expand Down Expand Up @@ -176,7 +175,6 @@
"Filter Transactions": "Filter Transactions",
"Filter by name": "Filter by name",
"Filter by name...": "Filter by name...",
"Filter votes": "Filter votes",
"Filtered results: {{results}}": "Filtered results: {{results}}",
"Final confirmation": "Final confirmation",
"Followed Account": "Followed Account",
Expand Down Expand Up @@ -351,7 +349,6 @@
"Proxy Authentication": "Proxy Authentication",
"Quit": "Quit",
"Rank": "Rank",
"Rank / Status": "Rank / Status",
"Read More": "Read More",
"Recent searches": "Recent searches",
"Recipient": "Recipient",
Expand Down Expand Up @@ -416,7 +413,6 @@
"Sharing link": "Sharing link",
"Show Less": "Show Less",
"Show More": "Show More",
"Show more": "Show more",
"Show passphrase": "Show passphrase",
"Show the QR code": "Show the QR code",
"Show this account's transactions on the dashboard.": "Show this account's transactions on the dashboard.",
Expand Down Expand Up @@ -494,7 +490,6 @@
"Update download finished": "Update download finished",
"Update now": "Update now",
"Updates downloaded, application has to be restarted to apply the updates.": "Updates downloaded, application has to be restarted to apply the updates.",
"Uptime": "Uptime",
"Upvotes": "Upvotes",
"Use extensions from https://raw.githubusercontent.com/michaeltomasik/extensions-lisk/master/": "Use extensions from https://raw.githubusercontent.com/michaeltomasik/extensions-lisk/master/",
"Use the sharing link to easily request any amount of LSK from Lisk Hub or Lisk Mobile users.": "Use the sharing link to easily request any amount of LSK from Lisk Hub or Lisk Mobile users.",
Expand All @@ -511,7 +506,6 @@
"Voted delegates": "Voted delegates",
"Voter": "Voter",
"Votes": "Votes",
"Votes of this account": "Votes of this account",
"Votes submitted": "Votes submitted",
"Voting": "Voting",
"Wallet": "Wallet",
Expand All @@ -523,7 +517,6 @@
"What is a Lisk ID?": "What is a Lisk ID?",
"What is your passphrase?": "What is your passphrase?",
"What's New...": "What's New...",
"Who voted for this delegate": "Who voted for this delegate",
"Why should I vote?": "Why should I vote?",
"Window": "Window",
"Write a message": "Write a message",
Expand Down Expand Up @@ -577,7 +570,6 @@
"from": "from",
"ie. 192.168.0.1": "ie. 192.168.0.1",
"if the problem persists": "if the problem persists",
"missed": "missed",
"or": "or",
"to": "to",
"with a second passphrase": "with a second passphrase",
Expand Down
15 changes: 1 addition & 14 deletions src/actions/account.js
Expand Up @@ -3,7 +3,7 @@
import i18next from 'i18next';
import actionTypes from '../constants/actions';
import { getAccount, setSecondPassphrase } from '../utils/api/account';
import { registerDelegate, getDelegate, getAllVotes, getVoters } from '../utils/api/delegate';
import { registerDelegate, getDelegate, getAllVotes } from '../utils/api/delegate';
import { getTransactions } from '../utils/api/transactions';
import { getBlocks } from '../utils/api/blocks';
import { loadTransactionsFinish, transactionsUpdated } from './transactions';
Expand Down Expand Up @@ -93,19 +93,6 @@ export const accountVotesFetched = ({ address }) =>
});
};

/**
* Gets list of all voters
*/
export const accountVotersFetched = ({ publicKey }) =>
(dispatch, getState) => {
const liskAPIClient = getState().peers.liskAPIClient;
return getVoters(liskAPIClient, { publicKey }).then(({ data }) => {
dispatch({
type: actionTypes.accountAddVoters,
voters: data,
});
});
};
/**
*
*/
Expand Down
86 changes: 14 additions & 72 deletions src/actions/search.js
@@ -1,7 +1,7 @@
import actionTypes from '../constants/actions';
import { loadingStarted, loadingFinished } from '../actions/loading';
import { getAccount } from '../utils/api/account';
import { getDelegate, getVoters, getVotes, listDelegates } from '../utils/api/delegate';
import { getDelegate, getVotes, listDelegates } from '../utils/api/delegate';
import { getTransactions } from '../utils/api/transactions';
import { getBlocks } from '../utils/api/blocks';
import searchAll from '../utils/api/search';
Expand Down Expand Up @@ -88,47 +88,6 @@ const searchVotes = ({ address, offset, limit }) =>
dispatch(loadingFinished(actionTypes.searchVotes));
};

/* istanbul ignore next */
/* because it's not used anymore and should be removed in #1911 */
const searchVoters = ({
address, publicKey, offset, limit, append,
}) =>
(dispatch, getState) => {
const liskAPIClient = getState().peers.liskAPIClient;
/* istanbul ignore else */
if (liskAPIClient) {
getVoters(liskAPIClient, {
publicKey, offset, limit,
}).then(response =>
dispatch({
type: actionTypes.searchVoters,
data: {
append: append || false,
voters: response.data.voters,
votersSize: response.data.votes,
address,
},
}));
}
};

/* istanbul ignore next */
/* because it's not used anymore and should be removed in #1911 */
export const searchMoreVoters = ({ address, offset = 0, limit = 100 }) =>
(dispatch, getState) => {
const networkConfig = getState().network;
getAccount({ networkConfig, address }).then((response) => {
const accountData = {
...response,
};
if (accountData.publicKey) {
dispatch(searchVoters({
address, publicKey: accountData.publicKey, offset, limit, append: true,
}));
}
});
};

export const searchAccount = ({ address }) =>
(dispatch, getState) => {
const networkConfig = getState().network;
Expand All @@ -139,22 +98,22 @@ export const searchAccount = ({ address }) =>
...response,
};
if (accountData.delegate && accountData.delegate.username) {
dispatch(searchDelegate({ publicKey: accountData.publicKey, address }));
dispatch(searchVoters({ address, publicKey: accountData.publicKey }));
searchDelegate({ publicKey: accountData.publicKey, address })(dispatch, getState);
}
dispatch({ data: accountData, type: actionTypes.searchAccount });
dispatch(updateWallet(response, getState().peers));
dispatch(searchVotes({ address, offset: 0, limit: 101 }));
searchVotes({ address, offset: 0, limit: 101 })(dispatch, getState);
});
}
};

export const searchTransactions = ({
address, limit, filter, showLoading = true, customFilters = {},
actionType = actionTypes.searchTransactions,
}) =>
(dispatch, getState) => {
const networkConfig = getState().network;
if (showLoading) dispatch(loadingStarted(actionTypes.searchTransactions));
if (showLoading) dispatch(loadingStarted(actionType));
/* istanbul ignore else */
if (networkConfig) {
getTransactions({
Expand All @@ -169,9 +128,9 @@ export const searchTransactions = ({
filter,
customFilters,
},
type: actionTypes.searchTransactions,
type: actionType,
});
if (filter !== undefined) {
if (filter !== undefined && actionType === actionTypes.searchTransactions) {
dispatch({
data: {
filterName: 'transactions',
Expand All @@ -180,34 +139,17 @@ export const searchTransactions = ({
type: actionTypes.addFilter,
});
}
if (showLoading) dispatch(loadingFinished(actionTypes.searchTransactions));
if (showLoading) dispatch(loadingFinished(actionType));
});
}
};

export const searchMoreTransactions = ({
address, limit, offset, filter, customFilters = {},
}) =>
(dispatch, getState) => {
const networkConfig = getState().network;
dispatch(loadingStarted(actionTypes.searchMoreTransactions));
getTransactions({
networkConfig, address, limit, offset, filter, customFilters,
})
.then((transactionsResponse) => {
dispatch({
data: {
address,
transactions: transactionsResponse.data,
count: parseInt(transactionsResponse.meta.count, 10),
filter,
customFilters,
},
type: actionTypes.searchMoreTransactions,
});
dispatch(loadingFinished(actionTypes.searchMoreTransactions));
});
};
export const searchMoreTransactions = params => (
searchTransactions({
...params,
actionType: actionTypes.searchMoreTransactions,
})
);

export const clearSearchSuggestions = () => ({
data: {},
Expand Down
36 changes: 0 additions & 36 deletions src/actions/search.test.js
Expand Up @@ -14,7 +14,6 @@ const {
searchTransactions,
searchAccount,
searchSuggestions,
searchMoreVoters,
} = actions;

jest.mock('../utils/api/search');
Expand Down Expand Up @@ -50,41 +49,6 @@ describe('actions: search', () => {
});
});

it('should call to searchMoreVoters no publicKey', () => {
accountAPI.getAccount.mockResolvedValue({ publicKey: null });
const address = '123L';
const offset = 0;
const limit = 100;
const action = searchMoreVoters({ address, offset, limit });
action(dispatch, getState);
expect(dispatch).not.toHaveBeenCalledWith();
});

it('should call to searchMoreVoters no publicKey offset or limit', () => {
accountAPI.getAccount.mockResolvedValue({ publicKey: null });
const address = '123L';
const action = searchMoreVoters({ address });
action(dispatch, getState);
expect(dispatch).not.toHaveBeenCalledWith();
});

it('should call to searchMoreVoters no offset or limit', () => {
const publicKey = 'my-key';
accountAPI.getAccount.mockResolvedValue({ publicKey });
delegateAPI.getVoters.mockResolvedValue({
data: { voters: [] },
});
const address = '123L';
const action = searchMoreVoters({ address });
action(dispatch, getState);
expect(dispatch).not.toHaveBeenCalledWith({
type: actionTypes.searchVoters,
data: {
voters: [],
},
});
});

describe('fetchVotedDelegateInfo', () => {
const delegates = {
data: [{
Expand Down
2 changes: 0 additions & 2 deletions src/components/extensionPoint/extensionPoint.js
Expand Up @@ -17,7 +17,6 @@ export default class ExtensionPoint extends React.Component {
transactionsFilterSet,
searchDelegate,
searchVotes,
searchVoters,
searchAccount,
searchTransactions,
} = this.props;
Expand Down Expand Up @@ -47,7 +46,6 @@ export default class ExtensionPoint extends React.Component {
transactionsFilterSet,
searchDelegate,
searchVotes,
searchVoters,
searchAccount,
searchTransactions,
}}
Expand Down
2 changes: 0 additions & 2 deletions src/components/extensionPoint/index.js
Expand Up @@ -11,7 +11,6 @@ import {
import {
searchDelegate,
searchVotes,
searchVoters,
searchAccount,
searchTransactions,
} from '../../actions/search';
Expand All @@ -34,7 +33,6 @@ const mapDispatchToProps = {
transactionsFilterSet,
searchDelegate,
searchVotes,
searchVoters,
searchAccount,
searchTransactions,
};
Expand Down
16 changes: 0 additions & 16 deletions src/components/transactions/accountList.js
Expand Up @@ -11,13 +11,8 @@ class AccountList extends React.Component {
super(props);
this.state = {
showVotesNumber: 35,
showVotersNumber: 35,
showMoreVoters: true,
votersOffset: 100,
loadAllVotes: false,
votersFilterQuery: '',
votesFilterQuery: '',
votersSize: (props.voters && props.voters.length) || 0,
votesSize: (props.votes && props.votes.length) || 0,
};
}
Expand All @@ -27,17 +22,6 @@ class AccountList extends React.Component {
this.setState({ [name]: newAmount });
}

searchMoreVoters() {
if (this.state.votersOffset < this.props.votersSize) {
this.props.searchMoreVoters(this.state.votersOffset);
const votersOffset = this.state.votersOffset + 100;
this.setState({
votersOffset,
showMoreVoters: false,
});
}
}

filterList(data, filterQuery) {
if (this.state[filterQuery] !== '') {
data = data.filter((obj) => {
Expand Down