-
Notifications
You must be signed in to change notification settings - Fork 295
/
StakingInfo.tsx
136 lines (123 loc) · 4.47 KB
/
StakingInfo.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
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { defineMessages, intlShape, FormattedMessage } from 'react-intl';
import { ButtonSkin } from 'react-polymorph/lib/skins/simple/ButtonSkin';
import ButtonLink from '../../widgets/ButtonLink';
import styles from './StakingInfo.scss';
const messages = defineMessages({
heading: {
id: 'staking.info.heading',
defaultMessage: '!!!Cardano is transitioning into a decentralized system',
description: 'Headline for the Decentralization progress notification.',
},
description: {
id: 'staking.info.description',
defaultMessage:
'!!!Cardano is transitioning from a federated system operated by its creators to a decentralized system operated by a community of stake pool operators. During this transition, blocks will be produced both by the federated nodes and by stake pools. The percentage of blocks produced by stake pools will increase every epoch until block production in the Cardano network becomes fully decentralized.',
description:
'Info description for the Decentralization progress notification.',
},
percentage: {
id: 'staking.info.percentage',
defaultMessage:
'!!!Currently, {percentage}% of the blocks are produced by the stake pools.',
description:
'Percentage info description for the Decentralization progress notification.',
},
buttonLabel: {
id: 'staking.info.buttonLabel',
defaultMessage: '!!!Learn more',
description: 'Button Label for the Decentralization progress notification.',
},
learnMoreLinkUrl: {
id: 'staking.info.learnMore.linkUrl',
defaultMessage: '!!!https://iohk.zendesk.com/hc',
description: '"Learn more" link URL in the staking info page',
},
});
type Props = {
percentage: number,
onLearnMoreClick: Function,
};
type State = { progressLabelClassName: string };
@observer
export default class StakingInfo extends Component<Props, State> {
static defaultProps = {
percentage: 0,
};
static contextTypes = {
intl: intlShape.isRequired,
};
progressRef: any;
constructor(props: Props) {
super(props);
this.progressRef = React.createRef();
this.state = { progressLabelClassName: styles.progressLabelWhite };
}
componentDidMount() {
this.handleProgressLabelClassName();
}
componentDidUpdate(prevProps: Props) {
const { percentage: prevPercentage } = prevProps;
const { percentage: currentPercentage } = this.props;
if (prevPercentage !== currentPercentage) {
this.handleProgressLabelClassName();
}
}
handleProgressLabelClassName = () => {
const { current: progressComponent } = this.progressRef;
const progressLabelClassName =
progressComponent.clientWidth >= 50
? styles.progressLabelWhite
: styles.progressLabel;
this.setState({ progressLabelClassName });
};
render() {
const { intl } = this.context;
const { percentage, onLearnMoreClick } = this.props;
const { progressLabelClassName } = this.state;
const heading = intl.formatMessage(messages.heading);
const description = intl.formatMessage(messages.description);
const buttonLabel = intl.formatMessage(messages.buttonLabel);
const showLearnMoreButton = false;
return (
<div className={styles.component}>
<div className={styles.mainContent}>
<div className={styles.heading}>{heading}</div>
<div className={styles.description}>{description}</div>
<div className={styles.description}>
<FormattedMessage
{...messages.percentage}
values={{ percentage }}
/>
</div>
<div className={styles.progressBar}>
<div className={styles.progressBarContainer}>
<div
className={styles.progress}
ref={this.progressRef}
style={{ width: `${percentage}%` }}
>
<div className={progressLabelClassName}>{percentage}%</div>
</div>
</div>
</div>
{showLearnMoreButton && (
<ButtonLink
className={styles.learnMoreButton}
onClick={() =>
onLearnMoreClick(intl.formatMessage(messages.learnMoreLinkUrl))
}
skin={ButtonSkin}
label={buttonLabel}
linkProps={{
className: styles.externalLinkIcon,
}}
/>
)}
</div>
</div>
);
}
}