forked from polkadot-js/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add displaying of the validators (polkadot-js#300)
* Add validators App Fix polkadot-js#191 * Pull validator breakidown into staking overview * Fix layout * Add AddressRow component * Minor CSS fix * Use standard address components in the staking app * Use new components and cleanup * Refactor and layout work on the validators * Re-use already available components * Remove app-validators in tsconfig
- Loading branch information
Showing
15 changed files
with
429 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2017-2018 @polkadot/app-staking authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
|
||
import { I18nProps } from '@polkadot/ui-app/types'; | ||
|
||
import React from 'react'; | ||
import AddressRow from '@polkadot/ui-app/AddressRow'; | ||
|
||
import translate from '../translate'; | ||
|
||
type Props = I18nProps & { | ||
current: Array<string> | ||
next: Array<string> | ||
}; | ||
|
||
class CurrentList extends React.PureComponent<Props> { | ||
render () { | ||
return ( | ||
<div className='validator--ValidatorsList'> | ||
<div className='validator--current'> | ||
{this.renderCurrent()} | ||
</div> | ||
<div className='validator--next'> | ||
{this.renderNext()} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
private renderCurrent () { | ||
const { current, t } = this.props; | ||
|
||
if (current.length === 0) { | ||
return null; | ||
} | ||
|
||
return [ | ||
<h4> | ||
{t('list.current', { | ||
defaultValue: 'Current: {{count}}', | ||
replace: { | ||
count: current.length | ||
} | ||
})} | ||
</h4>, | ||
...current.map((account) => { | ||
return ( | ||
<AddressRow | ||
className='validator--row' | ||
key={account} | ||
name={name || t('name.validator', { defaultValue: 'validator' })} | ||
value={account} | ||
withBalance={true} | ||
withNonce={false} | ||
identIconSize={48} | ||
isShort={true} | ||
/> | ||
); | ||
}) | ||
]; | ||
} | ||
|
||
private renderNext () { | ||
const { next, t } = this.props; | ||
|
||
if (next.length === 0) { | ||
return null; | ||
} | ||
|
||
return [ | ||
<h4> | ||
{t('list.next', { | ||
defaultValue: 'Next up: {{count}}', | ||
replace: { | ||
count: next.length | ||
} | ||
})} | ||
</h4>, | ||
...next.map((account) => { | ||
return ( | ||
<AddressRow | ||
className='validator--row' | ||
key={account} | ||
name={name || t('name.intention', { defaultValue: 'intention' })} | ||
value={account} | ||
withBalance={true} | ||
withNonce={false} | ||
identIconSize={48} | ||
isShort={true} | ||
/> | ||
); | ||
}) | ||
]; | ||
} | ||
} | ||
|
||
export default translate(CurrentList); |
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,110 @@ | ||
/* Copyright 2017-2018 @polkadot/app-staking authors & contributors | ||
/* This software may be modified and distributed under the terms | ||
/* of the ISC license. See the LICENSE file for details. */ | ||
|
||
.validator--Account-info-address { | ||
flex: 3; | ||
margin: 0px 5px 0px 5px; | ||
} | ||
|
||
.validator--Account-info-details { | ||
flex: 1; | ||
margin: 0px 5px 0px 5px; | ||
} | ||
|
||
.validator--row { | ||
display: flex; | ||
flex-direction: row; | ||
border-bottom: 1px solid #ccc; | ||
margin-bottom: 5px; | ||
padding-bottom: 2px; | ||
} | ||
|
||
.validator--Account-address { | ||
font-family: monospace; | ||
font-size: 1.5rem; | ||
} | ||
|
||
.validator--Account-icon { | ||
margin-right: 1rem; | ||
} | ||
|
||
.validator--Account-validating { | ||
opacity: 0.25 !important; | ||
padding-top: 8px; | ||
vertical-align: top !important; | ||
} | ||
|
||
.validator--Account-validating.isValidator { | ||
color: red; | ||
opacity: 1 !important; | ||
} | ||
|
||
.validator--Account-details,.column{ | ||
flex: 1; | ||
border: 1px, solid blue; | ||
} | ||
|
||
.validator--Account-balance, | ||
.validator--Account-nonce { | ||
opacity: 0.45; | ||
text-align: right; | ||
} | ||
|
||
.validator--ValidatorsList{ | ||
padding: 10px; | ||
display: flex; | ||
} | ||
|
||
.validator--IntensionsList{ | ||
padding: 10px; | ||
} | ||
|
||
.validator--current,.validator--next{ | ||
margin: 20px; | ||
flex: 1; | ||
} | ||
.app-validators--Query .app-validators--actionrow-value { | ||
padding: 0 0.25rem; | ||
} | ||
|
||
.app-validators--Query .ui--IdentityIcon { | ||
margin: -10px 0; | ||
vertical-align: middle; | ||
} | ||
|
||
.app-validators--actionrow { | ||
display: flex; | ||
} | ||
|
||
.app-validators--actionrow-value { | ||
flex: 1; | ||
min-width: 0; | ||
} | ||
|
||
.app-validators--actionrow-button { | ||
flex: 0; | ||
padding: 0 0.25rem; | ||
} | ||
|
||
.validator--Account-address.isMine { | ||
color: #47b547; | ||
font-weight: 500; | ||
opacity: 1 !important; | ||
} | ||
|
||
.validator-icon { | ||
color: #2284d0; | ||
position: absolute; | ||
font-size: 1.5em !important; | ||
} | ||
|
||
.nominator-icon { | ||
color: #aaa; | ||
position: absolute; | ||
font-size: 1.5em !important; | ||
} | ||
|
||
.ui--AddressRow-icon { | ||
margin: 12px; | ||
} |
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,59 @@ | ||
// Copyright 2017-2018 @polkadot/app-staking authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
|
||
import { RxBalanceMap } from '@polkadot/ui-react-rx/ApiObservable/types'; | ||
import { I18nProps } from '@polkadot/ui-app/types'; | ||
|
||
import './index.css'; | ||
|
||
import BN from 'bn.js'; | ||
import React from 'react'; | ||
|
||
import CurrentList from './CurrentList'; | ||
import Summary from './Summary'; | ||
|
||
type Props = I18nProps & { | ||
balances: RxBalanceMap, | ||
intentions: Array<string>, | ||
validators: Array<string> | ||
}; | ||
|
||
const ZERO = new BN(0); | ||
|
||
export default class Overview extends React.PureComponent<Props> { | ||
render () { | ||
const { balances, intentions, validators } = this.props; | ||
const intentionsSorted = this.sortByBalance( | ||
intentions.filter((address) => | ||
!validators.includes(address) | ||
) | ||
); | ||
const validatorsSorted = this.sortByBalance(validators); | ||
|
||
return ( | ||
<div className='staking--Overview'> | ||
<Summary | ||
balances={balances} | ||
intentions={intentions} | ||
validators={validators} | ||
/> | ||
<CurrentList | ||
current={validatorsSorted} | ||
next={intentionsSorted} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
private sortByBalance (list: Array<string>): Array<string> { | ||
const { balances } = this.props; | ||
|
||
return list.sort((a, b) => { | ||
const balanceA = balances[a] || { stakingBalance: ZERO }; | ||
const balanceB = balances[b] || { stakingBalance: ZERO }; | ||
|
||
return balanceB.stakingBalance.cmp(balanceA.stakingBalance); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.