-
Notifications
You must be signed in to change notification settings - Fork 297
/
WalletRow.js
210 lines (200 loc) · 6.53 KB
/
WalletRow.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// @flow
import React, { Component, Fragment } from 'react';
import { observer } from 'mobx-react';
import {
defineMessages,
intlShape,
FormattedMessage,
FormattedHTMLMessage,
} from 'react-intl';
import SVGInline from 'react-svg-inline';
import isNil from 'lodash/isNil';
import Wallet from '../../../domains/Wallet';
import { getColorFromRange } from '../../../utils/colors';
import settingsIcon from '../../../assets/images/settings-ic.inline.svg';
import { SIMPLE_DECIMAL_PLACES_IN_ADA } from '../../../config/numbersConfig';
import DropdownMenu from './DropdownMenu';
import DonutRing from './DonutRing';
import styles from './WalletRow.scss';
export const DELEGATION_ACTIONS = {
CHANGE_DELEGATION: 'changeDelegation',
REMOVE_DELEGATION: 'removeDelegation',
DELEGATE: 'delegate',
};
const messages = defineMessages({
walletAmount: {
id: 'staking.delegationCenter.walletAmount',
defaultMessage: '!!!{amount} ADA',
description:
'Amount of each wallet for the Delegation center body section.',
},
inactiveStakePercentageActivate: {
id: 'staking.delegationCenter.inactiveStakePercentageActivate',
defaultMessage:
'!!!<b>activate {inactiveStakePercentage}% of inactive stake</b>',
description:
'Inactive stake percentage of each wallet for the Delegation center body section.',
},
delegated: {
id: 'staking.delegationCenter.delegated',
defaultMessage: '!!!Delegated',
description: 'Delegated label for the Delegation center body section.',
},
notDelegated: {
id: 'staking.delegationCenter.notDelegated',
defaultMessage: '!!!Not-delegated',
description: 'Not-delegated label for the Delegation center body section.',
},
changeDelegation: {
id: 'staking.delegationCenter.changeDelegation',
defaultMessage: '!!!Change delegation',
description:
'Change delegation label for the Delegation center body section.',
},
removeDelegation: {
id: 'staking.delegationCenter.removeDelegation',
defaultMessage: '!!!Remove delegation',
description:
'Remove delegation label for the Delegation center body section.',
},
toStakePoolSlug: {
id: 'staking.delegationCenter.toStakePoolSlug',
defaultMessage: '!!!To <b>[{delegatedStakePoolSlug}]</b> stake pool',
description:
'Delegated stake pool slug for the Delegation center body section.',
},
delegate: {
id: 'staking.delegationCenter.delegate',
defaultMessage: '!!!Delegate',
description: 'Delegate label for the Delegation center body section.',
},
yourStake: {
id: 'staking.delegationCenter.yourStake',
defaultMessage: '!!!your stake',
description: 'Your stake label for the Delegation center body section.',
},
});
type Props = {
wallet: Wallet,
index?: number,
onDelegate: Function,
};
@observer
export default class WalletRow extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
onDelegate = () => {
const { wallet } = this.props;
this.props.onDelegate(wallet.id);
};
render() {
const { intl } = this.context;
const {
wallet: {
name,
amount,
inactiveStakePercentage,
isDelegated,
delegatedStakePool,
},
index,
} = this.props;
const inactiveStakePercentageValue = inactiveStakePercentage || 0;
const color =
isDelegated && !isNil(index) ? getColorFromRange(index) : 'transparent';
const delegated = intl.formatMessage(messages.delegated);
const notDelegated = intl.formatMessage(messages.notDelegated);
const changeDelegation = intl.formatMessage(messages.changeDelegation);
const removeDelegation = intl.formatMessage(messages.removeDelegation);
const delegate = intl.formatMessage(messages.delegate);
const yourStake = intl.formatMessage(messages.yourStake);
const delegatedWalletActionOptions = [
{
label: changeDelegation,
value: DELEGATION_ACTIONS.CHANGE_DELEGATION,
className: styles.normalOption,
},
{
label: removeDelegation,
value: DELEGATION_ACTIONS.REMOVE_DELEGATION,
className: styles.removeOption,
},
];
return (
<div className={styles.component}>
<div className={styles.left}>
<div className={styles.title}>{name}</div>
<div className={styles.description}>
<FormattedMessage
{...messages.walletAmount}
values={{
amount: amount.toFormat(SIMPLE_DECIMAL_PLACES_IN_ADA),
}}
/>
{inactiveStakePercentageValue > 0 && (
<Fragment>
<span className={styles.donutRing}>
<DonutRing
percentage={100 - inactiveStakePercentageValue}
sqSize={11}
strokeWidth={3}
/>
</span>
<FormattedHTMLMessage
{...messages.inactiveStakePercentageActivate}
values={{
inactiveStakePercentage: inactiveStakePercentageValue,
}}
/>
</Fragment>
)}
</div>
</div>
<div className={styles.right}>
<div>
<div className={styles.status}>
<span>{isDelegated ? delegated : notDelegated}</span>
{isDelegated && (
<DropdownMenu
label={
<SVGInline svg={settingsIcon} className={styles.gearIcon} />
}
menuItems={delegatedWalletActionOptions}
onMenuItemClick={() => null}
/>
)}
</div>
<div className={styles.action}>
{isDelegated && delegatedStakePool ? (
<FormattedHTMLMessage
{...messages.toStakePoolSlug}
values={{
delegatedStakePoolSlug: delegatedStakePool.slug,
}}
/>
) : (
<span>
<span
className={styles.actionLink}
role="presentation"
onClick={this.onDelegate}
>
{delegate}
</span>
{` ${yourStake}`}
</span>
)}
</div>
</div>
<div>
<div
className={styles.stakePoolRankingIndicator}
style={{ background: color }}
/>
</div>
</div>
</div>
);
}
}