ghost-portal/packages/ui-app/src/Progress.tsx
Jaco Greeff 46a48539b7
Additional block production overview on explorer (#212)
* Cleanup Card layouts

* Additional block production overview on explorer

* Adjust Card padding for accounts

* Observable calculations into ApiObservable

* DRY-er combineLatest + .pipe(map(...))

* .pipe(map(...))

* Progress takes value + total, auto-colors

* CardSummary with Progress

* Small style updates

* Cleanup withApiObservable (optional value name)

* Cleanup progress props

* Cleanup rpc method use

* Auto-set the prop from withStorage

* Cleanups in observable use

* Cleanups to layout

* Initial bestNumber

* Poll for changes in ApiObservable

* WIP (debug)

* Initial conversion (untested) or subscribeStorage

* s/apiObservable/observable/

* Starting to show stuff (after storage subscriptions). WIP.

* Staking UI works, still WIP on rest.

* Readability

* Storage withObservableDiv, Closes https://github.com/polkadot-js/apps/issues/215

* Add encoding FIXMEs

* 'nominee' on set click

* Align withObservable with others (single line)

* Retrieve ss58 encoded AccountId from storage

* Update with latest api (null/undefined storage distinction)
2018-08-13 12:05:11 +02:00

65 lines
1.8 KiB
TypeScript

// Copyright 2017-2018 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { BareProps } from './types';
import BN from 'bn.js';
import React from 'react';
import SUIProgress from 'semantic-ui-react/dist/commonjs/modules/Progress/Progress';
import isBn from '@polkadot/util/is/bn';
import isUndefined from '@polkadot/util/is/undefined';
import classes from './util/classes';
type BaseColors = 'blue' | 'green' | 'red' | 'orange';
export type Colors = 'auto' | 'autoReverse' | BaseColors;
type Props = BareProps & {
color?: Colors,
percent?: BN | number,
total?: BN | number,
value?: BN | number
};
export default class Progress extends React.PureComponent<Props> {
render () {
const { className, color = 'blue', percent, total, style, value } = this.props;
let calculated: number | undefined;
if (!isUndefined(value) && !isUndefined(total) && (isBn(total) ? total.gtn(0) : total > 0)) {
calculated = 100.0 * (isBn(value) ? value.toNumber() : value) / (isBn(total) ? total.toNumber() : total);
} else {
calculated = isBn(percent) ? percent.toNumber() : percent;
}
if (isUndefined(calculated) || calculated < 0) {
return null;
}
let rainbow: BaseColors;
if (color === 'auto' || color === 'autoReverse') {
if (calculated > 66.6) {
rainbow = color === 'auto' ? 'green' : 'red';
} else if (calculated > 33.3) {
rainbow = 'orange';
} else {
rainbow = color === 'auto' ? 'red' : 'green';
}
} else {
rainbow = color;
}
return (
<SUIProgress
className={classes('ui--Progress', className)}
color={rainbow}
percent={calculated}
size='tiny'
style={style}
/>
);
}
}