Update minimumPeriod for 2.0 and drop pre 1.0 support (#1423)
This commit is contained in:
parent
8595d69f65
commit
1ce39e2af2
@ -6,38 +6,27 @@
|
||||
import { BareProps, CallProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Moment, Option } from '@polkadot/types';
|
||||
import { Moment } from '@polkadot/types';
|
||||
import { withCalls } from '@polkadot/ui-api';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
type Props = BareProps & CallProps & {
|
||||
children?: React.ReactNode;
|
||||
label?: React.ReactNode;
|
||||
timestamp_blockPeriod?: Moment | Option<Moment>; // support for previous
|
||||
timestamp_minimumPeriod?: Moment; // support for new version
|
||||
};
|
||||
timestamp_minimumPeriod?: Moment;
|
||||
}
|
||||
|
||||
export class TimePeriod extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
const { children, className, label = '', style, timestamp_blockPeriod, timestamp_minimumPeriod } = this.props;
|
||||
const period = timestamp_minimumPeriod || (
|
||||
timestamp_blockPeriod
|
||||
? (
|
||||
(timestamp_blockPeriod as Moment).toNumber
|
||||
? (timestamp_blockPeriod as Moment)
|
||||
: (timestamp_blockPeriod as Option<Moment>).unwrapOr(null)
|
||||
)
|
||||
: null
|
||||
);
|
||||
|
||||
const { children, className, label = '', style, timestamp_minimumPeriod } = this.props;
|
||||
return (
|
||||
<div
|
||||
className={className}
|
||||
style={style}
|
||||
>
|
||||
{label}{
|
||||
period
|
||||
? `${formatNumber(period.toNumber() * 2)}s`
|
||||
timestamp_minimumPeriod
|
||||
? `${formatNumber(timestamp_minimumPeriod.toNumber() * 2)}s`
|
||||
: '-'
|
||||
}{children}
|
||||
</div>
|
||||
@ -46,6 +35,6 @@ export class TimePeriod extends React.PureComponent<Props> {
|
||||
}
|
||||
|
||||
export default withCalls<Props>(
|
||||
'query.timestamp.blockPeriod',
|
||||
'query.timestamp.minimumPeriod'
|
||||
// substrate 1.x: 'query.timestamp.blockPeriod'
|
||||
['consts.timestamp.minimumPeriod', { fallbacks: ['query.timestamp.minimumPeriod'] }]
|
||||
)(TimePeriod);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user