-
Notifications
You must be signed in to change notification settings - Fork 96
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
isalga
merged 26 commits into
feature/blockchain-application
from
4358-explore-apps-statistics
Jul 5, 2022
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5b04b39
Add component and screen structure
cbcb459
Add tooltips
63d457d
Create api util
7584902
Add TODO dependency on api call
2f80124
Add unit test
1f6967c
Add icons
5de3f97
Adjust styles
38eb961
Fix lint
c1ff1cd
Adjust chart styles and options
2728502
Add coverage expections
c3db070
Merge branch 'feature/blockchain-agnostic-new' into 4358-explore-apps…
9f04e0a
Increase e2e wait time
1a79d69
Merge branch 'feature/blockchain-agnostic-new' into 4358-explore-apps…
96218f5
Merge branch 'feature/blockchain-application' into 4358-explore-apps-…
5fdf0a3
Merge remote-tracking branch 'origin/feature/blockchain-application' …
e66b84e
Add alias
94d8692
remove old routesMap
7d0911d
PR feedback
72c6f5f
Update unit test
a0c7460
Merge branch 'feature/blockchain-application' into 4358-explore-apps-…
70fb743
PR feedback
ba91519
Fix test and lint
847c7d3
Add unit tests
727d36c
Ignore branch coverage
cc2e75a
Lint issues
799a3ab
PR feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
}); | ||
35 changes: 35 additions & 0 deletions
35
src/modules/blockchainApplication/explore/api/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getState } from '@fixtures/transactions'; | ||
import http from 'src/utils/api/http'; | ||
import { getStatistics } from '.'; | ||
|
||
jest.mock('src/utils/api/http', () => | ||
jest.fn().mockImplementation(() => Promise.resolve({ | ||
data: { | ||
registered: 2503, | ||
active: 2328, | ||
terminated: 35, | ||
totalSupplyLSK: '5000000', | ||
stakedLSK: '3000000', | ||
inflationRate: '4.50', | ||
}, | ||
}))); | ||
|
||
const baseUrl = 'http://custom-base-url.com/'; | ||
const { network } = getState(); | ||
|
||
describe('get blockchain application statistics', () => { | ||
it('Should call http with given params', () => { | ||
getStatistics({ | ||
network, | ||
baseUrl, | ||
params: { }, | ||
}); | ||
|
||
expect(http).toHaveBeenCalledWith({ | ||
path: '/api/v2/blockchain/apps/statistics', | ||
params: { }, | ||
network, | ||
baseUrl, | ||
}); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
...on/explore/components/BlockchainApplicationStatistics/blockchainApplicationStatistics.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
@import '../../../../../../setup/react/app/mixins.css'; | ||
|
||
.container { | ||
max-width: 350px; | ||
|
||
& > header { | ||
padding-bottom: 22px; | ||
} | ||
|
||
& > div { | ||
margin-bottom: 16px; | ||
} | ||
} | ||
|
||
.chartBox { | ||
padding: 16px 0px !important; | ||
} | ||
|
||
.statsBox { | ||
flex-direction: row !important; | ||
justify-content: space-between !important; | ||
|
||
& > div { | ||
&:first-child { | ||
flex-basis: 70%; | ||
} | ||
|
||
&:last-child { | ||
flex-basis: 30%; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
} | ||
} | ||
|
||
.statsInfoTitle { | ||
@mixin contentLarge; | ||
|
||
color: var(--color-blue-gray); | ||
} | ||
|
||
.statsInfo { | ||
@mixin headingNormalIntermediate; | ||
|
||
color: var(--color-maastricht-blue); | ||
margin: 8px 0 0; | ||
} |
26 changes: 26 additions & 0 deletions
26
...xplore/components/BlockchainApplicationStatistics/blockchainApplicationStatistics.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import BlockchainApplicationStatistics from './index'; | ||
|
||
describe('BlockchainApplicationStatistics', () => { | ||
const props = { | ||
statistics: { | ||
data: { | ||
registered: 101, | ||
active: 53, | ||
terminated: 9, | ||
totalSupplyLSK: '5000000', | ||
stakedLSK: '3000000', | ||
}, | ||
}, | ||
}; | ||
|
||
it('should properly', () => { | ||
const wrapper = mount(<BlockchainApplicationStatistics {...props} />); | ||
|
||
expect(wrapper.find('.statsInfoTitle').at(0)).toHaveText('Total Supply'); | ||
expect(wrapper.find('.statsInfoTitle').at(1)).toHaveText('Staked'); | ||
expect(wrapper.find('TokenAmount').at(0)).toHaveText('5,000,000'); | ||
expect(wrapper.find('TokenAmount').at(1)).toHaveText('3,000,000'); | ||
}); | ||
}); |
69 changes: 69 additions & 0 deletions
69
...modules/blockchainApplication/explore/components/BlockchainApplicationStatistics/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { toRawLsk } from '@token/fungible/utils/lsk'; | ||
import Box from 'src/theme/box'; | ||
import BoxHeader from 'src/theme/box/header'; | ||
import BoxContent from 'src/theme/box/content'; | ||
import { DoughnutChart } from 'src/modules/common/components/charts'; | ||
import TokenAmount from '@token/fungible/components/tokenAmount'; | ||
import Tooltip from 'src/theme/Tooltip'; | ||
import Icon from 'src/theme/Icon'; | ||
import { useTheme } from 'src/theme/Theme'; | ||
import { getColorPalette } from 'src/modules/common/components/charts/chartOptions'; | ||
import prepareChartDataAndOptions from '../../utils/prepareChartDataAndOptions'; | ||
import styles from './blockchainApplicationStatistics.css'; | ||
|
||
const BlockchainApplicationStatistics = ({ statistics }) => { | ||
const { t } = useTranslation(); | ||
const colorPalette = getColorPalette(useTheme()); | ||
const { | ||
doughnutChartData, doughnutChartOptions, | ||
} = prepareChartDataAndOptions(statistics.data, colorPalette, t); | ||
const cardsMap = [ | ||
{ | ||
title: t('Total Supply'), description: t('Total LSK tokens in circulation'), amount: toRawLsk(statistics.data.totalSupplyLSK), icon: 'totalSupplyToken', | ||
}, | ||
{ | ||
title: t('Staked'), description: t('Amount of LSK tokens staked by validators and nominators for DPoS governance'), amount: toRawLsk(statistics.data.stakedLSK), icon: 'stackedToken', | ||
}, | ||
]; | ||
|
||
return ( | ||
<Box className={styles.container}> | ||
<BoxHeader> | ||
<h1>{t('Statistics')}</h1> | ||
</BoxHeader> | ||
<BoxContent className={styles.chartBox}> | ||
<DoughnutChart | ||
data={doughnutChartData} | ||
options={doughnutChartOptions} | ||
/> | ||
</BoxContent> | ||
{cardsMap.map(({ | ||
title, description, amount, icon, | ||
}) => ( | ||
<BoxContent | ||
key={`app-stats-card-${icon}`} | ||
className={styles.statsBox} | ||
> | ||
<div> | ||
<div> | ||
<span className={styles.statsInfoTitle}>{title}</span> | ||
<Tooltip size="m" position="bottom"> | ||
<p>{description}</p> | ||
</Tooltip> | ||
</div> | ||
<p className={styles.statsInfo}> | ||
<TokenAmount val={amount} /> | ||
</p> | ||
</div> | ||
<div> | ||
<Icon name={icon} /> | ||
</div> | ||
</BoxContent> | ||
))} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default BlockchainApplicationStatistics; |
39 changes: 39 additions & 0 deletions
39
src/modules/blockchainApplication/explore/utils/prepareChartDataAndOptions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const prepareChartDataAndOptions = (statistics, colorPalette, t) => { | ||
const doughnutChartData = { | ||
labels: [ | ||
t('Registered'), | ||
t('Active'), | ||
t('Terminated'), | ||
], | ||
datasets: [ | ||
{ | ||
backgroundColor: [colorPalette[1], colorPalette[0], colorPalette[2]], | ||
data: [statistics.registered, statistics.active, statistics.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, | ||
}, | ||
}, | ||
}; | ||
|
||
return { doughnutChartData, doughnutChartOptions }; | ||
}; | ||
|
||
export default prepareChartDataAndOptions; |
47 changes: 47 additions & 0 deletions
47
src/modules/blockchainApplication/explore/utils/prepareChartDataAndOptions.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import prepareChartDataAndOptions from './prepareChartDataAndOptions'; | ||
|
||
describe('BlockchainApplication explore utils', () => { | ||
it('Should return correct data when calling prepareChartDataAndOptions', () => { | ||
const statistics = { | ||
registered: 101, | ||
active: 53, | ||
terminated: 9, | ||
totalSupplyLSK: '5000000', | ||
stakedLSK: '3000000', | ||
}; | ||
const colorPalette = ['green', 'blue', 'grey']; | ||
const t = (l) => l; | ||
const { | ||
doughnutChartData, doughnutChartOptions, | ||
} = prepareChartDataAndOptions(statistics, colorPalette, t); | ||
|
||
expect(doughnutChartData).toEqual({ | ||
labels: ['Registered', 'Active', 'Terminated'], | ||
datasets: [ | ||
{ | ||
backgroundColor: ['blue', 'green', 'grey'], | ||
data: [statistics.registered, statistics.active, statistics.terminated], | ||
}, | ||
], | ||
}); | ||
expect(doughnutChartOptions).toEqual({ | ||
cutoutPercentage: 70, | ||
legend: { | ||
display: true, | ||
position: 'left', | ||
align: 'start', | ||
labels: { | ||
padding: 20, | ||
}, | ||
}, | ||
layout: { | ||
padding: { | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
top: 0, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
src/modules/blockchainApplication/manage/components/ManageBlockchainApplications/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* istanbul ignore file */ | ||
import React from 'react'; | ||
import BlockchainApplicationStatistics from '../../../explore/components/BlockchainApplicationStatistics'; | ||
|
||
const ManageBlockchainAppications = ({ apps, statistics }) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please improve naming apps is so general, also it dosnt need it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How I should rename it? |
||
<BlockchainApplicationStatistics apps={apps} statistics={statistics} /> | ||
); | ||
|
||
export default ManageBlockchainAppications; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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