Skip to content

Commit

Permalink
Merge pull request #3996 from LiskHQ/3973-add-ineligible-delegates-to…
Browse files Browse the repository at this point in the history
…-outside-round

Add ineligible delegates to outside round - Closes #3973
  • Loading branch information
reyraa authored Dec 7, 2021
2 parents 0c1fa76 + 4306bf9 commit 60cc027
Showing 1 changed file with 93 additions and 76 deletions.
169 changes: 93 additions & 76 deletions src/components/screens/monitor/delegates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ const defaultUrlSearchParams = { search: '' };
* @param {Array} oldData - The old data array
* @returns {Array} Array build by merging the given two arrays
*/
const mergeUniquely = (key, newData, oldData = []) => (
[...oldData, ...newData.data.filter(
newItem => !oldData.find(oldItem => oldItem[key] === newItem[key]),
)]
);
const mergeUniquely = (key, newData, oldData = []) => [
...oldData,
...newData.data.filter(
(newItem) => !oldData.find((oldItem) => oldItem[key] === newItem[key]),
),
];
const mergeUniquelyByUsername = mergeUniquely.bind(this, 'username');
const mergeUniquelyById = mergeUniquely.bind(this, 'id');

Expand All @@ -36,107 +37,123 @@ const mergeUniquelyById = mergeUniquely.bind(this, 'id');
* retrieve in-round delegates
*/
const stripAccountDataAndMerge = (response, oldData = []) => {
response.data = response.data.map(del => ({
response.data = response.data.map((del) => ({
address: del.summary.address,
...del.dpos.delegate,
}));
return mergeUniquelyByUsername(response, oldData);
};

const mapStateToProps = state => ({
const mapStateToProps = (state) => ({
watchList: state.watchList,
blocks: state.blocks,
});

const ComposedDelegates = compose(
withRouter,
connect(mapStateToProps),
withData(
{
standByDelegates: {
apiUtil: (network, params) => getDelegates({
withData({
standByDelegates: {
apiUtil: (network, params) =>
getDelegates({
network,
params: {
...params,
limit: params.limit || DEFAULT_LIMIT,
status: 'standby,non-eligible',
},
}),
defaultData: [],
autoload: true,
transformResponse: stripAccountDataAndMerge,
},
defaultData: [],
autoload: true,
transformResponse: stripAccountDataAndMerge,
},

delegatesCount: {
apiUtil: network => getDelegates({ network, params: { limit: 1 } }),
defaultData: 0,
autoload: true,
transformResponse: response => response.meta.total,
},
delegatesCount: {
apiUtil: (network) => getDelegates({ network, params: { limit: 1 } }),
defaultData: 0,
autoload: true,
transformResponse: (response) => response.meta.total,
},

transactionsCount: {
apiUtil: network => getTransactions({ network, params: { limit: 1 } }, tokenMap.LSK.key),
defaultData: 0,
autoload: true,
transformResponse: response => response.meta.total,
},
transactionsCount: {
apiUtil: (network) =>
getTransactions({ network, params: { limit: 1 } }, tokenMap.LSK.key),
defaultData: 0,
autoload: true,
transformResponse: (response) => response.meta.total,
},

registrations: {
apiUtil: network => getRegisteredDelegates({
network,
}, tokenMap.LSK.key),
defaultData: [],
autoload: true,
},
registrations: {
apiUtil: (network) =>
getRegisteredDelegates(
{
network,
},
tokenMap.LSK.key,
),
defaultData: [],
autoload: true,
},

votes: {
apiUtil: (network, params) => getTransactions({
network,
params: { ...params, moduleAssetId: MODULE_ASSETS_NAME_ID_MAP.voteDelegate, sort: 'timestamp:desc' },
}, tokenMap.LSK.key),
getApiParams: state => ({ token: state.settings.token.active }),
autoload: true,
defaultData: [],
transformResponse: mergeUniquelyById,
},
votes: {
apiUtil: (network, params) =>
getTransactions(
{
network,
params: {
...params,
moduleAssetId: MODULE_ASSETS_NAME_ID_MAP.voteDelegate,
sort: 'timestamp:desc',
},
},
tokenMap.LSK.key,
),
getApiParams: (state) => ({ token: state.settings.token.active }),
autoload: true,
defaultData: [],
transformResponse: mergeUniquelyById,
},

networkStatus: {
apiUtil: network => getNetworkStatus({ network }),
defaultData: {},
autoload: true,
transformResponse: response => response,
},
networkStatus: {
apiUtil: (network) => getNetworkStatus({ network }),
defaultData: {},
autoload: true,
transformResponse: (response) => response,
},

sanctionedDelegates: {
apiUtil: (network, params) => getDelegates({ network, params: { ...params, status: 'punished,banned' } }),
defaultData: [],
autoload: true,
transformResponse: stripAccountDataAndMerge,
},
sanctionedDelegates: {
apiUtil: (network, params) =>
getDelegates({
network,
params: { ...params, status: 'punished,banned' },
}),
defaultData: [],
autoload: true,
transformResponse: stripAccountDataAndMerge,
},

votedDelegates: {
apiUtil: ({ networks }, params) =>
getDelegates({ network: networks.LSK, params }),
defaultData: {},
transformResponse: (response) => {
const transformedResponse = mergeUniquelyByUsername(response);
const responseMap = transformedResponse.reduce((acc, delegate) => {
acc[delegate.address] = delegate.summary?.address;
return acc;
}, {});
return responseMap;
},
votedDelegates: {
apiUtil: ({ networks }, params) =>
getDelegates({ network: networks.LSK, params }),
defaultData: {},
transformResponse: (response) => {
const transformedResponse = mergeUniquelyByUsername(response);
const responseMap = transformedResponse.reduce((acc, delegate) => {
acc[delegate.address] = delegate.summary?.address;
return acc;
}, {});
return responseMap;
},
},

watchedDelegates: {
apiUtil: ({ networks }, params) =>
getDelegates({ network: networks.LSK, params }),
defaultData: [],
getApiParams: state => ({ addressList: state.watchList }),
transformResponse: stripAccountDataAndMerge,
},
watchedDelegates: {
apiUtil: ({ networks }, params) =>
getDelegates({ network: networks.LSK, params }),
defaultData: [],
getApiParams: (state) => ({ addressList: state.watchList }),
transformResponse: stripAccountDataAndMerge,
},
),
}),
withFilters('standByDelegates', defaultUrlSearchParams),
withTranslation(),
)(Delegates);
Expand Down

0 comments on commit 60cc027

Please sign in to comment.