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

Add explore apps statistics component - Closes #4358 #4370

Merged
merged 26 commits into from
Jul 5, 2022

Conversation

isalga
Copy link
Contributor

@isalga isalga commented Jun 28, 2022

What was the problem?

This PR resolves #4358

How was it solved?

  • Create component
  • Add component to scaffolded page
  • Mock API call

How was it tested?

Add unit test

@isalga isalga self-assigned this Jun 28, 2022
@isalga isalga changed the base branch from development to feature/blockchain-agnostic-new June 28, 2022 13:55
*
* @returns {Promise}
*/
export const getStatistics = () => Promise.resolve({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the end point and make the api call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We agreed to mock it and API call is not ready. It should be done after this ticket. LiskArchive/lisk-service#1113

I suggest creating a ticket to unmock the api call (Which is written but comented)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the api call here but inside the component use the mock not the api response check @eniolam1000752 pr

datasets: [
{
backgroundColor: [colorPalette[1], colorPalette[0], colorPalette[2]],
data: apps.data.reduce((acc, stats) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? the api response it will give us the data

{  
"data":  {    
   "registered": 2503,
    "active": 2328, 
   "terminated": 35,
    “totalSupplyLSK”: “5000000”, 
   “stakedLSK”: “3000000”, 
   “inflationRate”: “4.50”, 
 }, 
  "meta": {}, 
 "links": {}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 callls, 1 for apps list and other for apps. We have to iterate the apps list to get the status and generate the status map. As far as I understood

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please go over the end point and check it one more time,

api is providing the application count based on the status
"registered": 2503, "active": 2328, "terminated": 35,

import React from 'react';
import BlockchainApplicationStatistics from '../../../explore/components/BlockchainApplicationStatistics';

const ManageBlockchainAppications = ({ apps, statistics }) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please improve naming apps is so general, also it dosnt need it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How I should rename it?

@soroushm soroushm changed the base branch from feature/blockchain-agnostic-new to feature/blockchain-application July 1, 2022 12:08
@isalga isalga requested a review from eniolam1000752 July 4, 2022 07:38
@isalga isalga changed the base branch from feature/blockchain-application to development July 4, 2022 07:53
@isalga isalga marked this pull request as ready for review July 4, 2022 07:53
@isalga isalga changed the base branch from development to feature/blockchain-application July 4, 2022 08:03
@isalga isalga requested a review from soroushm July 4, 2022 09:01
*
* @returns {Promise}
*/
export const getApps = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused apps

@@ -0,0 +1,49 @@
/* istanbul ignore file */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file should be go to /blockchainApplication/explore/api

@@ -0,0 +1,25 @@
/* istanbul ignore file */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the component file from index to BlockchainApplicationStatistics

Comment on lines 20 to 52
const doughnutChartData = {
labels: [
t('Registered'),
t('Active'),
t('Terminated'),
],
datasets: [
{
backgroundColor: [colorPalette[1], colorPalette[0], colorPalette[2]],
data: [statistics.data.registered, statistics.data.active, statistics.data.terminated],
},
],
};

const doughnutChartOptions = {
cutoutPercentage: 70,
legend: {
display: true,
position: 'left',
align: 'start',
labels: {
padding: 20,
},
},
layout: {
padding: {
left: 0,
right: 0,
bottom: 0,
top: 0,
},
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the part to utils and keep the component clean

Suggested change
const doughnutChartData = {
labels: [
t('Registered'),
t('Active'),
t('Terminated'),
],
datasets: [
{
backgroundColor: [colorPalette[1], colorPalette[0], colorPalette[2]],
data: [statistics.data.registered, statistics.data.active, statistics.data.terminated],
},
],
};
const doughnutChartOptions = {
cutoutPercentage: 70,
legend: {
display: true,
position: 'left',
align: 'start',
labels: {
padding: 20,
},
},
layout: {
padding: {
left: 0,
right: 0,
bottom: 0,
top: 0,
},
},
};
const {doughnutChartData, doughnutChartOptions} = prepareChartDataAndOptions(data, colorPalette)

<p className={`${styles.statsInfo} stacked-token`}>
<TokenAmount
val={toRawLsk(statistics.data.stakedLSK)}
token={tokenMap.LSK.key}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the LSK map here they are deprecated and non-related to here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how we pass the token? If we don't pass token it will display '5,000,000' instead of '5,000,000 LSK(or other token)' as it is in design

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just prefer to use a constant for those things, but now tokenMap is fine

@eniolam1000752
Copy link
Contributor

Please Resolve merge conflicts :)

@isalga isalga requested a review from soroushm July 5, 2022 10:01
Comment on lines +1 to +27
/* istanbul ignore file */
import http from 'src/utils/api/http';
import { HTTP_PREFIX } from 'src/const/httpCodes';

const httpPaths = {
blockchainAppsStatistics: `${HTTP_PREFIX}/blockchain/apps/statistics`,
};

/**
* Retrieves sidechains statistics information
*
* @param {Object} data
* @param {Object} data.network The network config from the Redux store
*
* @returns {Promise}
*/
// eslint-disable-next-line import/prefer-default-export
export const getStatistics = ({
network,
params = {},
baseUrl,
}) => http({
path: httpPaths.blockchainAppsStatistics,
network,
params,
baseUrl,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a unit test

Comment on lines 20 to 23

expect(wrapper.find('TokenAmount').at(0)).toHaveText('5,000,000');
expect(wrapper.find('TokenAmount').at(1)).toHaveText('3,000,000');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can add an extra assertion to check if Total Supply and Staked text render properly
image

@@ -0,0 +1,38 @@
// eslint-disable-next-line import/prefer-default-export
export const prepareChartDataAndOptions = (statistics, colorPalette, t) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can have a unit test for this function

@isalga isalga requested a review from eniolam1000752 July 5, 2022 11:28
const baseUrl = 'http://custom-base-url.com/';
const { network } = getState();

describe('get blockchain application detail', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be

Suggested change
describe('get blockchain application detail', () => {
describe('get blockchain application statistics', () => {

Comment on lines 6 to 8
<>
<BlockchainApplicationStatistics apps={apps} statistics={statistics} />
</>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a need for fragments(<>) here

@@ -0,0 +1,38 @@
// eslint-disable-next-line import/prefer-default-export
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have the file name equal to the function so its easier to find it,

@isalga isalga requested review from soroushm and eniolam1000752 July 5, 2022 12:31
@isalga isalga merged commit 812bbed into feature/blockchain-application Jul 5, 2022
@isalga isalga deleted the 4358-explore-apps-statistics branch July 5, 2022 13:44
soroushm pushed a commit that referenced this pull request Jul 5, 2022
* Add component and screen structure

* Add tooltips

* Create api util

* Add TODO dependency on api call

* Add unit test

* Add icons

* Adjust styles

* Fix lint

* Adjust chart styles and options

* Add coverage expections

* Increase e2e wait time

* Add alias

* remove old routesMap

* PR feedback

* Update unit test

* PR feedback

* Fix test and lint

* Add unit tests

* Ignore branch coverage

* Lint issues

* PR feedback
eniolam1000752 pushed a commit that referenced this pull request Jul 6, 2022
* Add component and screen structure

* Add tooltips

* Create api util

* Add TODO dependency on api call

* Add unit test

* Add icons

* Adjust styles

* Fix lint

* Adjust chart styles and options

* Add coverage expections

* Increase e2e wait time

* Add alias

* remove old routesMap

* PR feedback

* Update unit test

* PR feedback

* Fix test and lint

* Add unit tests

* Ignore branch coverage

* Lint issues

* PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Create a component for exploring applications statistics
3 participants