-
Notifications
You must be signed in to change notification settings - Fork 295
/
StakePoolsTableBody.tsx
131 lines (126 loc) · 4.29 KB
/
StakePoolsTableBody.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
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { intlShape } from 'react-intl';
import { get, map } from 'lodash';
import BigNumber from 'bignumber.js';
import moment from 'moment';
import classNames from 'classnames';
import {
formattedWalletAmount,
toFixedUserFormat,
} from '../../../utils/formatters';
import { PoolPopOver } from '../widgets/PoolPopOver';
import styles from './StakePoolsTable.scss';
import { getColorFromRange, getSaturationColor } from '../../../utils/colors';
import StakePool from '../../../domains/StakePool';
type TableBodyProps = {
sortedStakePoolList: StakePool,
numberOfRankedStakePools: number,
currentTheme: string,
onOpenExternalLink: Function,
showWithSelectButton?: boolean,
containerClassName: string,
onSelect?: (poolId: string) => void,
selectedPoolId?: ?number,
};
@observer
export class StakePoolsTableBody extends Component<TableBodyProps> {
static contextTypes = {
intl: intlShape.isRequired,
};
render() {
const {
sortedStakePoolList,
numberOfRankedStakePools,
currentTheme,
onSelect,
onOpenExternalLink,
showWithSelectButton,
containerClassName,
selectedPoolId,
} = this.props;
const { intl } = this.context;
return map(sortedStakePoolList, (stakePool, key) => {
const rank = get(stakePool, 'ranking', '');
const ticker = get(stakePool, 'ticker', '');
const saturation = get(stakePool, 'saturation', '');
const cost = new BigNumber(get(stakePool, 'cost', ''));
const margin = get(stakePool, 'profitMargin', '');
const producedBlocks = get(stakePool, 'producedBlocks', '');
const pledge = new BigNumber(get(stakePool, 'pledge', ''));
const retiring = get(stakePool, 'retiring', '');
const memberRewards = new BigNumber(
get(stakePool, 'potentialRewards', '')
);
const potentialRewards = formattedWalletAmount(memberRewards);
const retirement =
retiring && moment(retiring).locale(intl.locale).fromNow(true);
const pledgeValue = formattedWalletAmount(pledge, false, false);
const costValue = formattedWalletAmount(cost, false, false);
const progressBarContentClassnames = classNames([
styles.progressBarContent,
styles[getSaturationColor(saturation)],
]);
const color = getColorFromRange(rank, numberOfRankedStakePools);
return (
<tr key={key}>
<td>
{!memberRewards.isZero() ? (
rank
) : (
<>
{numberOfRankedStakePools + 1}
<span className={styles.asterisk}>*</span>
</>
)}
</td>
<td>
<PoolPopOver
color={color}
currentTheme={currentTheme}
onOpenExternalLink={onOpenExternalLink}
onSelect={onSelect}
isSelected={selectedPoolId === stakePool.id}
stakePool={stakePool}
containerClassName={containerClassName}
numberOfRankedStakePools={numberOfRankedStakePools}
showWithSelectButton={showWithSelectButton}
>
<span className={styles.ticker} role="presentation">
{ticker}
</span>
</PoolPopOver>
</td>
<td>
<div className={styles.saturation}>
<div className={styles.progressBar}>
<div className={styles.progressBarContainer}>
<div
className={progressBarContentClassnames}
style={{ width: `${parseFloat(saturation).toFixed(2)}%` }}
/>
</div>
</div>
<div className={styles.saturationLabel}>
{`${toFixedUserFormat(saturation, 2)}%`}
</div>
</div>
</td>
<td>{costValue}</td>
<td>{`${toFixedUserFormat(margin, 2)}%`}</td>
<td>{toFixedUserFormat(producedBlocks, 0)}</td>
<td>{potentialRewards}</td>
<td>{pledgeValue}</td>
<td>
{retirement ? (
<span className={styles.retiring}>{retirement}</span>
) : (
'-'
)}
</td>
</tr>
);
});
}
}