-
Notifications
You must be signed in to change notification settings - Fork 295
/
WalletUtxo.tsx
243 lines (230 loc) · 8.09 KB
/
WalletUtxo.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// @flow
import React, { Component, Fragment } from 'react';
import BigNumber from 'bignumber.js';
import classnames from 'classnames';
import { defineMessages, intlShape, FormattedHTMLMessage } from 'react-intl';
import {
BarChart,
CartesianGrid,
XAxis,
YAxis,
Tooltip,
Label,
Bar,
ResponsiveContainer,
} from 'recharts';
import { Link } from 'react-polymorph/lib/components/Link';
import { LinkSkin } from 'react-polymorph/lib/skins/simple/LinkSkin';
import BorderedBox from '../../widgets/BorderedBox';
import LoadingSpinner from '../../widgets/LoadingSpinner';
import Tick from './WalletUtxoTick';
import CustomTooltip from './WalletUtxoTooltip';
import Cursor from './WalletUtxoCursor';
import { DECIMAL_PLACES_IN_ADA } from '../../../config/numbersConfig';
import styles from './WalletUtxo.scss';
import type { TickProps } from './WalletUtxoTick';
import { WalletUtxoDescription } from './WalletUtxoDescription';
export const messages = defineMessages({
title: {
id: 'wallet.settings.utxos.title',
defaultMessage: '!!!Wallet UTXO distribution',
description: 'Title for the "Wallet Utxos" screen.',
},
description: {
id: 'wallet.settings.utxos.description',
defaultMessage:
'!!!This wallet contains <b>{formattedWalletAmount} ADA</b> on <b>{walletUtxosAmount} UTXOs</b> (unspent transaction outputs). Examine the histogram below to see the distribution of UTXOs with different amounts of ada.',
description: 'Description for the "Wallet Utxos" screen.',
},
emptyWallet: {
id: 'wallet.settings.utxos.emptyWallet',
defaultMessage:
'!!!This wallet is empty so it does not contain any UTXOs (unspent transaction outputs).',
description: 'Empty wallet description for the "Wallet Utxos" screen.',
},
findOutMoreLink: {
id: 'wallet.settings.utxos.findOutMoreLink',
defaultMessage: '!!!Find out more',
description: '"Find out more" link on the "Wallet Utxos" screen.',
},
findOutMoreLinkUrl: {
id: 'wallet.settings.utxos.findOutMoreLinkUrl',
defaultMessage:
'!!!https://iohk.zendesk.com/hc/en-us/articles/360034118013',
description: '"Find out more" link URL on the "Wallet Utxos" screen.',
},
labelX: {
id: 'wallet.settings.utxos.labelX',
defaultMessage: '!!!amount',
description: 'Label X for the "Wallet Utxos" screen.',
},
labelY: {
id: 'wallet.settings.utxos.labelY',
defaultMessage: '!!!Nº UTXO',
description: 'Label Y for the "Wallet Utxos" screen.',
},
pendingTransactions: {
id: 'wallet.settings.utxos.pendingTransactions',
defaultMessage:
'!!!<b>Pending transactions</b> may affect the accuracy of data presented here. <br /> You have <b>{pendingTxnsCount}</b> pending transaction{txnsPlural}.',
description:
'Number of pending transactions for the "Wallet Utxos" screen.',
},
});
type Props = {
walletAmount: BigNumber,
walletUtxosAmount: number,
chartData: Array<any>,
onExternalLinkClick: Function,
pendingTxnsCount: number,
isLoadingInitialUtxoData?: boolean,
};
type State = {
isHoveringChart: boolean,
};
export default class WalletUtxo extends Component<Props, State> {
static contextTypes = {
intl: intlShape.isRequired,
};
state = {
isHoveringChart: false,
};
shouldComponentUpdate() {
return !this.state.isHoveringChart;
}
renderPendingTxns = (pendingTxnsCount: number) => {
const txnsPlural = (!pendingTxnsCount || pendingTxnsCount > 1) && 's';
return (
<div className={styles.pendingTxnsWrapper}>
<div>
<p>
<FormattedHTMLMessage
{...messages.pendingTransactions}
values={{
pendingTxnsCount,
txnsPlural,
}}
/>
</p>
</div>
</div>
);
};
render() {
const { intl } = this.context;
const {
isLoadingInitialUtxoData,
walletAmount,
walletUtxosAmount,
chartData,
onExternalLinkClick,
pendingTxnsCount,
} = this.props;
const formattedWalletAmount = walletAmount.toFormat(DECIMAL_PLACES_IN_ADA);
const isEmpty = walletUtxosAmount === 0;
const componentStyles = classnames([
styles.component,
isEmpty ? styles.isEmpty : null,
]);
const findOutMoreLinkUrl = intl.formatMessage(messages.findOutMoreLinkUrl);
const findOutMoreLink = (
<Link
className={styles.externalLink}
onClick={(event) => onExternalLinkClick(findOutMoreLinkUrl, event)}
label={intl.formatMessage(messages.findOutMoreLink)}
skin={LinkSkin}
/>
);
const emptyOrLoadingState = isLoadingInitialUtxoData ? (
<LoadingSpinner />
) : (
<p>{intl.formatMessage(messages.emptyWallet)}</p>
);
return (
<div className={componentStyles}>
<BorderedBox className={styles.borderedBox}>
<div
className={styles.container}
onMouseEnter={() => this.setState({ isHoveringChart: true })}
onMouseLeave={() => this.setState({ isHoveringChart: false })}
>
<h1>{intl.formatMessage(messages.title)}</h1>
{!isLoadingInitialUtxoData && !isEmpty ? (
<Fragment>
<p>
<WalletUtxoDescription
description={messages.description}
formattedWalletAmount={formattedWalletAmount}
walletUtxosAmount={walletUtxosAmount}
/>{' '}
{findOutMoreLink}
</p>
<div className={styles.responsiveContainerWrapper}>
<ResponsiveContainer
height={280}
className={styles.responsiveContainer}
>
<BarChart data={chartData} barSize={23}>
<CartesianGrid
className={styles.cartesianGrid}
horizontal={false}
vertical={false}
y={-10}
height={255}
fill="transparent"
/>
<XAxis
dataKey="walletAmount"
interval={0}
axisLine={false}
tickLine={false}
tick={(props: TickProps) => (
<Tick {...props} textAnchor="start" vertical />
)}
className={styles.xAxis}
y={0}
>
<Label
value={intl.formatMessage(messages.labelX)}
offset={20}
position="insideBottomRight"
className={styles.xAxisLabel}
/>
</XAxis>
<YAxis
dataKey="walletUtxosAmount"
axisLine={false}
tickLine={false}
allowDecimals={false}
domain={[0, 'dataMax']}
tick={(props: TickProps) => (
<Tick {...props} textAnchor="end" />
)}
>
<Label
value={intl.formatMessage(messages.labelY)}
offset={0}
position="insideTopLeft"
className={styles.yAxisLabel}
/>
</YAxis>
<Tooltip
cursor={<Cursor offsetWidth={28} />}
isAnimationActive={false}
content={<CustomTooltip />}
/>
<Bar dataKey="walletUtxosAmount" className={styles.bar} />
</BarChart>
</ResponsiveContainer>
</div>
{this.renderPendingTxns(pendingTxnsCount)}
</Fragment>
) : (
emptyOrLoadingState
)}
</div>
</BorderedBox>
</div>
);
}
}