-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from topmonks/Chain-dashboard-asset-value-chart
Chain dashboard asset value chart
- Loading branch information
Showing
22 changed files
with
563 additions
and
65 deletions.
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
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.
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.
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
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,128 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { css } from "@emotion/react"; | ||
|
||
import Block from "../../assets/block.svg"; | ||
import Signed from "../../assets/signed.svg"; | ||
import Nominator from "../../assets/nominator.svg"; | ||
import Validator from "../../assets/validator.svg"; | ||
import Inflation from "../../assets/inflation.svg"; | ||
import StakingReward from "../../assets/staking-reward.svg"; | ||
|
||
import { Resource } from "../../model/resource"; | ||
import { Stats } from "../../model/stats"; | ||
import { getNetwork } from "../../services/networksService"; | ||
|
||
import { ErrorMessage } from "../ErrorMessage"; | ||
import Loading from "../Loading"; | ||
import NotFound from "../NotFound"; | ||
|
||
const statStyle = css` | ||
min-width: 100px; | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
const statIconStyle = css` | ||
width: 44px; | ||
height: 44px; | ||
margin-right: 10px; | ||
padding: 10px; | ||
`; | ||
|
||
const statTitleStyle = css` | ||
font-weight: 900; | ||
margin-top: auto; | ||
`; | ||
|
||
const statValueStyle = css` | ||
font-weight: 500; | ||
height: 32px; | ||
`; | ||
|
||
const statsLayoutStyle = css` | ||
display: grid; | ||
width: 100%; | ||
height: auto; | ||
gap: 10px; | ||
grid-template-columns: repeat(2, auto); | ||
@media (max-width: 530px) { | ||
grid-template-columns: repeat(1, auto); | ||
} | ||
`; | ||
|
||
type StatItemProps = { | ||
title: string; | ||
icon?: string; | ||
value?: string | number; | ||
}; | ||
|
||
const StatItem = (props: StatItemProps) => { | ||
const { | ||
title, | ||
value, | ||
icon, | ||
} = props; | ||
|
||
return ( | ||
<div css={statStyle}> | ||
<img css={statIconStyle} src={icon} /> | ||
<div style={{display: "flex", flexDirection: "column", justifyContent: "center" }}> | ||
<div css={statTitleStyle}>{title}</div> | ||
<div css={statValueStyle}>{value}</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export type NetworkInfoTableProps = { | ||
stats: Resource<Stats>; | ||
networkName: string; | ||
} | ||
|
||
export const NetworkStats = (props: NetworkInfoTableProps) => { | ||
const { stats, networkName } = props; | ||
|
||
const network = getNetwork(networkName); | ||
|
||
if (stats.loading) { | ||
return <Loading />; | ||
} | ||
|
||
if (stats.notFound) { | ||
return <NotFound>Stats not found.</NotFound>; | ||
} | ||
|
||
if (stats.error) { | ||
return ( | ||
<ErrorMessage | ||
message="Unexpected error occured while fetching data" | ||
details={stats.error.message} | ||
showReported | ||
/> | ||
); | ||
} | ||
|
||
if (!stats.data || !network) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div css={statsLayoutStyle}> | ||
<StatItem title="Finalized blocks" value={stats.data.chainFinalizedBlocks} icon={Block} /> | ||
<StatItem title="Signed extrinsics" value={stats.data.chainSignedExtrinsics} icon={Signed} /> | ||
<StatItem title="Staking inflation" value={`${stats.data.stakingInflationRatio.toFixed(1)}%`} icon={Inflation} /> | ||
<StatItem title="Staking rewards" value={`${stats.data.stakingRewardsRatio.toFixed(1)}%`} icon={StakingReward} /> | ||
<StatItem | ||
title="Validators" | ||
value={`${stats.data.stakingActiveValidatorsAmount}/${stats.data.stakingValidatorsIdealAmount}`} | ||
icon={Validator} | ||
/> | ||
<StatItem title="Nomination pools" value={`${stats.data.nominationPoolsPoolsActiveAmount}`} icon={Nominator} /> | ||
</div> | ||
); | ||
}; |
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,91 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { HTMLAttributes } from "react"; | ||
import { css } from "@emotion/react"; | ||
|
||
import { Resource } from "../../model/resource"; | ||
import { Stats } from "../../model/stats"; | ||
import { Network } from "../../model/network"; | ||
import { formatNumber } from "../../utils/number"; | ||
|
||
import { ErrorMessage } from "../ErrorMessage"; | ||
import Loading from "../Loading"; | ||
import NotFound from "../NotFound"; | ||
|
||
import { NetworkTokenDistributionChart } from "./NetworkTokenDistributionChart"; | ||
|
||
export const valueStyle = css` | ||
min-width: 70px; | ||
display: flex; | ||
max-width: 230px; | ||
margin: 0 auto; | ||
`; | ||
|
||
export const valueTypeStyle = css` | ||
margin-bottom: 8px; | ||
font-weight: 700; | ||
flex: 1 1 auto; | ||
`; | ||
|
||
export const separatorStyle = css` | ||
display: block; | ||
width: 1px; | ||
flex: 0 0 auto; | ||
background-color: rgba(0, 0, 0, .125); | ||
`; | ||
|
||
export const notFoundStyle = css` | ||
margin: 0 auto; | ||
margin-top: 32px; | ||
`; | ||
|
||
export const chartStyle = css` | ||
margin: 0 auto; | ||
margin-top: 32px; | ||
`; | ||
|
||
export type NetworkTokenDistributionProps = HTMLAttributes<HTMLDivElement> & { | ||
stats: Resource<Stats>; | ||
network: Network; | ||
}; | ||
|
||
export const NetworkTokenDistribution = (props: NetworkTokenDistributionProps) => { | ||
const {stats, network} = props; | ||
|
||
if (stats.loading) { | ||
return <Loading />; | ||
} | ||
|
||
if (stats.notFound) { | ||
return <NotFound css={notFoundStyle}>No stats data found</NotFound>; | ||
} | ||
|
||
if (stats.error) { | ||
return ( | ||
<ErrorMessage | ||
message="Unexpected error occured while fetching data" | ||
details={stats.error.message} | ||
showReported | ||
/> | ||
); | ||
} | ||
|
||
if (!stats.data) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<div css={valueStyle}> | ||
<div css={valueTypeStyle}>Total issuance</div> | ||
<div>{formatNumber(stats.data.balancesTotalIssuance, {compact: true})}</div> | ||
</div> | ||
</div> | ||
<NetworkTokenDistributionChart | ||
css={chartStyle} | ||
stats={stats.data} | ||
network={network} | ||
/> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.