-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display principal rep threshold on network section & representa…
…tives page (closes #92)
- Loading branch information
Showing
6 changed files
with
164 additions
and
56 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
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import { connect } from 'react-redux' | ||
import { createSelector } from 'reselect' | ||
|
||
import { getNetwork } from '@core/network' | ||
import { | ||
getNetwork, | ||
get_principal_representative_minimum_weight | ||
} from '@core/network' | ||
|
||
import RepresentativesWeight from './representatives-weight' | ||
|
||
const mapStateToProps = createSelector(getNetwork, (network) => ({ network })) | ||
const mapStateToProps = createSelector( | ||
getNetwork, | ||
get_principal_representative_minimum_weight, | ||
(network, principal_representative_minimum_weight) => ({ | ||
network, | ||
principal_representative_minimum_weight | ||
}) | ||
) | ||
|
||
export default connect(mapStateToProps)(RepresentativesWeight) |
138 changes: 91 additions & 47 deletions
138
src/views/components/representatives-weight/representatives-weight.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 |
---|---|---|
@@ -1,61 +1,105 @@ | ||
import React from 'react' | ||
import React, { useMemo } from 'react' | ||
import BigNumber from 'bignumber.js' | ||
import ImmutablePropTypes from 'react-immutable-proptypes' | ||
|
||
import './representatives-weight.styl' | ||
|
||
export default class RepresentativesWeight extends React.Component { | ||
render() { | ||
const { network } = this.props | ||
const onlineWeight = BigNumber( | ||
network.getIn(['weight', 'onlineWeight', 'median'], 0) | ||
) | ||
const trendedWeight = BigNumber( | ||
network.getIn(['weight', 'trendedWeight', 'median'], 0) | ||
) | ||
const quorumTotal = BigNumber.max(onlineWeight, trendedWeight) | ||
const quorumWeightDelta = quorumTotal.multipliedBy(0.67) | ||
|
||
const onlineSelected = onlineWeight.isGreaterThan(trendedWeight) | ||
|
||
const onlineNano = onlineWeight.shiftedBy(-36) | ||
const trendedNano = trendedWeight.shiftedBy(-36) | ||
const quorumNano = quorumWeightDelta.shiftedBy(-36) | ||
return ( | ||
<div className='representatives__weight-container'> | ||
<div className='representatives__weight'> | ||
<div | ||
className={`representatives__weight-section ${ | ||
!onlineSelected && 'selected' | ||
}`}> | ||
<div className='representatives__weight-section-label'>Trended</div> | ||
<div className='representatives__weight-section-value'> | ||
{trendedNano.isNaN() ? '-' : `${trendedNano.toFormat(1)}M`} | ||
</div> | ||
import { format_value } from '@core/utils' | ||
|
||
export default function RepresentativesWeight({ | ||
network, | ||
principal_representative_minimum_weight | ||
}) { | ||
const pr_min_weight = useMemo(() => { | ||
return principal_representative_minimum_weight | ||
? format_value({ | ||
value: BigNumber(principal_representative_minimum_weight) | ||
.shiftedBy(-30) | ||
.toNumber() | ||
}) | ||
: '-' | ||
}, [principal_representative_minimum_weight]) | ||
|
||
const online_weight = useMemo( | ||
() => BigNumber(network.getIn(['weight', 'onlineWeight', 'median'], 0)), | ||
[network] | ||
) | ||
|
||
const trended_weight = useMemo( | ||
() => BigNumber(network.getIn(['weight', 'trendedWeight', 'median'], 0)), | ||
[network] | ||
) | ||
|
||
const quorum_total = useMemo( | ||
() => BigNumber.max(online_weight, trended_weight), | ||
[online_weight, trended_weight] | ||
) | ||
const quorum_weight_delta = useMemo( | ||
() => quorum_total.multipliedBy(0.67), | ||
[quorum_total] | ||
) | ||
|
||
const online_selected = useMemo( | ||
() => online_weight.isGreaterThan(trended_weight), | ||
[online_weight, trended_weight] | ||
) | ||
|
||
const online_nano = useMemo( | ||
() => online_weight.shiftedBy(-36), | ||
[online_weight] | ||
) | ||
const trended_nano = useMemo( | ||
() => trended_weight.shiftedBy(-36), | ||
[trended_weight] | ||
) | ||
const quorum_nano = useMemo( | ||
() => quorum_weight_delta.shiftedBy(-36), | ||
[quorum_weight_delta] | ||
) | ||
|
||
return ( | ||
<div className='representatives__weight-container'> | ||
<div className='representatives__weight'> | ||
<div | ||
className={`representatives__weight-section ${ | ||
!online_selected && 'selected' | ||
}`}> | ||
<div className='representatives__weight-section-label'>Trended</div> | ||
<div className='representatives__weight-section-value'> | ||
{trended_nano.isNaN() ? '-' : `${trended_nano.toFormat(1)}M`} | ||
</div> | ||
<div | ||
className={`representatives__weight-section ${ | ||
onlineSelected && 'selected' | ||
}`}> | ||
<div className='representatives__weight-section-label'>Online</div> | ||
<div className='representatives__weight-section-value'> | ||
{onlineNano.isNaN() ? '-' : `${onlineNano.toFormat(1)}M`} | ||
</div> | ||
</div> | ||
<div | ||
className={`representatives__weight-section ${ | ||
online_selected && 'selected' | ||
}`}> | ||
<div className='representatives__weight-section-label'>Online</div> | ||
<div className='representatives__weight-section-value'> | ||
{online_nano.isNaN() ? '-' : `${online_nano.toFormat(1)}M`} | ||
</div> | ||
</div> | ||
<div className='representatives__weight-section'> | ||
<div className='representatives__weight-section-label'> | ||
Quorum Delta | ||
</div> | ||
<div className='representatives__weight-section-value'> | ||
{quorum_nano.isNaN() ? '-' : `${quorum_nano.toFormat(1)}M`} | ||
</div> | ||
</div> | ||
<div className='representatives__weight-section'> | ||
<div className='representatives__weight-section-label'> | ||
PR Threshold | ||
</div> | ||
<div className='representatives__weight-section'> | ||
<div className='representatives__weight-section-label'> | ||
Quorum Delta | ||
</div> | ||
<div className='representatives__weight-section-value'> | ||
{quorumNano.isNaN() ? '-' : `${quorumNano.toFormat(1)}M`} | ||
</div> | ||
<div className='representatives__weight-section-value'> | ||
{pr_min_weight} | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
RepresentativesWeight.propTypes = { | ||
network: ImmutablePropTypes.map | ||
network: ImmutablePropTypes.map, | ||
principal_representative_minimum_weight: ImmutablePropTypes.number | ||
} |