/
Staleness.js
51 lines (48 loc) · 1.35 KB
/
Staleness.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// @flow
import { get } from 'dot-prop-immutable';
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { translate } from 'react-i18next';
import compose from 'lodash/fp/compose';
import { Icon, Popup } from 'semantic-ui-react';
import TimeAgo from 'react-timeago';
class GlobalAccountFragmentDataStaleness extends PureComponent<Props> {
render() {
const {
currentHeight,
lastHeight,
lastUpdate,
t,
} = this.props;
const age = currentHeight - lastHeight;
return (
<React.Fragment>
<Popup
content={<TimeAgo date={`${lastUpdate}z`} />}
flowing
header={t('last_updated')}
position="right center"
size="tiny"
trigger={(
<Icon
color={(age > 1000) ? 'red' : 'grey'}
name="clock outline"
/>
)}
/>
</React.Fragment>
);
}
}
const mapStateToProps = (state, ownProps) => {
const account = ownProps.account.replace('.', '\\.');
return {
currentHeight: get(state, 'chain.head_block_num'),
lastHeight: get(state, `accounts.${account}.head_block_num`),
lastUpdate: get(state, `accounts.${account}.head_block_time`),
};
};
export default compose(
translate('common'),
connect(mapStateToProps)
)(GlobalAccountFragmentDataStaleness);