Cleanup ComponentMap (easier to reason about) (#744)

* Cleanup CompoinentMap (easier to reason about)

* Remove voting countdown
This commit is contained in:
Jaco Greeff 2019-02-21 11:06:36 +01:00 committed by GitHub
parent 1fa3d3de78
commit 06dd4651f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 48 deletions

View File

@ -18,13 +18,12 @@ type Props = I18nProps & {
democracy_nextTally?: BN,
democracy_publicDelay?: BN,
democracy_publicPropCount?: BN,
democracy_referendumCount?: BN,
democracy_votingPeriod?: BN
democracy_referendumCount?: BN
};
class Summary extends React.PureComponent<Props> {
render () {
const { chain_bestNumber = new BN(0), democracy_launchPeriod = new BN(1), democracy_nextTally = new BN(0), democracy_publicPropCount, democracy_referendumCount = new BN(0), democracy_votingPeriod = new BN(1), t } = this.props;
const { chain_bestNumber = new BN(0), democracy_launchPeriod = new BN(1), democracy_nextTally = new BN(0), democracy_publicPropCount, democracy_referendumCount = new BN(0), t } = this.props;
return (
<summary>
@ -40,13 +39,6 @@ class Summary extends React.PureComponent<Props> {
</CardSummary>
</section>
<section className='ui--media-medium'>
<CardSummary
label={t('voting period')}
progress={{
value: chain_bestNumber.mod(democracy_votingPeriod).addn(1),
total: democracy_votingPeriod
}}
/>
<CardSummary
label={t('launch period')}
progress={{
@ -66,7 +58,6 @@ export default translate(
'query.democracy.nextTally',
'query.democracy.publicPropCount',
'query.democracy.referendumCount',
'query.democracy.votingPeriod',
'derive.chain.bestNumber'
)(Summary)
);

View File

@ -23,45 +23,36 @@ import Vector from './Vector';
import Vote from './Vote';
import VoteThreshold from './VoteThreshold';
const components: ComponentMap = {
'AccountId': Account,
'AccountIdOf': Account,
'AccountIndex': Amount,
'Address': Account,
'Balance': Balance,
'BalanceOf': Balance,
'BlockNumber': Amount,
'bool': Bool,
'Bytes': Bytes,
'Code': Code,
'CodeHash': Hash,
'Gas': Amount,
'Hash': Hash,
'Index': Amount,
'KeyValue': KeyValue,
'Vec<KeyValue>': KeyValueArray,
'ParaId': Amount,
'Moment': Moment,
'MomentOf': Moment,
'ProposalIndex': Amount,
'PropIndex': Amount,
'Proposal': Proposal,
'ReferendumIndex': Amount,
'SeedOf': Hash,
'SessionKey': Account,
'Signature': Hash,
'String': Text,
'Text': Text,
'Tuple': Tuple,
'u32': Amount,
'u64': Amount,
'u128': Amount,
'Vector': Vector,
'Vote': Vote,
'VoteIndex': Amount,
'VoteThreshold': VoteThreshold
type TypeToComponent = {
c: React.ComponentType<Props>,
t: Array<string>
};
const components: ComponentMap = ([
{ c: Account, t: ['AccountId', 'AccountIdOf', 'Address', 'SessionKey'] },
{ c: Amount, t: ['AccountIndex', 'BlockNumber', 'Gas', 'Index', 'ParaId', 'ProposalIndex', 'PropIndex', 'ReferendumIndex', 'u16', 'u32', 'u64', 'u128', 'u256', 'VoteIndex'] },
{ c: Balance, t: ['Amount', 'AssetOf', 'Balance', 'BalanceOf'] },
{ c: Bool, t: ['bool'] },
{ c: Bytes, t: ['Bytes'] },
{ c: Code, t: ['Code'] },
{ c: Hash, t: ['CodeHash', 'Hash', 'SeedOf', 'Signature'] },
{ c: KeyValue, t: ['KeyValue'] },
{ c: KeyValueArray, t: ['Vec<KeyValue>'] },
{ c: Moment, t: ['Moment', 'MomentOf'] },
{ c: Proposal, t: ['Proposal'] },
{ c: Text, t: ['String', 'Text'] },
{ c: Tuple, t: ['Tuple'] },
{ c: Vector, t: ['Vector'] },
{ c: Vote, t: ['Vote'] },
{ c: VoteThreshold, t: ['VoteThreshold'] }
] as Array<TypeToComponent>).reduce((components, { c, t }) => {
t.forEach((type) => {
components[type] = c;
});
return components;
}, {} as ComponentMap);
export default function findComponent (def: TypeDef, overrides: ComponentMap = {}): React.ComponentType<Props> {
const type = (({ info, sub, type }: TypeDef) => {
switch (info) {