-
Notifications
You must be signed in to change notification settings - Fork 295
/
StakingEpochs.tsx
160 lines (147 loc) · 4.56 KB
/
StakingEpochs.tsx
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';
import { Select } from 'react-polymorph/lib/components/Select';
import { SelectSkin } from 'react-polymorph/lib/skins/simple/SelectSkin';
import BorderedBox from '../../widgets/BorderedBox';
import LoadingSpinner from '../../widgets/LoadingSpinner';
import StakingEpochsCurrentEpochData from './StakingEpochsCurrentEpochData';
import StakingEpochsPreviousEpochData from './StakingEpochsPreviousEpochData';
import { SELECTED_EPOCH_OPTIONS, humanizeDurationToShort } from './helpers';
import type { EpochData } from '../../../api/staking/types';
import styles from './StakingEpochs.scss';
const messages = defineMessages({
currentEpochHeading: {
id: 'staking.epochs.currentHeading',
defaultMessage: '!!!current epoch',
description: 'Headline for the current epoch.',
},
previousEpochHeading: {
id: 'staking.epochs.previousHeading',
defaultMessage: '!!!previous epoch',
description: 'Headline for the previous epoch.',
},
});
type Props = {
currentEpochName: string,
currentEpochData: EpochData,
currentEpochEndDateTime: string,
currentEpochProgress: number,
previousEpochName: string,
previousEpochData: EpochData,
isLoading: boolean,
};
type State = {
selectedEpoch: string,
duration: string,
};
const { CURRENT_EPOCH, PREVIOUS_EPOCH } = SELECTED_EPOCH_OPTIONS;
@observer
export default class StakingEpochs extends Component<Props, State> {
static contextTypes = {
intl: intlShape.isRequired,
};
static defaultProps = {
isLoading: false,
};
constructor() {
super();
this.state = {
selectedEpoch: CURRENT_EPOCH,
duration: '',
};
}
componentDidMount() {
const { intl } = this.context;
const { currentEpochEndDateTime } = this.props;
this.setState({
duration: humanizeDurationToShort(intl.locale, currentEpochEndDateTime),
});
}
onSelectedEpochChange = (selectedEpoch: string) =>
this.setState({ selectedEpoch });
render() {
const {
currentEpochName,
currentEpochData,
currentEpochProgress,
previousEpochName,
previousEpochData,
isLoading,
} = this.props;
const { selectedEpoch, duration } = this.state;
const { intl } = this.context;
const epochSelectOptions = [
{
label: `${currentEpochName} (${intl.formatMessage(
messages.currentEpochHeading
)})`,
value: CURRENT_EPOCH,
},
{
label: `${previousEpochName} (${intl.formatMessage(
messages.previousEpochHeading
)})`,
value: PREVIOUS_EPOCH,
},
];
if (!currentEpochName) {
return null;
}
return (
<div className={styles.component}>
<BorderedBox>
<div className={styles.headerWrapper}>
<Select
className={styles.epochSelector}
options={epochSelectOptions}
value={selectedEpoch}
onChange={this.onSelectedEpochChange}
skin={SelectSkin}
selectionRenderer={(option) => (
<div className={styles.customSelectValue}>{option.label}</div>
)}
optionHeight={50}
/>
</div>
{selectedEpoch === CURRENT_EPOCH && (
<div>
<div className={styles.currentEpochProgressBar}>
<div className={styles.progressBarContainer}>
<div
className={styles.progress}
style={{ width: `${currentEpochProgress}%` }}
>
<div
className={styles.overlapProgressLabel}
style={{ left: `${10000 / currentEpochProgress}%` }}
>
{duration}
</div>
</div>
<div className={styles.progressLabel}>{duration}</div>
</div>
</div>
<StakingEpochsCurrentEpochData
currentEpochData={currentEpochData}
isLoading={isLoading}
/>
</div>
)}
{selectedEpoch === PREVIOUS_EPOCH && (
<StakingEpochsPreviousEpochData
previousEpochData={previousEpochData}
isLoading={isLoading}
/>
)}
{isLoading && (
<div className={styles.loadingSpinnerWrapper}>
<LoadingSpinner />
</div>
)}
</BorderedBox>
</div>
);
}
}